From c2bfba92f0c2ce32b577f6b83604372b44841015 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 24 Mar 2014 10:47:37 -0600 Subject: [PATCH] consolidate duplicate Cell classes --- classpath/avian/Cell.java | 20 +++++++++++ classpath/avian/Continuations.java | 10 ------ test/extra/ComposableContinuations.java | 46 ++----------------------- 3 files changed, 23 insertions(+), 53 deletions(-) diff --git a/classpath/avian/Cell.java b/classpath/avian/Cell.java index 448c515c19..afe9c9213b 100644 --- a/classpath/avian/Cell.java +++ b/classpath/avian/Cell.java @@ -31,4 +31,24 @@ public class Cell { sb.append(")"); return sb.toString(); } + + public static Cell cons(Car car, Cell cdr) { + return new Cell(car, cdr); + } + + public static boolean equal(T a, T b) { + return (a == null && b == null) || (a != null && a.equals(b)); + } + + public static boolean equal(Cell a, Cell b) { + while (a != null) { + if (b == null || (! equal(a.value, b.value))) { + return false; + } + a = a.next; + b = b.next; + } + + return b == null; + } } diff --git a/classpath/avian/Continuations.java b/classpath/avian/Continuations.java index 09c42a2211..3401cbcd45 100644 --- a/classpath/avian/Continuations.java +++ b/classpath/avian/Continuations.java @@ -324,14 +324,4 @@ public class Continuations { this.next = next; } } - - private static class Cell { - public final T value; - public final Cell next; - - public Cell(T value, Cell next) { - this.value = value; - this.next = next; - } - } } diff --git a/test/extra/ComposableContinuations.java b/test/extra/ComposableContinuations.java index 0a517bb2f6..d33d39693b 100644 --- a/test/extra/ComposableContinuations.java +++ b/test/extra/ComposableContinuations.java @@ -1,7 +1,10 @@ package extra; import static avian.Continuations.shift; +import static avian.Cell.cons; +import static avian.Cell.equal; +import avian.Cell; import avian.Function; import avian.Continuations; @@ -87,47 +90,4 @@ public class ComposableContinuations { } }), 42)); } - - private static boolean equal(T a, T b) { - return (a == null && b == null) || (a != null && a.equals(b)); - } - - private static boolean equal(Cell a, Cell b) { - while (a != null) { - if (b == null || (! equal(a.car, b.car))) { - return false; - } - a = a.cdr; - b = b.cdr; - } - - return b == null; - } - - private static Cell cons(Car car, Cell cdr) { - return new Cell(car, cdr); - } - - private static class Cell { - public final Car car; - public final Cell cdr; - - public Cell(Car car, Cell cdr) { - this.car = car; - this.cdr = cdr; - } - - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("("); - for (Cell c = this; c != null; c = c.cdr) { - sb.append(c.car); - if (c.cdr != null) { - sb.append(", "); - } - } - sb.append(")"); - return sb.toString(); - } - } }