public <B extends AbstractRuleBucket<T, NRE, DRE>> void add(B bucket) throws DRE { String id = null; try { for (String conceptId : bucket.getIds()) { id = conceptId; T rule = null; rule = bucket.getById(id); add(rule); } } catch (NoRuleException e) { throw new IllegalStateException("No rule of type " + getRuleTypeName() + " width " + id + " not found in overhanded bucket. The bucket is in an inconsistent state."); } } }
/** * Returns a rule of type {@code T} by its id. * * @return The rule with the requested id. * * @throws <NRE> if the requested rule cannot be found. */ public T getById(String id) throws NRE { T rule = rules.get(id); if (null == rule) { throw newNoRuleException(id); } return rule; }
protected void add(T rule) throws DRE { if (rules.containsKey(rule.getId())) { throw newDuplicateRuleException("The " + getRuleTypeName() + " " + rule.getId() + " is already contained in this bucket"); } else { rules.put(rule.getId(), rule); } }
/** * Matches the rules in this bucket against the given pattern that might contain * wildcards, i.e. '*' and '?'. * * @param pattern * The pattern. * @return The list of matching rules. * @throws NoRuleException * If the pattern did not contained any wildcard and the referenced * rule is not contained in the bucket. */ public List<T> match(String pattern) throws NoRuleException { List<T> matches = new ArrayList<>(); if (pattern.contains("?") || pattern.contains("*")) { for (Map.Entry<String, T> entry : rules.entrySet()) { if (FilenameUtils.wildcardMatch(entry.getKey(), pattern)) { matches.add(entry.getValue()); } } } else { matches.add(getById(pattern)); } return matches; }