public boolean isIndexed() { return getIndexProperty() != null; }
private Slot getIndexedSlot(Role role) { Slot indexedSlot = role.getType().findSlot(role.getIndexProperty()); if (indexedSlot == null) { // indexed field doesn't exist throw new Error("Unknown indexed field: " + role.getIndexProperty()); } return indexedSlot; }
protected String getCollectionTypeFor(Role role) { boolean indexed = (role.getIndexProperty() != null); boolean ordered = role.isOrdered(); if (indexed && ordered) { throw new Error("Can't handle roles that are both indexed and ordered"); } String elemsType = getTypeFullName(role.getType()); if (indexed) { // FIXME: the type of the key should correspond to the type of the index property return makeGenericType("java.util.Map", "java.lang.Object", elemsType); } else { return makeGenericType("java.util.Set", elemsType); } }
@Override protected void generateStaticKeyFunctionForRole(Role role, PrintWriter out) { if (role.isIndexed()) { onNewline(out); Slot indexedSlot = getIndexedSlot(role); String keyField = role.getIndexProperty(); println(out, generateMapKeyFunction(role.getName(), role.getType().getFullName(), indexedSlot.getSlotType().getFullname(), keyField, role.getIndexCardinality() == Role.MULTIPLICITY_MANY)); onNewline(out); } else { super.generateStaticKeyFunctionForRole(role, out); } }
protected void generateRoleSlotMethodsMultStarIndexed(Role role, PrintWriter out, String methodModifiers, String capitalizedSlotName, String slotAccessExpression, String typeName, String slotName) { Slot indexedSlot = getIndexedSlot(role); String keyField = role.getIndexProperty(); String retType = role.getType().getFullName(); String methodNameSufix = ""; boolean haveMany = role.getIndexCardinality() == Role.MULTIPLICITY_MANY; if (haveMany) { retType = makeGenericType("java.util.Set", retType); } onNewline(out); printMethod(out, "public", retType, "get" + capitalize(role.getName()) + "By" + capitalize(keyField) + methodNameSufix, indexedSlot.getSlotType().getFullname() + " key"); startMethodBody(out); printWords(out, "return", getSearchForKey(role, haveMany ? getCollectionToUse() : retType)); print(out, ";"); endMethodBody(out); }