@Override public boolean isIncluded(SimpleField field) { List<FieldConstraint> constraints = field.getConstraints(); if (constraints != null) { for (FieldConstraint x : constraints) { if (x instanceof ArrayElementIdConstraint) { return true; } } } return false; } });
/** * Returns a map where the key is the array field name, and value is a * List<Path> listing the identity fields for that array */ public Map<Path, List<Path>> getArrayIdentities() { FieldCursor cursor = getFieldCursor(); Map<Path, List<Path>> idMap = new HashMap<>(); while (cursor.next()) { FieldTreeNode fn = cursor.getCurrentNode(); if (fn instanceof SimpleField) { for (FieldConstraint fc : ((SimpleField) fn).getConstraints()) { if (fc instanceof ArrayElementIdConstraint) { Path fieldName = cursor.getCurrentPath(); int lastAny = findLastAnyIndex(fieldName); if (lastAny != -1) { Path arrayName = fieldName.prefix(lastAny); Path idName = fieldName.suffix(-(lastAny + 1)); List<Path> ids = idMap.get(arrayName); if (ids == null) { idMap.put(arrayName, ids = new ArrayList<>()); } ids.add(idName); } } } } } return idMap; }
/** * Returns a map where the key is the array field name, and value is a * List<Path> listing the identity fields for that array */ public Map<Path, List<Path>> getArrayIdentities() { FieldCursor cursor = getFieldCursor(); Map<Path, List<Path>> idMap = new HashMap<>(); while (cursor.next()) { FieldTreeNode fn = cursor.getCurrentNode(); if (fn instanceof SimpleField) { for (FieldConstraint fc : ((SimpleField) fn).getConstraints()) { if (fc instanceof ArrayElementIdConstraint) { Path fieldName = cursor.getCurrentPath(); int lastAny = findLastAnyIndex(fieldName); if (lastAny != -1) { Path arrayName = fieldName.prefix(lastAny); Path idName = fieldName.suffix(-(lastAny + 1)); List<Path> ids = idMap.get(arrayName); if (ids == null) { idMap.put(arrayName, ids = new ArrayList<>()); } ids.add(idName); } } } } } return idMap; }
private static boolean required(SimpleField f) { List<FieldConstraint> constraints = f.getConstraints(); if (constraints != null) { for (FieldConstraint c : constraints) { if (c instanceof RequiredConstraint) { return ((RequiredConstraint) c).getValue(); } else if (c instanceof IdentityConstraint) { return ((IdentityConstraint) c).isValidForFieldType(f.getType()); } else if (c instanceof ArrayElementIdConstraint) { return ((ArrayElementIdConstraint) c).isValidForFieldType(f.getType()); } } } return false; }
private static boolean required(SimpleField f) { List<FieldConstraint> constraints = f.getConstraints(); if (constraints != null) { for (FieldConstraint c : constraints) { if (c instanceof RequiredConstraint) { return ((RequiredConstraint) c).getValue(); } else if (c instanceof IdentityConstraint) { return ((IdentityConstraint) c).isValidForFieldType(f.getType()); } else if (c instanceof ArrayElementIdConstraint) { return ((ArrayElementIdConstraint) c).isValidForFieldType(f.getType()); } } } return false; }
private void getIdentityFields(TreeMap<Path, Field> fieldMap, FieldCursor cursor) { if (cursor.firstChild()) { do { FieldTreeNode fn = cursor.getCurrentNode(); if (fn instanceof ObjectField) { getIdentityFields(fieldMap, cursor); } else if (fn instanceof SimpleField) { SimpleField f = (SimpleField) fn; for (FieldConstraint fc : f.getConstraints()) { if (fc instanceof IdentityConstraint) { fieldMap.put(getEntityRelativeFieldName(f), f); break; } } } } while (cursor.nextSibling()); cursor.parent(); } } }
private void getIdentityFields(TreeMap<Path, Field> fieldMap, FieldCursor cursor) { if (cursor.firstChild()) { do { FieldTreeNode fn = cursor.getCurrentNode(); if (fn instanceof ObjectField) { getIdentityFields(fieldMap, cursor); } else if (fn instanceof SimpleField) { SimpleField f = (SimpleField) fn; for (FieldConstraint fc : f.getConstraints()) { if (fc instanceof IdentityConstraint) { fieldMap.put(f.getFullPath(), f); break; } } } } while (cursor.nextSibling()); cursor.parent(); } } }
private void getIdentityFields(TreeMap<Path, Field> fieldMap, FieldCursor cursor) { if (cursor.firstChild()) { do { FieldTreeNode fn = cursor.getCurrentNode(); if (fn instanceof ObjectField) { getIdentityFields(fieldMap, cursor); } else if (fn instanceof SimpleField) { SimpleField f = (SimpleField) fn; for (FieldConstraint fc : f.getConstraints()) { if (fc instanceof IdentityConstraint) { fieldMap.put(getEntityRelativeFieldName(f), f); break; } } } } while (cursor.nextSibling()); cursor.parent(); } } }