in gremlin/neptune-social-media-utils/src/main/java/com/aws/neptune/utils/generator/IdStore.java [100:142]
public IdBean getRandomIdForRelation(int leftId) {
IdBean ids = new IdBean();
ids.left = leftId;
if (multiplicity.equals("SIMPLE")) {
ids.right = getRandomIdWithException(
relation.right,
simpleStore.getIds(ids.left));
if ( -1 == ids.right) {
throw new SupernodeException(relation,ids);
}
simpleStore.put(leftId, ids.right);
}else if (multiplicity.equals("ONE2ONE")) {
throw new RuntimeException(
String.format("Supernode is not applicable to %s relation", multiplicity));
}else if (multiplicity.equals("MANY2ONE")) {
throw new RuntimeException(
String.format("Supernode is not applicable to %s relation", multiplicity));
}else if (multiplicity.equals("ONE2MANY")) {
ids.right = getRandomIdWithException(relation.right, generalstore.getRightIds());
if ( -1 == ids.right) {
throw new SupernodeException(relation,ids);
}
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 SupernodeException(relation,ids);
}
}
generalstore.putRight(ids.right);
}else if ( multiplicity.equals("MULTI")) {
List <Integer> excl = null;
excl = new ArrayList<Integer>();
if ( ! relation.selfRef) {
excl.add(ids.left);
}
ids.right = getRandomIdWithException(relation.right, excl);
}else {
throw new MultiplicityException(multiplicity);
}
return ids;
}