BigComplex { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; BigComplex other = (BigComplex) obj; return re.compareTo(other.re) == 0 && im.compareTo(other.im) == 0; } private  BigComplex(BigDecimal re, BigDecimal im); BigComplex add(BigComplex value); BigComplex add(BigComplex value, MathContext mathContext); BigComplex add(BigDecimal value, MathContext mathContext); BigComplex add(BigDecimal value); BigComplex add(double value); BigComplex subtract(BigComplex value); BigComplex subtract(BigComplex value, MathContext mathContext); BigComplex subtract(BigDecimal value, MathContext mathContext); BigComplex subtract(BigDecimal value); BigComplex subtract(double value); BigComplex multiply(BigComplex value); BigComplex multiply(BigComplex value, MathContext mathContext); BigComplex multiply(BigDecimal value, MathContext mathContext); BigComplex multiply(BigDecimal value); BigComplex multiply(double value); BigComplex divide(BigComplex value, MathContext mathContext); BigComplex divide(BigDecimal value, MathContext mathContext); BigComplex divide(double value, MathContext mathContext); BigComplex reciprocal(MathContext mathContext); BigComplex conjugate(); BigComplex negate(); BigDecimal abs(MathContext mathContext); BigDecimal angle(MathContext mathContext); BigDecimal absSquare(MathContext mathContext); boolean isReal(); BigComplex re(); BigComplex im(); BigComplex round(MathContext mathContext); @Override int hashCode(); @Override boolean equals(Object obj); boolean strictEquals(Object obj); @Override String toString(); static BigComplex valueOf(BigDecimal real); static BigComplex valueOf(double real); static BigComplex valueOf(double real, double imaginary); static BigComplex valueOf(BigDecimal real, BigDecimal imaginary); static BigComplex valueOfPolar(BigDecimal radius, BigDecimal angle, MathContext mathContext); static BigComplex valueOfPolar(double radius, double angle, MathContext mathContext); static final BigComplex ZERO; static final BigComplex ONE; static final BigComplex I; final BigDecimal re; final BigDecimal im; }
@Test public void testEquals() { assertEquals(false, BigComplex.ONE.equals(null)); assertEquals(false, BigComplex.ONE.equals("string")); assertEquals(false, BigComplex.ONE.equals(BigComplex.ZERO)); assertEquals(false, BigComplex.valueOf(1, 2).equals(BigComplex.valueOf(1, 999))); assertEquals(false, BigComplex.valueOf(1, 2).equals(BigComplex.valueOf(999, 2))); assertEquals(true, BigComplex.ZERO.equals(BigComplex.ZERO)); assertEquals(true, BigComplex.valueOf(1, 2).equals(BigComplex.valueOf(1, 2))); assertEquals(true, BigComplex.valueOf(1, 2).equals(BigComplex.valueOf(1.0, 2.0))); assertEquals(true, BigComplex.valueOf(1, 2).equals(BigComplex.valueOf(new BigDecimal("1.00000"), new BigDecimal("2.0000")))); }