
de.schlegel11.lambdadecor.DefaultLambdaDecor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lambda-decor Show documentation
Show all versions of lambda-decor Show documentation
Decorator and strategy lambda mixture
package de.schlegel11.lambdadecor;
import java.util.Objects;
import java.util.function.Function;
/**
* @author Marcel Schlegel (schlegel11)
* @since 1.0
*/
public class DefaultLambdaDecor implements LambdaDecor {
private Behaviour behaviour;
private Unappliable unappliable = Unappliable.EMPTY;
private DefaultLambdaDecor(Behaviour behaviour) {
this.behaviour = Objects.requireNonNull(behaviour,
"Behaviour argument \"updateBehaviour\" for initialisation is null.");
}
public static LambdaDecor create(Behaviour behaviour) {
return new DefaultLambdaDecor<>(behaviour);
}
public static LambdaDecor create() {
return create(DefaultBehaviour.newBehaviour());
}
@Override
public void updateBehaviour(Function, Behaviour> behaviourFunction) {
Objects.requireNonNull(behaviourFunction,
"Function argument \"behaviourFunction\" in \"updateBehaviour(behaviourFunction)\" is null.");
behaviour = Objects.requireNonNull(behaviourFunction.apply(behaviour), "Behaviour is null.");
}
@Override
public T apply(T type) {
DecorPair pair = behaviour.apply(type);
unappliable = pair._Unapply;
return pair._Behaviour;
}
@Override
public void unapply() {
unappliable.unapply();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy