private static boolean assertFields(Object model, String superField, String subFields) { String[] splitFields = subFields.split(ALTERNATIVE); boolean found = false; for (String subField : splitFields) { found = found || isSet(superField != null ? get(model, superField) : model, capitalize(subField)); } return found; }
/** * Evaluate whether a resource satisfies a given constraint. * * @param resource the resource under test * @param constraint the constraint being impose * @return true iff the constraint is satisfied */ @Override public boolean satisfies(R resource, String constraint) { boolean satisfied = false; try { constraint = constraint.substring(constraint.indexOf(":") + 1).trim(); String[] tokens = constraint.split("="); Object value = ReflectionHelper.get(resource, tokens[0]); satisfied = value instanceof String ? ((String)value).matches(tokens[1].replaceAll("\\*", ".*")) : value instanceof Boolean ? ((Boolean)value).equals(Boolean.parseBoolean(constraint)) : value instanceof Integer ? ((Integer)value).equals(Integer.parseInt(constraint)) : false; } catch (Exception e) { // any parse exception implies a mismatch e.printStackTrace(); } return satisfied; }
Object superType = get(model, superField(r)); if(superType != null) missing.addAll(joinSuperType(doAssertRequired(reason, detail, superType ,frameOffset, subField(r)), superType));