コード例 #1
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;
   }
 }
コード例 #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;
   }
 }
コード例 #3
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;
 }