summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-02-21 15:40:55 -0500
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-02-21 15:40:55 -0500
commitd7648dd32feedd293be253f827d0a9618d53d043 (patch)
tree439a2563f70c102d35ae8768492dfd359aeb4956 /BJC-Utils2/src
parent77a797089a2e065cc8cf2a83ae8356b16591aebe (diff)
Some refactoring of other packages
Diffstat (limited to 'BJC-Utils2/src')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java61
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/IPrecedent.java27
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Pair.java49
3 files changed, 96 insertions, 41 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 f969960..f5d553c 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java
@@ -3,61 +3,70 @@ package bjc.utils.data;
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
+ * 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
+ *
* @author ben
*
- * @param <T> The type of the data being held
+ * @param <T>
+ * The type of the data being held
*/
public class GenHolder<T> {
/**
* The state this holder is responsible for.
*/
public T held;
-
+
/**
* Creates a new empty holder, with its state set to null
*/
public GenHolder() {
held = null;
}
-
+
/**
- * Creates a new holder, with its state initialized to the provided value
+ * Creates a new holder, with its state initialized to the provided
+ * value
*
- * @param held The state to initialize this holder to.
+ * @param held
+ * The state to initialize this holder to.
*/
public GenHolder(T hld) {
held = hld;
}
-
+
+ /**
+ * Return the result of applying the given transformation to the held
+ * value Doesn't change the held value
+ *
+ * @param f
+ * The transformation to apply
+ * @return A holder with the transformed value
+ */
+ public <NewT> GenHolder<NewT> map(Function<T, NewT> f) {
+ return new GenHolder<NewT>(f.apply(held));
+ }
+
/**
- * Apply the given transformation to the held value.
- * Returns the holder for allowing chaining of transforms
- * @param f The transform to apply to the value
+ * Apply the given transformation to the held value. Returns the holder
+ * for allowing chaining of transforms
+ *
+ * @param f
+ * The transform to apply to the value
* @return The holder
*/
public GenHolder<T> transform(Function<T, T> f) {
held = f.apply(held);
-
+
return this;
}
-
- /**
- * Return the result of applying the given transformation to the held value
- * Doesn't change the held value
- * @param f The transformation to apply
- * @return A holder with the transformed value
- */
- public <NewT> GenHolder<NewT> map(Function<T, NewT> f) {
- return new GenHolder<NewT>(f.apply(held));
- }
-
+
/**
* Returns a raw mapped value, not contained in a GenHolder
- * @param f The function to use for mapping the value
+ *
+ * @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) {
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IPrecedent.java b/BJC-Utils2/src/main/java/bjc/utils/data/IPrecedent.java
new file mode 100644
index 0000000..98258ef
--- /dev/null
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/IPrecedent.java
@@ -0,0 +1,27 @@
+package bjc.utils.data;
+
+/**
+ * Represents something that has a set precedence
+ *
+ * @author ben
+ *
+ */
+public interface IPrecedent {
+ /**
+ * Get the precedence of the attached object
+ *
+ * @return The precedence of the attached object
+ */
+ int getPrecedence();
+
+ /**
+ * Create a new object with set precedence
+ *
+ * @param prec
+ * The precedence of the object to handle
+ * @return A new object with set precedence
+ */
+ static IPrecedent newSimplePrecedent(int prec) {
+ return () -> prec;
+ }
+} \ 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 14ac52d..11ce79c 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
@@ -5,47 +5,66 @@ import java.util.function.Function;
/**
* Holds a pair of values of two different types.
+ *
* @author ben
*
- * @param <L> The type of the thing held on the left (first)
- * @param <R> The type of the thing held on the right (second)
+ * @param <L>
+ * The type of the thing held on the left (first)
+ * @param <R>
+ * The type of the thing held on the right (second)
*/
public class Pair<L, R> {
+ /**
+ * The left value of the pair
+ */
public L l;
+
+ /**
+ * The right value of the pair
+ */
public R r;
/**
* Create a new pair that holds two nulls.
*/
public Pair() {
-
+
}
-
+
/**
* Create a new pair holding the specified values.
- * @param left The value to hold on the left.
- * @param right The value to hold on the right.
+ *
+ * @param left
+ * The value to hold on the left.
+ * @param right
+ * The value to hold on the right.
*/
public Pair(L left, R right) {
l = left;
r = right;
}
-
+
/**
* Create a new pair by applying the given functions to the left/right.
- * Does not change the internal contents of this pair.
- * @param lf The function to apply to the left value.
- * @param rf The function to apply to the right value.
+ * Does not change the internal contents of this pair.
+ *
+ * @param lf
+ * The function to apply to the left value.
+ * @param rf
+ * The function to apply to the right value.
* @return A new pair containing the two modified values.
*/
- public <L2, R2> Pair<L2, R2> apply(Function<L, L2> lf, Function<R, R2> rf) {
+ public <L2, R2> Pair<L2, R2> apply(Function<L, L2> lf,
+ Function<R, R2> rf) {
return new Pair<L2, R2>(lf.apply(l), rf.apply(r));
}
-
+
/**
- * Collapse this pair to a single value.
- * Does not change the internal contents of this pair.
- * @param bf The function to use to collapse the pair.
+ * Collapse this pair to a single value. Does not change the internal
+ * contents of this pair.
+ *
+ * @param bf
+ * The function to use to collapse the pair.
* @return The collapsed value.
*/
public <E> E merge(BiFunction<L, R, E> bf) {