Example usage for org.apache.commons.functor.adapter BinaryProcedureBinaryFunction BinaryProcedureBinaryFunction

List of usage examples for org.apache.commons.functor.adapter BinaryProcedureBinaryFunction BinaryProcedureBinaryFunction

Introduction

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

Prototype

public BinaryProcedureBinaryFunction(BinaryProcedure<? super L, ? super R> procedure) 

Source Link

Document

Create a new BinaryProcedureBinaryFunction.

Usage

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

public FixedSizeMap(Map<K, V> map) {
    super(map);/*from w ww. j  a v a2s  .c  o m*/
    setOnPut(new BinaryFunction<Map<K, V>, Object[], V>() {
        public V evaluate(Map<K, V> map, Object[] b) {
            K key = (K) Array.get(b, 0);
            V value = (V) Array.get(b, 1);
            if (map.containsKey(key)) {
                return map.put(key, value);
            } else {
                throw new IllegalArgumentException();
            }
        }
    });

    setOnPutAll(new BinaryProcedure<Map<K, V>, Map<K, V>>() {
        public void run(Map<K, V> a, Map<K, V> b) {
            Map<K, V> dest = a;
            Map<K, V> src = b;

            if (GeneratorContains.instance().test(IteratorToGeneratorAdapter.adapt(src.keySet().iterator()),
                    Not.not(new ContainsKey(dest)))) {
                throw new IllegalArgumentException();
            } else {
                dest.putAll(src);
            }
        }
    });

    setOnRemove(new BinaryProcedureBinaryFunction<Map<K, V>, K, V>(
            (BinaryProcedure<? super Map<K, V>, ? super K>) new Throw<K, V>(
                    new UnsupportedOperationException())));
    setOnClear(new Throw<K, V>(new UnsupportedOperationException()));
}