@Override public String toString() { return getClass().getCanonicalName()+"["+getConstraintsDescription()+"]"; }
protected Maybe<Bundle> findOne(boolean requireExactlyOne) { if (symbolicName==null && url==null) throw new IllegalStateException(this+" must be given either a symbolic name or a URL"); List<Bundle> result = findAll(); if (result.isEmpty()) return Maybe.absent("No bundle matching "+getConstraintsDescription()); if (requireExactlyOne && result.size()>1) return Maybe.absent("Multiple bundles ("+result.size()+") matching "+getConstraintsDescription()); // take the highest version of the first symbolic name alphabetically Bundle r1 = result.get(0); for (int i=1; i<result.size(); i++) { if (result.get(i).getSymbolicName().equals(r1.getSymbolicName())) { r1 = result.get(i); } else { // was in order so no more symbolic names break; } } return Maybe.of(r1); }