final ObjectSpecification objectSpec = object.getSpecification();
return objectSpec.equals(requiredSpec) && matchesPattern(pattern, object);
}
private boolean matchesPattern(final ObjectAdapter pattern, final ObjectAdapter instance) {
final ObjectAdapter object = instance;
final ObjectSpecification nc = object.getSpecification();
final List<ObjectAssociation> fields = nc.getAssociations(Contributed.EXCLUDED);
for (int f = 0; f < fields.size(); f++) {
final ObjectAssociation fld = fields.get(f);
// are ignoring internal collections - these probably should be
// considered
// ignore non-persistent fields - there is no persisted field to
// compare against
if (fld.isNotPersisted()) {
continue;
}
if (!fld.isOneToOneAssociation()) {
continue;
}
// if pattern contains empty value then it matches anything
if (fld.isEmpty(pattern)) {
continue;
}
// find the object to match against, if any
final ObjectAdapter reqd = fld.get(pattern);
if (reqd == null) {
continue;
}
// find the object; it's a bust if nothing
final ObjectAdapter search = fld.get(object);
if (search == null) {
return false;
}
if (fld.getSpecification().isValue()) {
// compare values directly
if (!reqd.getObject().equals(search.getObject())) {
return false;
}
} else {
// compare the titles
final String r = reqd.titleString().toLowerCase();
final String s = search.titleString().toLowerCase();
// if the pattern does not occur in the object, then it's a bust
if (s.indexOf(r) == -1) {
return false;
}