Ejemplo n.º 1
0
 private void validateForPrioritize(S s) {
   if (s.strict()) {
     throw new IllegalArgumentException(s.name() + ": not prioritizable: is strict");
   }
   if (!this.range.contains(s)) {
     throw new IllegalArgumentException(s.name() + ": not contained or is backup");
   }
 }
Ejemplo n.º 2
0
 /**
  * Removes the given strategy and returns true if it was found and removed. If <code>s</code> is
  * strict then it will be searched by target, else it will be searched by name.
  *
  * @param s to remove
  * @return true if strategy has been removed, false otherwise
  */
 public boolean remove(S s) {
   if (s.strict()) {
     return this.strict.remove(s.target()) != null;
   } else {
     final ListIterator<S> it = this.range.listIterator();
     while (it.hasNext()) {
       if (it.next().name().equals(s.name())) {
         it.remove();
         return true;
       }
     }
     return false;
   }
 }
Ejemplo n.º 3
0
 /**
  * Adds the given strategy. If <code>s.strict()</code> and this instance already contains a
  * strict strategy with the exact same target then <code>s</code> will replace the contained
  * strategy.
  *
  * @param s to add
  * @return the replaced strict strategy, if any, or null
  */
 public S add(S s) {
   if (s.strict()) {
     return this.strict.put(s.target(), s);
   } else {
     final ListIterator<S> it = this.range.listIterator();
     while (it.hasNext()) {
       final S crt = it.next();
       if (crt.target().isAssignableFrom(s.target())) {
         it.set(s);
         it.add(crt);
         return null;
       }
     }
     this.range.add(s);
     return null;
   }
 }
Ejemplo n.º 4
0
 /**
  * Returns <code>true</code> if the given strategy is contained within this instance, <code>
  * false</code> otherwise.
  *
  * @param s to search
  * @return true if strategy has been found, false otherwise
  */
 public boolean contains(S s) {
   // if s is strict then search in strict:
   if (s.strict() && this.strict.containsKey(s.target())) {
     return true;
   }
   // else search in range:
   if (this.containsName(this.range, s.name())) {
     return true;
   }
   // search for it in backup, if any:
   if (this.backup != null) {
     if (this.containsName(this.backup, s.name())) {
       return true;
     }
   }
   return false;
 }