private void validate(Object key, Object value) {
   if (!keyPredicate.evaluate(key)) {
     throw new IllegalArgumentException("Cannot add key - Predicate rejected it");
   }
   if (!valuePredicate.evaluate(value)) {
     throw new IllegalArgumentException("Cannot add value - Predicate rejected it");
   }
 }
Beispiel #2
0
 public static Collection filter(Collection paramCollection, .Predicate paramPredicate)
 {
   Iterator localIterator = paramCollection.iterator();
   while (localIterator.hasNext()) {
     if (!paramPredicate.evaluate(localIterator.next())) {
       localIterator.remove();
     }
   }
   return paramCollection;
 }
 public static <E> List<E> selectRejected(
     final Collection<? extends E> inputCollection, final Predicate<? super E> predicate) {
   List<E> result = new ArrayList<E>();
   for (E elem : inputCollection) {
     if (!predicate.evaluate(elem)) {
       result.add(elem);
     }
   }
   return result;
 }
  /**
   * Wait for a condition, expressed via a {@link Predicate} to become true.
   *
   * @param timeout maximum time in milliseconds to wait for the predicate to become true.
   * @param predicate predicate waiting on.
   */
  protected void waitFor(int timeout, Predicate predicate) throws Exception {
    ParamChecker.notNull(predicate, "predicate");
    long mustEnd = System.currentTimeMillis() + timeout;

    boolean eval;
    while (!(eval = predicate.evaluate()) && System.currentTimeMillis() < mustEnd) {
      LOG.info("Waiting up to {} msec", mustEnd - System.currentTimeMillis());
      Thread.sleep(100);
    }
    if (!eval) {
      throw new Exception("Waiting timed out after " + timeout + " msec");
    }
  }
 public Object setValue(Object o) {
   if (!predicate.evaluate(o)) {
     throw new IllegalArgumentException("Cannot set value - Predicate rejected it");
   }
   return entry.setValue(o);
 }
 @Override
 public boolean evaluate(Object... inputs) {
   return !a.evaluate(inputs);
 }
 @Override
 public boolean evaluate(T input) {
   return _predicate.evaluate(input);
 }