private boolean subsumes(Restriction other) { for (Restriction r : restrictions) { if (other.isSubsumedBy(r)) { return true; } } return false; } }
private void accept(Restriction newRestriction) { Iterator<Restriction> i = restrictions.iterator(); while (i.hasNext()) { Restriction existing = i.next(); if (newRestriction.isSubsumedBy(existing)) { return; } if (existing.isSubsumedBy(newRestriction)) { i.remove(); } } restrictions.add(newRestriction); }
@Override public boolean isSubsumedBy(Restriction other) { if (other instanceof CompositeRestriction) { return isSubsumedBy((CompositeRestriction) other); } for (Restriction r : restrictions) { if (!r.isSubsumedBy(other)) { return false; } } return true; }
/** * Compose multiple restrictions where each Restriction can veto an * operation. */ public static Restriction concat(Restriction... restrictions) { switch (restrictions.length) { case 0: return UNRESTRICTED; case 1: return restrictions[0]; case 2: if (restrictions [0].isSubsumedBy(restrictions [1])) { return restrictions [1]; } if (restrictions [1].isSubsumedBy(restrictions [0])) { return restrictions [0]; } // Fall through for default behaviour default: return concat(asList(restrictions)); } }