Integrated new types, tests still work, not used yet
[Mograsim.git] / era.mi / src / era / mi / logic / Util.java
index 5a6e4f5..0567138 100644 (file)
@@ -2,10 +2,14 @@ package era.mi.logic;
 \r
 import java.util.Arrays;\r
 \r
-public final class Util {\r
+import era.mi.logic.types.Bit;\r
+\r
+public final class Util\r
+{\r
 \r
        @SuppressWarnings("unchecked")\r
-       public static <T> T[] concat(T[]... arrays) {\r
+       public static <T> T[] concat(T[]... arrays)\r
+       {\r
                if (arrays.length == 0)\r
                        throw new IllegalArgumentException("Cannot concatenate 0 arrays.");\r
 \r
@@ -15,7 +19,8 @@ public final class Util {
 \r
                T[] newArray = Arrays.copyOf(arrays[0], length);\r
                int appendIndex = arrays[0].length;\r
-               for (int i = 1; i < arrays.length; i++) {\r
+               for (int i = 1; i < arrays.length; i++)\r
+               {\r
                        System.arraycopy(arrays[i], 0, newArray, appendIndex, arrays[i].length);\r
                        appendIndex += arrays[i].length;\r
                }\r
@@ -45,31 +50,38 @@ public final class Util {
 //             return (T[][]) newArray;\r
 //     }\r
 \r
-       public static Bit[] and(Bit[] a, Bit[] b) {\r
-               return binBitOp(a, b, (bA, bB) -> Bit.and(bA, bB));\r
+       public static Bit[] and(Bit[] a, Bit[] b)\r
+       {\r
+               return binBitOp(a, b, Bit::and);\r
        }\r
 \r
-       public static Bit[] or(Bit[] a, Bit[] b) {\r
-               return binBitOp(a, b, (bA, bB) -> Bit.or(bA, bB));\r
+       public static Bit[] or(Bit[] a, Bit[] b)\r
+       {\r
+               return binBitOp(a, b, Bit::or);\r
        }\r
 \r
-       public static Bit[] xor(Bit[] a, Bit[] b) {\r
-               return binBitOp(a, b, (bA, bB) -> Bit.xor(bA, bB));\r
+       public static Bit[] xor(Bit[] a, Bit[] b)\r
+       {\r
+               return binBitOp(a, b, Bit::xor);\r
        }\r
 \r
-       private static Bit[] binBitOp(Bit[] a, Bit[] b, BitOp op) {\r
+       private static Bit[] binBitOp(Bit[] a, Bit[] b, BitOp op)\r
+       {\r
                if (a.length != b.length)\r
                        throw new IllegalArgumentException("Bit Arrays were not of equal length.");\r
                Bit[] out = new Bit[a.length];\r
-               for (int i = 0; i < a.length; i++) {\r
+               for (int i = 0; i < a.length; i++)\r
+               {\r
                        out[i] = op.execute(a[i], b[i]);\r
                }\r
                return out;\r
        }\r
 \r
-       public static Bit[] not(Bit[] a) {\r
+       public static Bit[] not(Bit[] a)\r
+       {\r
                Bit[] out = new Bit[a.length];\r
-               for (int i = 0; i < a.length; i++) {\r
+               for (int i = 0; i < a.length; i++)\r
+               {\r
                        out[i] = a[i].not();\r
                }\r
                return out;\r
@@ -80,16 +92,19 @@ public final class Util {
         * \r
         * @author Christian Femers\r
         */\r
-       public static Bit[] combineInto(Bit[] dest, Bit[] addition) {\r
+       public static Bit[] combineInto(Bit[] dest, Bit[] addition)\r
+       {\r
                if (dest.length != addition.length)\r
                        throw new IllegalArgumentException("Bit Arrays were not of equal length.");\r
-               for (int i = 0; i < addition.length; i++) {\r
-                       dest[i] = dest[i].combineWith(addition[i]);\r
+               for (int i = 0; i < addition.length; i++)\r
+               {\r
+                       dest[i] = dest[i].join(addition[i]);\r
                }\r
                return dest;\r
        }\r
 \r
-       interface BitOp {\r
+       interface BitOp\r
+       {\r
                Bit execute(Bit a, Bit b);\r
        }\r
 }\r