Example usage for org.apache.commons.functor BinaryPredicate BinaryPredicate

List of usage examples for org.apache.commons.functor BinaryPredicate BinaryPredicate

Introduction

In this page you can find the example usage for org.apache.commons.functor BinaryPredicate BinaryPredicate.

Prototype

BinaryPredicate

Source Link

Usage

From source file:org.apache.commons.functor.example.map.PredicatedMap.java

public PredicatedMap(Map<K, V> map, final Predicate<K> keyPredicate, final Predicate<V> valuePredicate) {
    super(map);/*from   w ww.  j a va2  s .  c o  m*/
    setOnPut(new ConditionalBinaryFunction<Map<K, V>, Object[], V>(new BinaryPredicate<Map<K, V>, Object[]>() {
        @SuppressWarnings("unchecked")
        public boolean test(Map<K, V> a, Object[] b) {
            return keyPredicate.test((K) Array.get(b, 0)) && valuePredicate.test((V) Array.get(b, 1));
        }
    }, DEFAULT_ON_PUT, BinaryProcedureBinaryFunction
            .<Map<K, V>, Object[], V>adapt(new Throw<Map<K, V>, Object>(new IllegalArgumentException()))));

    setOnPutAll(new BinaryProcedure<Map<K, V>, Map<K, V>>() {
        public void run(Map<K, V> dest, Map<K, V> src) {
            for (Iterator<Map.Entry<K, V>> iter = src.entrySet().iterator(); iter.hasNext();) {
                Map.Entry<K, V> pair = iter.next();
                if (keyPredicate.test(pair.getKey()) && valuePredicate.test(pair.getValue())) {
                    dest.put(pair.getKey(), pair.getValue());
                }
            }
        }
    });
}

From source file:org.mili.core.io.DirectoryCleanerTest.java

@Test
public void shouldCleanDirectoryRecursive() {
    cleaner.isExpiring = new BinaryPredicate<Long, Integer>() {
        @Override//from  w w w . ja v a2  s  . c  om
        public boolean test(Long time, Integer days) {
            return true;
        }
    };
    cleaner.cleanDirectory(dir_01, true, 1);
    assertEquals(1, dir_01.listFiles().length);
    assertEquals(0, dir_02.listFiles().length);
}