summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BJC-Utils2/.classpath7
-rw-r--r--BJC-Utils2/.settings/org.eclipse.jdt.core.prefs14
-rw-r--r--BJC-Utils2/pom.xml11
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java66
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Pair.java54
5 files changed, 138 insertions, 14 deletions
diff --git a/BJC-Utils2/.classpath b/BJC-Utils2/.classpath
index 0a1dadd..2e39f26 100644
--- a/BJC-Utils2/.classpath
+++ b/BJC-Utils2/.classpath
@@ -12,15 +12,12 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
diff --git a/BJC-Utils2/.settings/org.eclipse.jdt.core.prefs b/BJC-Utils2/.settings/org.eclipse.jdt.core.prefs
index abec6ca..13b3428 100644
--- a/BJC-Utils2/.settings/org.eclipse.jdt.core.prefs
+++ b/BJC-Utils2/.settings/org.eclipse.jdt.core.prefs
@@ -1,5 +1,13 @@
eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/BJC-Utils2/pom.xml b/BJC-Utils2/pom.xml
index c6b5c63..7eb6f43 100644
--- a/BJC-Utils2/pom.xml
+++ b/BJC-Utils2/pom.xml
@@ -15,11 +15,10 @@
</properties>
<dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ </dependency>
</dependencies>
</project>
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java
new file mode 100644
index 0000000..f969960
--- /dev/null
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java
@@ -0,0 +1,66 @@
+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
+ * @author ben
+ *
+ * @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
+ *
+ * @param held The state to initialize this holder to.
+ */
+ public GenHolder(T hld) {
+ held = hld;
+ }
+
+ /**
+ * 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
+ * @return The mapped value outside of a GenHolder
+ */
+ public <E> E unwrap(Function<T, E> f) {
+ return f.apply(held);
+ }
+}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
new file mode 100644
index 0000000..14ac52d
--- /dev/null
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
@@ -0,0 +1,54 @@
+package bjc.utils.data;
+
+import java.util.function.BiFunction;
+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)
+ */
+public class Pair<L, R> {
+ public L l;
+ 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.
+ */
+ 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.
+ * @return A new pair containing the two modified values.
+ */
+ 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.
+ * @return The collapsed value.
+ */
+ public <E> E merge(BiFunction<L, R, E> bf) {
+ return bf.apply(l, r);
+ }
+}