X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2FUtil.java;h=4a03410e25531721a41de50fa9b95af2d10da525;hb=74aebd92f41d03f4a44c9a455ef8c05465136412;hp=0cd4b8241a7c50a5a0d4b83648b40155da234785;hpb=de79184d60c80d6775b368e61d3368de032952e8;p=Mograsim.git diff --git a/era.mi/src/era/mi/logic/Util.java b/era.mi/src/era/mi/logic/Util.java index 0cd4b824..4a03410e 100644 --- a/era.mi/src/era/mi/logic/Util.java +++ b/era.mi/src/era/mi/logic/Util.java @@ -2,29 +2,26 @@ package era.mi.logic; import java.util.Arrays; -public final class Util -{ - - @SuppressWarnings("unchecked") - public static T[] concat(T[]... arrays) - { - if (arrays.length == 0) - throw new IllegalArgumentException("Cannot concatenate 0 arrays."); +public final class Util { - int length = 0; - for (T[] array : arrays) - length += array.length; + @SuppressWarnings("unchecked") + public static T[] concat(T[]... arrays) { + if (arrays.length == 0) + throw new IllegalArgumentException("Cannot concatenate 0 arrays."); - T[] newArray = Arrays.copyOf(arrays[0], length); - int appendIndex = arrays[0].length; - for (int i = 1; i < arrays.length; i++) - { - System.arraycopy(arrays[i], 0, newArray, appendIndex, arrays[i].length); - appendIndex += arrays[i].length; - } + int length = 0; + for (T[] array : arrays) + length += array.length; + + T[] newArray = Arrays.copyOf(arrays[0], length); + int appendIndex = arrays[0].length; + for (int i = 1; i < arrays.length; i++) { + System.arraycopy(arrays[i], 0, newArray, appendIndex, arrays[i].length); + appendIndex += arrays[i].length; + } - return newArray; - } + return newArray; + } // @SuppressWarnings("unchecked") // public static T[][] split(T[] array, int... lengths) @@ -48,61 +45,51 @@ public final class Util // return (T[][]) newArray; // } - public static Bit[] and(Bit[] a, Bit[] b) - { - return binBitOp(a, b, (bA, bB) -> Bit.and(bA, bB)); - } + public static Bit[] and(Bit[] a, Bit[] b) { + return binBitOp(a, b, (bA, bB) -> Bit.and(bA, bB)); + } - public static Bit[] or(Bit[] a, Bit[] b) - { - return binBitOp(a, b, (bA, bB) -> Bit.or(bA, bB)); - } + public static Bit[] or(Bit[] a, Bit[] b) { + return binBitOp(a, b, (bA, bB) -> Bit.or(bA, bB)); + } - public static Bit[] xor(Bit[] a, Bit[] b) - { - return binBitOp(a, b, (bA, bB) -> Bit.xor(bA, bB)); - } + public static Bit[] xor(Bit[] a, Bit[] b) { + return binBitOp(a, b, (bA, bB) -> Bit.xor(bA, bB)); + } - private static Bit[] binBitOp(Bit[] a, Bit[] b, BitOp op) - { - if (a.length != b.length) - throw new IllegalArgumentException("Bit Arrays were not of equal length."); - Bit[] out = new Bit[a.length]; - for (int i = 0; i < a.length; i++) - { - out[i] = op.execute(a[i], b[i]); + private static Bit[] binBitOp(Bit[] a, Bit[] b, BitOp op) { + if (a.length != b.length) + throw new IllegalArgumentException("Bit Arrays were not of equal length."); + Bit[] out = new Bit[a.length]; + for (int i = 0; i < a.length; i++) { + out[i] = op.execute(a[i], b[i]); + } + return out; } - return out; - } - public static Bit[] not(Bit[] a) - { - Bit[] out = new Bit[a.length]; - for (int i = 0; i < a.length; i++) - { - out[i] = a[i].not(); + public static Bit[] not(Bit[] a) { + Bit[] out = new Bit[a.length]; + for (int i = 0; i < a.length; i++) { + out[i] = a[i].not(); + } + return out; } - return out; - } - - /** - * uses the {@link Bit#combineWith(Bit)} method, does not create a new array, - * the result is stored in the first array. - * - * @author Christian Femers - */ - public static Bit[] combineInto(Bit[] dest, Bit[] addition) - { - if (dest.length != addition.length) - throw new IllegalArgumentException("Bit Arrays were not of equal length."); - for (int i = 0; i < addition.length; i++) { - dest[i] = dest[i].combineWith(addition[i]); + + /** + * uses the {@link Bit#combineWith(Bit)} method, does not create a new array, the result is stored in the first array. + * + * @author Christian Femers + */ + public static Bit[] combineInto(Bit[] dest, Bit[] addition) { + if (dest.length != addition.length) + throw new IllegalArgumentException("Bit Arrays were not of equal length."); + for (int i = 0; i < addition.length; i++) { + dest[i] = dest[i].combineWith(addition[i]); + } + return dest; } - return dest; - } - interface BitOp - { - Bit execute(Bit a, Bit b); - } + interface BitOp { + Bit execute(Bit a, Bit b); + } }