package org.libsmith.anvil;

import java.util.Optional;
import java.util.function.Function;

/**
 * @author Dmitriy Balakin <dmitriy.balakin@0x0000.ru>
 * @created 21.03.16 3:10
 */
public class Holder<T> {
    private T value;

    public Holder()
    { }

    public Holder(T value) {
        setValue(value);
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = value;
    }

    public boolean hasValue() {
        return getValue() != null;
    }

    public <R> Optional<R> apply(Function<? super T, ? extends R> function) {
        return hasValue() ? Optional.of(function.apply(getValue())) : Optional.empty();
    }
}

@@ -75,24 +75,96 @@
 unction.
-Function
+Consumer;%0Aimport java.util.function.Function;%0Aimport java.util.function.Supplier
 ;%0A%0A/**%0A 
@@ -270,16 +270,51 @@
 lder%3CT%3E 
+implements Supplier%3CT%3E, Consumer%3CT%3E
 %7B%0A    pr
@@ -330,29 +330,32 @@
 alue;%0A%0A    p
-ublic
+rotected
  Holder()%0A  
@@ -376,49 +376,139 @@
 lic 
-Holder(T value) %7B%0A        setValue(value)
+static %3CT%3E Holder%3CT%3E of(T value) %7B%0A        Holder%3CT%3E holder = new Holder%3C%3E();%0A        holder.setValue(value);%0A        return holder
 ;%0A  
@@ -883,11 +883,160 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public void accept(T value) %7B%0A        setValue(value);%0A    %7D%0A%0A    @Override%0A    public T get() %7B%0A        return getValue();%0A    %7D
 %0A%7D%0A

Add Supplier and Consumer ability to Holder