commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r737572 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/fraction/FractionFormat.java site/xdoc/changes.xml test/org/apache/commons/math/fraction/FractionFormatTest.java
Date Sun, 25 Jan 2009 19:28:21 GMT
Author: psteitz
Date: Sun Jan 25 19:28:21 2009
New Revision: 737572

URL: http://svn.apache.org/viewvc?rev=737572&view=rev
Log:
Changed FractionFormat to extend NumberFormat.  JIRA: MATH-189

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/FractionFormat.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionFormatTest.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/FractionFormat.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/FractionFormat.java?rev=737572&r1=737571&r2=737572&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/FractionFormat.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/FractionFormat.java
Sun Jan 25 19:28:21 2009
@@ -19,7 +19,6 @@
 
 import java.io.Serializable;
 import java.text.FieldPosition;
-import java.text.Format;
 import java.text.NumberFormat;
 import java.text.ParseException;
 import java.text.ParsePosition;
@@ -36,7 +35,7 @@
  * @since 1.1
  * @version $Revision$ $Date$
  */
-public class FractionFormat extends Format implements Serializable {
+public class FractionFormat extends NumberFormat implements Serializable {
     
     /** Serializable version identifier */
     private static final long serialVersionUID = -6337346779577272306L;
@@ -183,7 +182,7 @@
     }
     
     /**
-     * Formats a object to produce a string.  <code>obj</code> must be either
a 
+     * Formats an object and appends the result to a StringBuffer. <code>obj</code>
must be either a 
      * {@link Fraction} object or a {@link Number} object.  Any other type of
      * object will result in an {@link IllegalArgumentException} being thrown.
      *
@@ -310,17 +309,6 @@
 
         return new Fraction(num.intValue(), den.intValue());
     }
-
-    /**
-     * Parses a string to produce a object.
-     * @param source the string to parse
-     * @param pos input/ouput parsing parameter.
-     * @return the parsed object.
-     * @see java.text.Format#parseObject(java.lang.String, java.text.ParsePosition)
-     */
-    public Object parseObject(String source, ParsePosition pos) {
-        return parse(source, pos);
-    }
     
     /**
      * Modify the denominator format.
@@ -388,4 +376,34 @@
          
          return ret;
     }
+
+    /**
+     * Formats a double value as a fraction and appends the result to a StringBuffer. 
+     *
+     * @param value the double value to format
+     * @param buffer StringBuffer to append to
+     * @param position On input: an alignment field, if desired. On output: the
+     *            offsets of the alignment field
+     * @return a reference to the appended buffer
+     * @see {@link #format(Object, StringBuffer, FieldPosition)}
+     */
+    public StringBuffer format(double value, StringBuffer buffer,
+            FieldPosition position) {
+        return format(Double.valueOf(value), buffer, position);
+    }
+
+    
+    /**
+     * Formats a long value as a fraction and appends the result to a StringBuffer. 
+     *
+     * @param value the long value to format
+     * @param buffer StringBuffer to append to
+     * @param position On input: an alignment field, if desired. On output: the
+     *            offsets of the alignment field
+     * @return a reference to the appended buffer
+     * @see {@link #format(Object, StringBuffer, FieldPosition)}
+     */
+    public StringBuffer format(long value, StringBuffer buffer, FieldPosition position) {
+        return format(Long.valueOf(value), buffer, position);
+    }
 }

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=737572&r1=737571&r2=737572&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sun Jan 25 19:28:21 2009
@@ -38,7 +38,10 @@
     <title>Commons Math Release Notes</title>
   </properties>
   <body>
-    <release version="2.0" date="TBD" description="TBD">   
+    <release version="2.0" date="TBD" description="TBD">
+      <action dev="psteitz" type="update" issue="MATH-189">
+        Changed FractionFormat to extend NumberFormat.
+      </action> 
       <action dev="psteitz" type="update" issue="MATH-242" due-to="Christian Semrau">
         Forced symmetry in binomialCoefficientLog and added test cases for MathUtils.
       </action>

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionFormatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionFormatTest.java?rev=737572&r1=737571&r2=737572&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionFormatTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionFormatTest.java
Sun Jan 25 19:28:21 2009
@@ -289,4 +289,12 @@
         assertEquals(nf, format.getWholeFormat());
         format.setWholeFormat(old);
     }
+    
+    public void testLongFormat() {
+        assertEquals("10 / 1", improperFormat.format(10l));
+    }
+    
+    public void testDoubleFormat() {
+        assertEquals("355 / 113", improperFormat.format(Math.PI));
+    }
 }



Mime
View raw message