Skip to content

Commit

Permalink
Remove API that appears to be unnecessary with immutable types (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 authored May 3, 2021
1 parent 954e06d commit e11143b
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 362 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.spongepowered.math.vector.Vector3{{ E }};
* Represent a complex number of the form {@code x + yi}. The x and y components are stored as {@code {{ e }}}s. This class is immutable.
*/
@Immutable
public final class Complex{{ E }} implements Imaginary{{ E }}, Comparable<Complex{{ E }}>, Serializable, Cloneable {
public final class Complex{{ E }} implements Imaginary{{ E }}, Comparable<Complex{{ E }}>, Serializable {

private static final long serialVersionUID = 1;
/**
Expand All @@ -25,20 +25,14 @@ public final class Complex{{ E }} implements Imaginary{{ E }}, Comparable<Comple
* An immutable identity (1, 0) complex.
*/
public static final Complex{{ E }} IDENTITY = new Complex{{ E }}(1, 0);

private final {{ e }} x;
private final {{ e }} y;
@SuppressWarnings("Immutable")
private transient volatile boolean hashed = false;
@SuppressWarnings("Immutable")
private transient volatile int hashCode = 0;

/**
* Constructs a new complex. The components are set to the identity (1, 0).
*/
public Complex{{ E }}() {
this(1, 0);
}

/**
* Constructs a new complex from the {{ EOverload }} components.
*
Expand All @@ -60,16 +54,6 @@ public final class Complex{{ E }} implements Imaginary{{ E }}, Comparable<Comple
this.y = y;
}

/**
* Copy constructor.
*
* @param c The complex to copy
*/
public Complex{{ E }}(final Complex{{ E }} c) {
this.x = c.x;
this.y = c.y;
}

/**
* Gets the x (real) component of this complex.
*
Expand Down Expand Up @@ -513,11 +497,6 @@ public final class Complex{{ E }} implements Imaginary{{ E }}, Comparable<Comple
return (int) Math.signum(this.lengthSquared() - that.lengthSquared());
}

@Override
public Complex{{ E }} clone() {
return new Complex{{ E }}(this);
}

@Override
public String toString() {
return "(" + this.x + ", " + this.y + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.spongepowered.math.vector.Vector3{{ E }};
* immutable.</p>
*/
@Immutable
public final class Quaternion{{ E }} implements Imaginary{{ E }}, Comparable<Quaternion{{ E }}>, Serializable, Cloneable {
public final class Quaternion{{ E }} implements Imaginary{{ E }}, Comparable<Quaternion{{ E }}>, Serializable {

private static final long serialVersionUID = 1;
/**
Expand All @@ -35,13 +35,6 @@ public final class Quaternion{{ E }} implements Imaginary{{ E }}, Comparable<Qua
@SuppressWarnings("Immutable")
private transient volatile int hashCode = 0;

/**
* Constructs a new quaternion. The components are set to the identity (0, 0, 0, 1).
*/
public Quaternion{{ E }}() {
this(0, 0, 0, 1);
}

/**
* Constructs a new quaternion from the {{ EOverload }} components.
*
Expand Down Expand Up @@ -69,15 +62,6 @@ public final class Quaternion{{ E }} implements Imaginary{{ E }}, Comparable<Qua
this.w = w;
}

/**
* Copy constructor.
*
* @param q The quaternion to copy
*/
public Quaternion{{ E }}(final Quaternion{{ E }} q) {
this(q.x, q.y, q.z, q.w);
}

/**
* Gets the x (imaginary) component of this quaternion.
*
Expand Down Expand Up @@ -579,11 +563,6 @@ public final class Quaternion{{ E }} implements Imaginary{{ E }}, Comparable<Qua
return (int) Math.signum(this.lengthSquared() - q.lengthSquared());
}

@Override
public Quaternion{{ E }} clone() {
return new Quaternion{{ E }}(this);
}

@Override
public String toString() {
return "(" + this.x + ", " + this.y + ", " + this.z + ", " + this.w + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,24 @@ import org.spongepowered.math.vector.Vector2{{ E }};
* A 2x2 matrix containing values of type {@code {{ e }}}.`
*/
@Immutable
public final class Matrix2{{ E }} implements Matrix{{ E }}, Serializable, Cloneable {
public final class Matrix2{{ E }} implements Matrix{{ E }}, Serializable {

private static final long serialVersionUID = 1;
public static final Matrix2{{ E }} ZERO = new Matrix2{{ E }}(
0, 0,
0, 0);
public static final Matrix2{{ E }} IDENTITY = new Matrix2{{ E }}();
0, 0,
0, 0
);
public static final Matrix2{{ E }} IDENTITY = new Matrix2{{ E }}(
1, 0,
0, 1
);
private final {{ e }} m00, m01;
private final {{ e }} m10, m11;
@SuppressWarnings("Immutable")
private transient volatile boolean hashed = false;
@SuppressWarnings("Immutable")
private transient volatile int hashCode = 0;

public Matrix2{{ E }}() {
this(
1, 0,
0, 1);
}

public Matrix2{{ E }}(final Matrix2{{ E }} m) {
this(
m.m00, m.m01,
m.m10, m.m11);
}

public Matrix2{{ E }}(final Matrix3{{ E }} m) {
this(
m.get(0, 0), m.get(0, 1),
Expand Down Expand Up @@ -370,11 +362,6 @@ public final class Matrix2{{ E }} implements Matrix{{ E }}, Serializable, Clonea
return this.hashCode;
}

@Override
public Matrix2{{ E }} clone() {
return new Matrix2{{ E }}(this);
}

public static Matrix2{{ E }} from(final {{ e }} n) {
return n == 0 ? Matrix2{{ E}}.ZERO : new Matrix2{{ E }}(n, n, n, n);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import org.spongepowered.math.vector.Vector2{{ E }};
import org.spongepowered.math.vector.Vector3{{ E }};

@Immutable
public final class Matrix3{{ E }} implements Matrix{{ E }}, Serializable, Cloneable {
public final class Matrix3{{ E }} implements Matrix{{ E }}, Serializable {

private static final long serialVersionUID = 1;
public static final Matrix3{{ E }} ZERO = new Matrix3{{ E }}(
0, 0, 0,
0, 0, 0,
0, 0, 0
);
public static final Matrix3{{ E }} IDENTITY = new Matrix3{{ E }}();
public static final Matrix3{{ E }} IDENTITY = new Matrix3{{ E }}(
1, 0, 0,
0, 1, 0,
0, 0, 1
);
private final {{ e }} m00, m01, m02;
private final {{ e }} m10, m11, m12;
private final {{ e }} m20, m21, m22;
Expand All @@ -27,14 +31,6 @@ public final class Matrix3{{ E }} implements Matrix{{ E }}, Serializable, Clonea
@SuppressWarnings("Immutable")
private transient volatile int hashCode = 0;

public Matrix3{{ E }}() {
this(
1, 0, 0,
0, 1, 0,
0, 0, 1
);
}

public Matrix3{{ E }}(final Matrix2{{ E }} m) {
this(
m.get(0, 0), m.get(0, 1), 0,
Expand All @@ -43,14 +39,6 @@ public final class Matrix3{{ E }} implements Matrix{{ E }}, Serializable, Clonea
);
}

public Matrix3{{ E }}(final Matrix3{{ E }} m) {
this(
m.m00, m.m01, m.m02,
m.m10, m.m11, m.m12,
m.m20, m.m21, m.m22
);
}

public Matrix3{{ E }}(final Matrix4{{ E }} m) {
this(
m.get(0, 0), m.get(0, 1), m.get(0, 2),
Expand Down Expand Up @@ -474,11 +462,6 @@ public final class Matrix3{{ E }} implements Matrix{{ E }}, Serializable, Clonea
return this.hashCode;
}

@Override
public Matrix3{{ E }} clone() {
return new Matrix3{{ E }}(this);
}

public static Matrix3{{ E }} from(final {{ e }} n) {
return n == 0 ? Matrix3{{ E }}.ZERO : new Matrix3{{ E }}(n, n, n, n, n, n, n, n, n);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.spongepowered.math.vector.Vector3{{ E }};
import org.spongepowered.math.vector.Vector4{{ E }};

@Immutable
public final class Matrix4{{ E }} implements Matrix{{ E }}, Serializable, Cloneable {
public final class Matrix4{{ E }} implements Matrix{{ E }}, Serializable {

private static final long serialVersionUID = 1;
public static final Matrix4{{ E }} ZERO = new Matrix4{{ E }}(
Expand All @@ -21,7 +21,12 @@ public final class Matrix4{{ E }} implements Matrix{{ E }}, Serializable, Clonea
0, 0, 0, 0,
0, 0, 0, 0
);
public static final Matrix4{{ E }} IDENTITY = new Matrix4{{ E }}();
public static final Matrix4{{ E }} IDENTITY = new Matrix4{{ E }}(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);
private final {{ e }} m00, m01, m02, m03;
private final {{ e }} m10, m11, m12, m13;
private final {{ e }} m20, m21, m22, m23;
Expand All @@ -31,14 +36,6 @@ public final class Matrix4{{ E }} implements Matrix{{ E }}, Serializable, Clonea
@SuppressWarnings("Immutable")
private transient volatile int hashCode = 0;

public Matrix4{{ E }}() {
this(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
}

public Matrix4{{ E }}(final Matrix2{{ E }} m) {
this(
m.get(0, 0), m.get(0, 1), 0, 0,
Expand All @@ -55,14 +52,6 @@ public final class Matrix4{{ E }} implements Matrix{{ E }}, Serializable, Clonea
0, 0, 0, 0);
}

public Matrix4{{ E }}(final Matrix4{{ E }} m) {
this(
m.m00, m.m01, m.m02, m.m03,
m.m10, m.m11, m.m12, m.m13,
m.m20, m.m21, m.m22, m.m23,
m.m30, m.m31, m.m32, m.m33);
}

public Matrix4{{ E }}(final MatrixN{{ E }} m) {
this.m00 = m.get(0, 0);
this.m01 = m.get(0, 1);
Expand Down Expand Up @@ -599,11 +588,6 @@ public final class Matrix4{{ E }} implements Matrix{{ E }}, Serializable, Clonea
return this.hashCode;
}

@Override
public Matrix4{{ E }} clone() {
return new Matrix4{{ E }}(this);
}

public static Matrix4{{ E }} from(final {{ e }} n) {
return n == 0 ? Matrix4{{ E }}.ZERO : new Matrix4{{ E }}(n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.spongepowered.math.HashFunctions;
import org.spongepowered.math.TrigMath;

@Immutable
public final class Vector2{{ E }} implements Vector{{ E }}, Comparable<Vector2{{ E }}>, Serializable, Cloneable {
public final class Vector2{{ E }} implements Vector{{ E }}, Comparable<Vector2{{ E }}>, Serializable {

private static final long serialVersionUID = 1;
public static final Vector2{{ E }} ZERO = new Vector2{{ E }}(0, 0);
Expand All @@ -24,14 +24,6 @@ public final class Vector2{{ E }} implements Vector{{ E }}, Comparable<Vector2{{
@SuppressWarnings("Immutable")
private transient volatile int hashCode = 0;

public Vector2{{ E }}() {
this(0, 0);
}

public Vector2{{ E }}(final Vector2{{ E }} v) {
this(v.x, v.y);
}

public Vector2{{ E }}(final Vector3{{ E }} v) {
this(v.x(), v.y());
}
Expand Down Expand Up @@ -373,11 +365,6 @@ public final class Vector2{{ E }} implements Vector{{ E }}, Comparable<Vector2{{
return this.hashCode;
}

@Override
public Vector2{{ E }} clone() {
return new Vector2{{ E }}(this);
}

@Override
public String toString() {
return "(" + this.x + ", " + this.y + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.spongepowered.math.HashFunctions;
import org.spongepowered.math.TrigMath;

@Immutable
public final class Vector3{{ E }} implements Vector{{ E }}, Comparable<Vector3{{ E }}>, Serializable, Cloneable {
public final class Vector3{{ E }} implements Vector{{ E }}, Comparable<Vector3{{ E }}>, Serializable {

private static final long serialVersionUID = 1;
public static final Vector3{{ E }} ZERO = new Vector3{{ E }}(0, 0, 0);
Expand All @@ -28,10 +28,6 @@ public final class Vector3{{ E }} implements Vector{{ E }}, Comparable<Vector3{{
@SuppressWarnings("Immutable")
private transient volatile int hashCode = 0;

public Vector3{{ E }}() {
this(0, 0, 0);
}

public Vector3{{ E }}(final Vector2{{ E }} v) {
this(v, 0);
}
Expand All @@ -44,10 +40,6 @@ public final class Vector3{{ E }} implements Vector{{ E }}, Comparable<Vector3{{
this(v.x(), v.y(), z);
}

public Vector3{{ E }}(final Vector3{{ E }} v) {
this(v.x, v.y, v.z);
}

public Vector3{{ E }}(final Vector4{{ E }} v) {
this(v.x(), v.y(), v.z());
}
Expand Down Expand Up @@ -407,11 +399,6 @@ public final class Vector3{{ E }} implements Vector{{ E }}, Comparable<Vector3{{
return this.hashCode;
}

@Override
public Vector3{{ E }} clone() {
return new Vector3{{ E }}(this);
}

@Override
public String toString() {
return "(" + this.x + ", " + this.y + ", " + this.z + ")";
Expand Down
Loading

0 comments on commit e11143b

Please sign in to comment.