@Test public void testRelative() throws Exception { assertEquals(new RelativeVector(1, 2, 3, false, false, false), deserializeRelative("1,2,3")); assertEquals(new RelativeVector(1, 2, 3, true, false, false), deserializeRelative("~1,2,3")); assertEquals(new RelativeVector(1, 2, 3, true, true, false), deserializeRelative("~1,~2,3")); assertEquals(new RelativeVector(1, 2, 3, true, true, true), deserializeRelative("~1,~2,~3")); assertEquals(new RelativeVector(1, 2, 3, true, false, true), deserializeRelative("~1,2,~3")); assertEquals(new ImmutableVector(1, 2, 3), new RelativeVector(1, 2, 3, false, false, false)); assertNotEquals(new RelativeVector(1, 2, 4, false, false, true), new RelativeVector(1, 2, 3, false, false, true)); assertEquals(new ImmutableVector(2, 3, 4), new RelativeVector(1, 1, 1, true, true, true) .with(new ImmutableVector(1, 2, 3))); assertEquals(new ImmutableVector(0, 1, 2), new RelativeVector(-1, -1, -1, true, true, true) .with(new ImmutableVector(1, 2, 3))); }
@Nonnull public static RelativeVector deserializeRelative(@Nonnull String string) throws NullPointerException { checkNotNullOrEmpty(string); String[] split = DESERIALIZE.split(string, 4); checkArgument(split.length == 3, string + " is in an invalid format."); boolean xRel = split[0].startsWith("~"); boolean yRel = split[1].startsWith("~"); boolean zRel = split[2].startsWith("~"); double x = parseDouble(StringUtils.defaultIfEmpty(split[0].substring(xRel ? 1 : 0), "0")); double y = parseDouble(StringUtils.defaultIfEmpty(split[1].substring(yRel ? 1 : 0), "0")); double z = parseDouble(StringUtils.defaultIfEmpty(split[2].substring(zRel ? 1 : 0), "0")); return new RelativeVector(x, y, z, xRel, yRel, zRel); }
VectorUtils { @Nonnull public static RelativeVector deserializeRelative(@Nonnull String string) throws NullPointerException { checkNotNullOrEmpty(string); String[] split = DESERIALIZE.split(string, 4); checkArgument(split.length == 3, string + " is in an invalid format."); boolean xRel = split[0].startsWith("~"); boolean yRel = split[1].startsWith("~"); boolean zRel = split[2].startsWith("~"); double x = parseDouble(StringUtils.defaultIfEmpty(split[0].substring(xRel ? 1 : 0), "0")); double y = parseDouble(StringUtils.defaultIfEmpty(split[1].substring(yRel ? 1 : 0), "0")); double z = parseDouble(StringUtils.defaultIfEmpty(split[2].substring(zRel ? 1 : 0), "0")); return new RelativeVector(x, y, z, xRel, yRel, zRel); } }
VectorUtils { @Nonnull public static RelativeVector deserializeRelative(@Nonnull String string) throws NullPointerException { checkNotNullOrEmpty(string); String[] split = DESERIALIZE.split(string, 4); checkArgument(split.length == 3, string + " is in an invalid format."); boolean xRel = split[0].startsWith("~"); boolean yRel = split[1].startsWith("~"); boolean zRel = split[2].startsWith("~"); double x = parseDouble(StringUtils.defaultIfEmpty(split[0].substring(xRel ? 1 : 0), "0")); double y = parseDouble(StringUtils.defaultIfEmpty(split[1].substring(yRel ? 1 : 0), "0")); double z = parseDouble(StringUtils.defaultIfEmpty(split[2].substring(zRel ? 1 : 0), "0")); return new RelativeVector(x, y, z, xRel, yRel, zRel); }  }
VectorUtils { @Nonnull public static RelativeVector deserializeRelative(@Nonnull String string) throws NullPointerException { checkNotNullOrEmpty(string); String[] split = DESERIALIZE.split(string, 4); checkArgument(split.length == 3, string + " is in an invalid format."); boolean xRel = split[0].startsWith("~"); boolean yRel = split[1].startsWith("~"); boolean zRel = split[2].startsWith("~"); double x = parseDouble(StringUtils.defaultIfEmpty(split[0].substring(xRel ? 1 : 0), "0")); double y = parseDouble(StringUtils.defaultIfEmpty(split[1].substring(yRel ? 1 : 0), "0")); double z = parseDouble(StringUtils.defaultIfEmpty(split[2].substring(zRel ? 1 : 0), "0")); return new RelativeVector(x, y, z, xRel, yRel, zRel); }  @Nonnull static Vector deserialize(@Nonnull String string); static String serialize(Vector vector); static Vector getRandomVectorWithin(Vector min, Vector max); static boolean isWithin(Vector test, Vector min, Vector max); static boolean isSameBlock(@Nullable Vector o, @Nullable Vector o2); static Vector getIntermediateWithXValue(Vector origin, Vector vec, double x); static Vector getIntermediateWithYValue(Vector origin, Vector vec, double y); static Vector getIntermediateWithZValue(Vector origin, Vector vec, double z); @Nonnull static RelativeVector deserializeRelative(@Nonnull String string); static String serializeRelative(RelativeVector vector); }
VectorUtils { @Nonnull public static RelativeVector deserializeRelative(@Nonnull String string) throws NullPointerException { checkNotNullOrEmpty(string); String[] split = DESERIALIZE.split(string, 4); checkArgument(split.length == 3, string + " is in an invalid format."); boolean xRel = split[0].startsWith("~"); boolean yRel = split[1].startsWith("~"); boolean zRel = split[2].startsWith("~"); double x = parseDouble(StringUtils.defaultIfEmpty(split[0].substring(xRel ? 1 : 0), "0")); double y = parseDouble(StringUtils.defaultIfEmpty(split[1].substring(yRel ? 1 : 0), "0")); double z = parseDouble(StringUtils.defaultIfEmpty(split[2].substring(zRel ? 1 : 0), "0")); return new RelativeVector(x, y, z, xRel, yRel, zRel); }  @Nonnull static Vector deserialize(@Nonnull String string); static String serialize(Vector vector); static Vector getRandomVectorWithin(Vector min, Vector max); static boolean isWithin(Vector test, Vector min, Vector max); static boolean isSameBlock(@Nullable Vector o, @Nullable Vector o2); static Vector getIntermediateWithXValue(Vector origin, Vector vec, double x); static Vector getIntermediateWithYValue(Vector origin, Vector vec, double y); static Vector getIntermediateWithZValue(Vector origin, Vector vec, double z); @Nonnull static RelativeVector deserializeRelative(@Nonnull String string); static String serializeRelative(RelativeVector vector);  }