public byte[] byteSerialize() { byte[] face = ArrayUtil.intToByteArray(f.val()); byte[] dir = ArrayUtil.intToByteArray(d.val()); byte[] s = ArrayUtil.intToByteArray(slice); return ArrayUtil.concatenateArrays(face, dir, s); }
@Override public int compareTo(Twist t) { int diff; diff = f.val() - t.f.val(); if (diff != 0) return diff; diff = d.val() - t.d.val(); if (diff != 0) return diff; return slice - t.slice; }
public static Twist byteDeserialize(byte[] src) { int face = ArrayUtil.byteArrayToInt(Arrays.copyOfRange(src, 0, 4)); int dir = ArrayUtil.byteArrayToInt(Arrays.copyOfRange(src, 4, 8)); int s = ArrayUtil.byteArrayToInt(Arrays.copyOfRange(src, 8, 12)); return createTwist(Face.getFace(face), Dir.getDir(dir), s); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(String.format("%-4s", f.toString() + d.toString() + (slice == 0 ? "" : slice))); return sb.toString(); }
private static int getKey(Face f, Dir d, int s) { return (f.val() << 16) + (d.val() << 8) + s; }