summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-04-13 16:54:12 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-04-13 16:54:12 -0400
commitba07771f8333f1b098ab8a9ec9fec886b72b9cc0 (patch)
tree7d1326235d021cb4767065cddd25bbe9fbdf5ce1 /BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java
parent12637af8d6b7b9b2d96deb89e5a09e05178a8e65 (diff)
Removed old data types
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java113
1 files changed, 0 insertions, 113 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java
deleted file mode 100644
index bd87f07..0000000
--- a/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package bjc.utils.data;
-
-import java.util.function.Consumer;
-import java.util.function.Function;
-
-/**
- * Holds a single value of a specific type. This is used for indirect
- * references to data, and more specifically for accessing non-final
- * variables from a lambda. AKA the identity monad
- *
- * This is an eager variant of {@link IHolder}
- *
- * @author ben
- *
- * @param <T>
- * The type of the data being held
- */
-public class GenHolder<T> implements IHolder<T> {
- /**
- * The state this holder is responsible for.
- */
- private T heldValue;
-
- /**
- * Creates a new empty holder, with its state set to null
- */
- public GenHolder() {
- heldValue = null;
- }
-
- /**
- * Creates a new holder, with its state initialized to the provided
- * value
- *
- * @param held
- * The state to initialize this holder to.
- */
- public GenHolder(T held) {
- heldValue = held;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see bjc.utils.data.IHolder#doWith(java.util.function.Consumer)
- */
- @Override
- public void doWith(Consumer<T> action) {
- if (action == null) {
- throw new NullPointerException("Action must be non-null");
- }
-
- action.accept(heldValue);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see bjc.utils.data.IHolder#map(java.util.function.Function)
- */
- @Override
- public <NewT> IHolder<NewT> map(Function<T, NewT> transformer) {
- if (transformer == null) {
- throw new NullPointerException("Transformer must be non-null");
- }
-
- return new GenHolder<>(transformer.apply(heldValue));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see bjc.utils.data.IHolder#transform(java.util.function.Function)
- */
- @Override
- public IHolder<T> transform(Function<T, T> transformer) {
- if (transformer == null) {
- throw new NullPointerException("Transformer must be non-null");
- }
-
- heldValue = transformer.apply(heldValue);
-
- return this;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see bjc.utils.data.IHolder#unwrap(java.util.function.Function)
- */
- @Override
- public <E> E unwrap(Function<T, E> unwrapper) {
- if (unwrapper == null) {
- throw new NullPointerException("Unwrapper must be null");
- }
-
- return unwrapper.apply(heldValue);
- }
-
- @Override
- public String toString() {
- if (heldValue == null) {
- return "(null)";
- }
-
- return heldValue.toString();
- }
-
- @Override
- public <E> IHolder<E> bind(Function<T, IHolder<E>> binder) {
- return binder.apply(heldValue);
- }
-}