summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-03-22 12:28:35 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-03-22 12:28:35 -0400
commit01cb9f504c860bc1c037a44f3a76bf342a293d46 (patch)
tree02d1d34de0828159bbda93e881c93a6b45720f32 /BJC-Utils2/src/main/java/bjc/utils/data
parent4685955a62c430007c5c8ed2b915ffc618d30aca (diff)
General formatting cleanup and documentation update
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java23
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java24
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/IPair.java34
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/IPrecedent.java15
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Pair.java33
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyHolder.java28
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java40
7 files changed, 130 insertions, 67 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
index fba801b..5cf35ae 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java
@@ -32,7 +32,7 @@ public class GenHolder<T> implements IHolder<T> {
* Creates a new holder, with its state initialized to the provided
* value
*
- * @param held
+ * @param hld
* The state to initialize this holder to.
*/
public GenHolder(T hld) {
@@ -42,11 +42,21 @@ public class GenHolder<T> implements IHolder<T> {
/*
* (non-Javadoc)
*
+ * @see bjc.utils.data.IHolder#doWith(java.util.function.Consumer)
+ */
+ @Override
+ public void doWith(Consumer<T> f) {
+ f.accept(held);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see bjc.utils.data.IHolder#map(java.util.function.Function)
*/
@Override
public <NewT> IHolder<NewT> map(Function<T, NewT> f) {
- return new GenHolder<NewT>(f.apply(held));
+ return new GenHolder<>(f.apply(held));
}
/*
@@ -70,13 +80,4 @@ public class GenHolder<T> implements IHolder<T> {
public <E> E unwrap(Function<T, E> f) {
return f.apply(held);
}
-
- /*
- * (non-Javadoc)
- *
- * @see bjc.utils.data.IHolder#doWith(java.util.function.Consumer)
- */
- public void doWith(Consumer<T> f) {
- f.accept(held);
- }
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java
index ddcb2f6..3675842 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java
@@ -15,8 +15,19 @@ import java.util.function.Function;
public interface IHolder<T> {
/**
+ * Call a provided function with the value being held
+ *
+ * @param f
+ * The function to call
+ */
+ public void doWith(Consumer<T> f);
+
+ /**
* Return the result of applying the given transformation to the held
- * value Doesn't change the held value
+ * value. Doesn't change the held value.
+ *
+ * @param <NewT>
+ * The new type of the held value
*
* @param f
* The transformation to apply
@@ -37,17 +48,12 @@ public interface IHolder<T> {
/**
* Returns a raw mapped value, not contained in a GenHolder
*
+ * @param <E>
+ * The type of the value that is the end result
+ *
* @param f
* The function to use for mapping the value
* @return The mapped value outside of a GenHolder
*/
public <E> E unwrap(Function<T, E> f);
-
- /**
- * Call a provided function with the value being held
- *
- * @param f
- * The function to call
- */
- public void doWith(Consumer<T> f);
} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java
index fcf2b05..9923099 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java
@@ -4,12 +4,27 @@ import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
+/**
+ * An interface representing a pair of values
+ *
+ * @author ben
+ *
+ * @param <L>
+ * The type stored in the left side of the pair
+ * @param <R>
+ * The type stored in the right side of the pair
+ */
public interface IPair<L, R> {
/**
* Create a new pair by applying the given functions to the left/right.
* Does not change the internal contents of this pair.
*
+ * @param <L2>
+ * The new left type of the pair
+ * @param <R2>
+ * The new right type of the pair
+ *
* @param lf
* The function to apply to the left value.
* @param rf
@@ -20,21 +35,22 @@ public interface IPair<L, R> {
Function<R, R2> rf);
/**
+ * Execute an action with the values of this pair. Has no effect on the
+ * internal contents
+ *
+ * @param bc
+ * The action to execute on the values
+ */
+ public void doWith(BiConsumer<L, R> bc);
+
+ /**
* Collapse this pair to a single value. Does not change the internal
* contents of this pair.
+ * @param <E> The resulting type after merging
*
* @param bf
* The function to use to collapse the pair.
* @return The collapsed value.
*/
public <E> E merge(BiFunction<L, R, E> bf);
-
- /**
- * Execute an action with the values of this pair. Has no effect on the
- * internal contents
- *
- * @param bc
- * The action to execute on the values
- */
- public void doWith(BiConsumer<L, R> bc);
} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IPrecedent.java b/BJC-Utils2/src/main/java/bjc/utils/data/IPrecedent.java
index 1e00a59..a9ae0bc 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/IPrecedent.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/IPrecedent.java
@@ -6,15 +6,9 @@ package bjc.utils.data;
* @author ben
*
*/
+@FunctionalInterface
public interface IPrecedent {
/**
- * Get the precedence of the attached object
- *
- * @return The precedence of the attached object
- */
- public int getPrecedence();
-
- /**
* Create a new object with set precedence
*
* @param prec
@@ -24,4 +18,11 @@ public interface IPrecedent {
public static IPrecedent newSimplePrecedent(int prec) {
return () -> prec;
}
+
+ /**
+ * Get the precedence of the attached object
+ *
+ * @return The precedence of the attached object
+ */
+ public int getPrecedence();
} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
index 4e7f6ae..4a8fbc3 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
@@ -7,6 +7,8 @@ import java.util.function.Function;
/**
* Holds a pair of values of two different types.
*
+ * Is an eager variant of {@link IPair}
+ *
* @author ben
*
* @param <L>
@@ -45,28 +47,35 @@ public class Pair<L, R> implements IPair<L, R> {
r = right;
}
- /* (non-Javadoc)
- * @see bjc.utils.data.IPair#apply(java.util.function.Function, java.util.function.Function)
+ /*
+ * (non-Javadoc)
+ *
+ * @see bjc.utils.data.IPair#apply(java.util.function.Function,
+ * java.util.function.Function)
*/
@Override
public <L2, R2> IPair<L2, R2> apply(Function<L, L2> lf,
Function<R, R2> rf) {
- return new Pair<L2, R2>(lf.apply(l), rf.apply(r));
+ return new Pair<>(lf.apply(l), rf.apply(r));
}
- /* (non-Javadoc)
- * @see bjc.utils.data.IPair#merge(java.util.function.BiFunction)
- */
- @Override
- public <E> E merge(BiFunction<L, R, E> bf) {
- return bf.apply(l, r);
- }
-
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see bjc.utils.data.IPair#doWith(java.util.function.BiConsumer)
*/
@Override
public void doWith(BiConsumer<L, R> bc) {
bc.accept(l, r);
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see bjc.utils.data.IPair#merge(java.util.function.BiFunction)
+ */
+ @Override
+ public <E> E merge(BiFunction<L, R, E> bf) {
+ return bf.apply(l, r);
+ }
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyHolder.java
index 43dec86..6321cc2 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyHolder.java
@@ -21,9 +21,9 @@ import bjc.utils.funcdata.FunctionalList;
*/
public class LazyHolder<T> implements IHolder<T> {
/**
- * The source for a value held by this lazy holder
+ * List of queued actions to be performed on realized values
*/
- private Supplier<T> heldSrc;
+ private FunctionalList<Function<T, T>> actions;
/**
* The value internally held by this lazy holder
@@ -31,9 +31,9 @@ public class LazyHolder<T> implements IHolder<T> {
private T held;
/**
- * List of queued actions to be performed on realized values
+ * The source for a value held by this lazy holder
*/
- private FunctionalList<Function<T, T>> actions;
+ private Supplier<T> heldSrc;
/**
* Create a new lazy holder with the given supplier
@@ -58,8 +58,17 @@ public class LazyHolder<T> implements IHolder<T> {
}
@Override
+ public void doWith(Consumer<T> f) {
+ transform((val) -> {
+ f.accept(val);
+
+ return val;
+ });
+ }
+
+ @Override
public <NewT> IHolder<NewT> map(Function<T, NewT> f) {
- return new LazyHolder<NewT>(() -> {
+ return new LazyHolder<>(() -> {
if (held == null) {
return actions.reduceAux(heldSrc.get(),
Function<T, T>::apply, f::apply);
@@ -89,13 +98,4 @@ public class LazyHolder<T> implements IHolder<T> {
return f.apply(held);
}
- @Override
- public void doWith(Consumer<T> f) {
- transform((val) -> {
- f.accept(val);
-
- return val;
- });
- }
-
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java
index 2aab4ce..bd02b52 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java
@@ -6,20 +6,41 @@ import java.util.function.Function;
import bjc.utils.data.IPair;
+/**
+ * A lazy holder of two values
+ *
+ * Lazy variant of {@link IPair}
+ *
+ * @author ben
+ *
+ * @param <L>
+ * The type of value stored on the left side of the pair
+ * @param <R>
+ * The type of value stored on the right side of the pair
+ */
public class LazyPair<L, R> implements IPair<L, R> {
+ /**
+ * The backing store for this pair
+ */
protected LazyHolder<IPair<L, R>> del;
+ /*
+ * (non-Javadoc)
+ *
+ * @see bjc.utils.data.IPair#apply(java.util.function.Function,
+ * java.util.function.Function)
+ */
@Override
public <L2, R2> IPair<L2, R2> apply(Function<L, L2> lf,
Function<R, R2> rf) {
return del.unwrap((par) -> par.apply(lf, rf));
}
- @Override
- public <E> E merge(BiFunction<L, R, E> bf) {
- return del.unwrap((par) -> par.merge(bf));
- }
-
+ /*
+ * (non-Javadoc)
+ *
+ * @see bjc.utils.data.IPair#doWith(java.util.function.BiConsumer)
+ */
@Override
public void doWith(BiConsumer<L, R> bc) {
del.doWith((par) -> {
@@ -27,4 +48,13 @@ public class LazyPair<L, R> implements IPair<L, R> {
});
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see bjc.utils.data.IPair#merge(java.util.function.BiFunction)
+ */
+ @Override
+ public <E> E merge(BiFunction<L, R, E> bf) {
+ return del.unwrap((par) -> par.merge(bf));
+ }
}