public IdBean getRandomPairIdForRelation()

in gremlin/neptune-social-media-utils/src/main/java/com/aws/neptune/utils/generator/IdStore.java [146:238]


    public IdBean getRandomPairIdForRelation() {
        IdBean ids = new IdBean(idBean.getRandomIdForVertexType(relation.left),
                                idBean.getRandomIdForVertexType(relation.right));
        if (multiplicity.equals("SIMPLE")) {
            boolean added = simpleStore.put(ids.left, ids.right);
            while(!added) {
                //check left id already relates to every right id
                while (simpleStore.getIds(ids.left).size() == idBean.getIdPoolSize(relation.right)) {
                    int index = orderedIndex(simpleStore.excl_left_id, ids.left);
                    if ( -1 != index)
                        simpleStore.excl_left_id.add(index, ids.left);
                    ids.left = getRandomIdWithException(relation.left,
                                                        simpleStore.excl_left_id);
                    if ( -1 == ids.left) {
                        throw new TooManyEdgeExeption(relation, multiplicity);
                    }
                }
                ids.right = getRandomIdWithException(
                                            relation.right,
                                            simpleStore.getIds(ids.left));
                added = simpleStore.put(ids.left, ids.right);
               // System.out.println(String.join(" ","Replaced", Integer.toString(ids.left), Integer.toString(ids.right)));
            }
        }else if(multiplicity.equals("ONE2ONE")) {
            if( ! generalstore.putLeft(ids.left)){
                ids.left = getRandomIdWithException(relation.left, generalstore.getLeftIds());
                if ( ! generalstore.putLeft(ids.left) || -1 == ids.left) {
                    throw new TooManyEdgeExeption(relation, multiplicity);
                }
            }
            if ( relation.left.equals(relation.right) && ids.left == ids.right && ! relation.selfRef) {
                List <Integer> excl = generalstore.getRightIds();
                excl.add(ids.right);
                ids.right = getRandomIdWithException(relation.right, excl);
                if ( -1 == ids.right) {
                    throw new TooManyEdgeExeption(relation, multiplicity);
                }
                generalstore.putRight(ids.right);
            }else if( ! generalstore.putRight(ids.right)) {
                ids.right = getRandomIdWithException(relation.right, generalstore.getRightIds());
                if ( relation.left.equals(relation.right) && ids.left == ids.right && ! relation.selfRef) {
                    List <Integer> excl = generalstore.getRightIds();
                    excl.add(ids.right);
                    ids.right = getRandomIdWithException(relation.right, excl);
                    if ( -1 == ids.right) {
                        throw new TooManyEdgeExeption(relation, multiplicity);
                    }
                }
                generalstore.putRight(ids.right);
            }
        }else if (multiplicity.equals("MANY2ONE")) {
            if (! generalstore.putLeft(ids.left)) {
                ids.left = getRandomIdWithException(relation.left, generalstore.getLeftIds());
                if ( -1 == ids.left) {
                    throw new TooManyEdgeExeption(relation, multiplicity);
                }
                if ( relation.left.equals(relation.right) && ids.left == ids.right && ! relation.selfRef) {
                    List <Integer> excl = generalstore.getRightIds();
                    excl.add(ids.left);
                    ids.right = getRandomIdWithException(relation.right, excl);
                    if ( -1 == ids.right) {
                        throw new TooManyEdgeExeption(relation, multiplicity);
                    }
                }
            }
            generalstore.putLeft(ids.left);
        }else if (multiplicity.equals("ONE2MANY")) {
            if (! generalstore.putRight(ids.right)) {
                ids.right = getRandomIdWithException(relation.right, generalstore.getRightIds());
                if ( -1 == ids.right) {
                    throw new TooManyEdgeExeption(relation, multiplicity);
                }
                if ( relation.left.equals(relation.right) && ids.left == ids.right && ! relation.selfRef) {
                    List <Integer> excl = generalstore.getRightIds();
                    excl.add(ids.right);
                    ids.right = getRandomIdWithException(relation.right, excl);
                    if ( -1 == ids.right) {
                        throw new TooManyEdgeExeption(relation, multiplicity);
                    }
                }
            }
            generalstore.putRight(ids.right);
        }else if (multiplicity.equals("MULTI")) {
            List <Integer> excl = new ArrayList<Integer>();;
            if ( ! relation.selfRef) {
                excl.add(ids.left);
                ids.right = getRandomIdWithException(relation.right, excl);
            }
        }else {
            throw new MultiplicityException(multiplicity);
        }
        return ids;
    }