Author: erans
Date: Fri Jan  7 20:33:12 2011
New Revision: 1056493

URL: http://svn.apache.org/viewvc?rev=1056493&view=rev
Log:
MATH-422
Removed setters. Removed coresponding unit tests.
Added a "getInstance" method so that some tests can still work.
Removed a seemingly unnecessary call to the "clone" method.

Modified:
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexFormat.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/complex/ComplexFormatAbstractTest.java

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexFormat.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexFormat.java?rev=1056493&r1=1056492&r2=1056493&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexFormat.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/ComplexFormat.java
 Fri Jan  7 20:33:12 2011
@@ -91,23 +91,43 @@ public class ComplexFormat {
      * @param format the custom format for both real and imaginary parts.
      */
     public ComplexFormat(String imaginaryCharacter, NumberFormat format) {
-        this(imaginaryCharacter, format, (NumberFormat)format.clone());
+        this(imaginaryCharacter, format, format);
     }
 
     /**
      * Create an instance with a custom imaginary character, a custom number
      * format for the real part, and a custom number format for the imaginary
      * part.
+     *
      * @param imaginaryCharacter The custom imaginary character.
      * @param realFormat the custom format for the real part.
      * @param imaginaryFormat the custom format for the imaginary part.
+     * @throws NullArgumentException if {...@code imaginaryCharacter} is
+     * {...@code null}.
+     * @throws NoDataException if {...@code imaginaryCharacter} is an
+     * empty string.
+     * @throws NullArgumentException if {...@code imaginaryFormat} is 
{...@code null}.
+     * @throws NullArgumentException if {...@code realFormat} is {...@code 
null}.
      */
-    public ComplexFormat(String imaginaryCharacter, NumberFormat realFormat,
-            NumberFormat imaginaryFormat) {
-        super();
-        setImaginaryCharacter(imaginaryCharacter);
-        setImaginaryFormat(imaginaryFormat);
-        setRealFormat(realFormat);
+    public ComplexFormat(String imaginaryCharacter,
+                         NumberFormat realFormat,
+                         NumberFormat imaginaryFormat) {
+        if (imaginaryCharacter == null) {
+            throw new NullArgumentException();
+        }
+        if (imaginaryCharacter.length() == 0) {
+            throw new NoDataException();
+        }
+        if (imaginaryFormat == null) {
+            throw new NullArgumentException(LocalizedFormats.IMAGINARY_FORMAT);
+        }
+        if (realFormat == null) {
+            throw new NullArgumentException(LocalizedFormats.REAL_FORMAT);
+        }
+
+        this.imaginaryCharacter = imaginaryCharacter;
+        this.imaginaryFormat = imaginaryFormat;
+        this.realFormat = realFormat;
     }
 
     /**
@@ -238,6 +258,18 @@ public class ComplexFormat {
     }
 
     /**
+     * Returns the default complex format for the given locale.
+     * @param locale the specific locale used by the format.
+     * @param imaginaryCharacter Imaginary character.
+     * @return the complex format specific to the given locale.
+     */
+    public static ComplexFormat getInstance(String imaginaryCharacter,
+                                            Locale locale) {
+        NumberFormat f = CompositeFormat.getDefaultNumberFormat(locale);
+        return new ComplexFormat(imaginaryCharacter, f);
+    }
+
+    /**
      * Access the realFormat.
      * @return the realFormat.
      */
@@ -330,46 +362,4 @@ public class ComplexFormat {
         return new Complex(re.doubleValue(), im.doubleValue() * sign);
 
     }
-
-    /**
-     * Modify the imaginaryCharacter.
-     * @param imaginaryCharacter The new imaginaryCharacter value.
-     * @throws NullArgumentException if {...@code imaginaryCharacter} is
-     * {...@code null}.
-     * @throws NoDataException if {...@code imaginaryCharacter} is an
-     * empty string.
-     */
-    public void setImaginaryCharacter(String imaginaryCharacter) {
-        if (imaginaryCharacter == null) {
-            throw new NullArgumentException();
-        }
-        if (imaginaryCharacter.length() == 0) {
-            throw new NoDataException();
-        }
-        this.imaginaryCharacter = imaginaryCharacter;
-    }
-
-    /**
-     * Modify the imaginaryFormat.
-     * @param imaginaryFormat The new imaginaryFormat value.
-     * @throws NullArgumentException if {...@code imaginaryFormat} is 
{...@code null}.
-     */
-    public void setImaginaryFormat(NumberFormat imaginaryFormat) {
-        if (imaginaryFormat == null) {
-            throw new NullArgumentException(LocalizedFormats.IMAGINARY_FORMAT);
-        }
-        this.imaginaryFormat = imaginaryFormat;
-    }
-
-    /**
-     * Modify the realFormat.
-     * @param realFormat The new realFormat value.
-     * @throws NullArgumentException if {...@code realFormat} is {...@code 
null}.
-     */
-    public void setRealFormat(NumberFormat realFormat) {
-        if (realFormat == null) {
-            throw new NullArgumentException(LocalizedFormats.REAL_FORMAT);
-        }
-        this.realFormat = realFormat;
-    }
 }

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/complex/ComplexFormatAbstractTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/complex/ComplexFormatAbstractTest.java?rev=1056493&r1=1056492&r2=1056493&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/complex/ComplexFormatAbstractTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/complex/ComplexFormatAbstractTest.java
 Fri Jan  7 20:33:12 2011
@@ -40,8 +40,7 @@ public abstract class ComplexFormatAbstr
 
     protected ComplexFormatAbstractTest() {
         complexFormat = ComplexFormat.getInstance(getLocale());
-        complexFormatJ = ComplexFormat.getInstance(getLocale());
-        complexFormatJ.setImaginaryCharacter("j");
+        complexFormatJ = ComplexFormat.getInstance("j", getLocale());
     }
 
     @Test
@@ -308,68 +307,18 @@ public abstract class ComplexFormatAbstr
     @Test
     public void testGetImaginaryFormat() {
         NumberFormat nf = NumberFormat.getInstance();
-        ComplexFormat cf = new ComplexFormat();
-
-        Assert.assertNotSame(nf, cf.getImaginaryFormat());
-        cf.setImaginaryFormat(nf);
+        ComplexFormat cf = new ComplexFormat(nf);
         Assert.assertSame(nf, cf.getImaginaryFormat());
     }
 
     @Test
-    public void testSetImaginaryFormatNull() {
-        try {
-            ComplexFormat cf = new ComplexFormat();
-            cf.setImaginaryFormat(null);
-            Assert.fail();
-        } catch (NullArgumentException ex) {
-            // success
-        }
-    }
-
-    @Test
-    public void testSetRealFormatNull() {
-        try {
-            ComplexFormat cf = new ComplexFormat();
-            cf.setRealFormat(null);
-            Assert.fail();
-        } catch (NullArgumentException ex) {
-            // success
-        }
-    }
-
-    @Test
     public void testGetRealFormat() {
         NumberFormat nf = NumberFormat.getInstance();
-        ComplexFormat cf = new ComplexFormat();
-
-        Assert.assertNotSame(nf, cf.getRealFormat());
-        cf.setRealFormat(nf);
+        ComplexFormat cf = new ComplexFormat(nf);
         Assert.assertSame(nf, cf.getRealFormat());
     }
 
     @Test
-    public void testSetImaginaryCharacterNull() {
-        try {
-            ComplexFormat cf = new ComplexFormat();
-            cf.setImaginaryCharacter(null);
-            Assert.fail();
-        } catch (NullArgumentException ex) {
-            // success
-        }
-    }
-
-    @Test
-    public void testSetImaginaryCharacterEmpty() {
-        try {
-            ComplexFormat cf = new ComplexFormat();
-            cf.setImaginaryCharacter("");
-            Assert.fail();
-        } catch (MathIllegalArgumentException ex) {
-            // success
-        }
-    }
-
-    @Test
     public void testFormatNumber() {
         ComplexFormat cf = ComplexFormat.getInstance(getLocale());
         Double pi = Double.valueOf(FastMath.PI);


Reply via email to