diff options
| author | Ben Culkin <scorpress@gmail.com> | 2023-11-08 19:45:47 -0500 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2023-11-08 19:45:47 -0500 |
| commit | 81b2acf9e1294d28ac61d6915c6162dc0008a00c (patch) | |
| tree | 2b09770dfa23d8d238bce6c4ff267d422a03dffa | |
| parent | 0a3946e579a0c358a13aa1621fecc3e220cd6e38 (diff) | |
| parent | cbf4dda5cc09dc6d2c3c10329e7941923cc04e2e (diff) | |
Merge branch 'trunk' of git@ashardalon.com:esodata.git into trunk
| -rw-r--r-- | .classpath | 15 | ||||
| -rw-r--r-- | .settings/org.eclipse.jdt.core.prefs | 6 | ||||
| -rw-r--r-- | pom.xml | 4 | ||||
| -rw-r--r-- | src/main/java/bjc/data/Contexts.java | 17 | ||||
| -rw-r--r-- | src/main/java/bjc/typeclasses/FunList.java | 17 | ||||
| -rw-r--r-- | src/test/java/bjc/test/TestUtils.java | 20 | ||||
| -rw-r--r-- | src/test/java/bjc/test/data/ContextsTest.java | 64 |
7 files changed, 121 insertions, 22 deletions
@@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src/example/java"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> @@ -24,5 +24,18 @@ <attribute name="test" value="true"/> </attributes> </classpathentry> + <classpathentry excluding="**" kind="src" output="target/classes" path="data"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + <attribute name="optional" value="true"/> + </attributes> + </classpathentry> + <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + <attribute name="test" value="true"/> + <attribute name="optional" value="true"/> + </attributes> + </classpathentry> <classpathentry kind="output" path="target/classes"/> </classpath> diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index cf2cd45..2af1e7b 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,8 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 -org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.compliance=11 org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=17 +org.eclipse.jdt.core.compiler.source=11 @@ -24,8 +24,8 @@ </scm> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <maven.compiler.source>17</maven.compiler.source> - <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>11</maven.compiler.source> + <maven.compiler.target>11</maven.compiler.target> <!-- github server corresponds to entry in ~/.m2/settings.xml --> <github.global.server>github</github.global.server> </properties> diff --git a/src/main/java/bjc/data/Contexts.java b/src/main/java/bjc/data/Contexts.java index 699a450..7de1b5f 100644 --- a/src/main/java/bjc/data/Contexts.java +++ b/src/main/java/bjc/data/Contexts.java @@ -117,4 +117,21 @@ class ContextImpl implements Context { public Context getParent() { return parent; } + + @Override + public int hashCode() { + return Objects.hash(objects, parent); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ContextImpl other = (ContextImpl) obj; + return Objects.equals(objects, other.objects) && Objects.equals(parent, other.parent); + } }
\ No newline at end of file diff --git a/src/main/java/bjc/typeclasses/FunList.java b/src/main/java/bjc/typeclasses/FunList.java index 78717af..f849a16 100644 --- a/src/main/java/bjc/typeclasses/FunList.java +++ b/src/main/java/bjc/typeclasses/FunList.java @@ -4,22 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Function; -/** - * Represent a FunList data structure which contains a B and zero or more As - * @author bjcul - * - * @param <A> The type for A - * @param <B> The type for B - */ -public sealed interface FunList<A, B> permits FunList.Done<A, B>, FunList.More<A, B> { - /** - * Represents a FunList that contains a B and zero As - * - * @author bjcul - * - * @param <A> Unused type - * @param <B> Type of the contained value - */ +public /*sealed*/ interface FunList<A, B> /*permits FunList.Done<A, B>, FunList.More<A, B>*/ { public final class Done<A, B> implements FunList<A, B> { private final B val; diff --git a/src/test/java/bjc/test/TestUtils.java b/src/test/java/bjc/test/TestUtils.java index 04cdf70..664aaef 100644 --- a/src/test/java/bjc/test/TestUtils.java +++ b/src/test/java/bjc/test/TestUtils.java @@ -144,4 +144,24 @@ public class TestUtils { public static <T> void assertStackEquals(bjc.esodata.Stack<T> src, T... exps) { assertArrayEquals(exps, src.toArray()); } + + public static <T> void assertOneOf(T actual, T... expecteds) { + for (T expected : expecteds) { + if (expected.equals(actual)) return; + } + + StringBuilder builder = new StringBuilder(); + builder.append("Value '"); + builder.append(actual.toString()); + builder.append("' was not one of the expected values: "); + for (T expected : expecteds) { + builder.append("'"); + builder.append(expected.toString()); + builder.append("', "); + } + builder.deleteCharAt(builder.length() - 1); + builder.deleteCharAt(builder.length() - 1); + + assertFalse("Value '%' was no", true); + } } diff --git a/src/test/java/bjc/test/data/ContextsTest.java b/src/test/java/bjc/test/data/ContextsTest.java new file mode 100644 index 0000000..cff6e06 --- /dev/null +++ b/src/test/java/bjc/test/data/ContextsTest.java @@ -0,0 +1,64 @@ +package bjc.test.data; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import bjc.data.Context; +import bjc.data.Contexts; +import bjc.test.TestUtils; + +public class ContextsTest { + + @Test(expected = UnsupportedOperationException.class) + public void testNull() { + Context ctx = Contexts.NULL; + ctx.register("a", "b"); + } + @Test + public void testCreate() { + Context ctx = Contexts.create(); + + assertTrue(ctx.getParent() == Contexts.NULL); + + ctx.register("a", "b"); + + assertEquals("b", ctx.get("a")); + assertEquals("b", ctx.get(String.class)); + assertEquals("b", ctx.get("a", String.class)); + } + + @Test + public void testCreateContext() { + Context parent = Contexts.create(); + + assertTrue(parent.getParent() == Contexts.NULL); + + parent.register("a", "1"); + + Context child1 = Contexts.create(parent); + Context child2 = Contexts.create(parent); + + Context child11 = Contexts.create(child1); + Context child22 = Contexts.create(child2); + + child1.register("b", "2"); + child1.register("c", "3"); + + child2.register("d", "4"); + child2.register("e", "5"); + + child11.register("a", "6"); + + child22.register("a", "7"); + child22.register("f", "8"); + + assertEquals("2", child1.get("b")); + assertEquals("1", child1.get("a")); + assertEquals("6", child11.get("a")); + assertEquals("7", child22.get("a")); + + TestUtils.assertOneOf(child1.get(String.class), "1", "2", "3"); + } + +} |
