sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1454417 - in /sis/ip-review: NumberConverter.xhtml rev/29615/ rev/29615/HEADER.html rev/29615/NumberConverter.xhtml
Date Fri, 08 Mar 2013 15:11:19 GMT
Author: desruisseaux
Date: Fri Mar  8 15:11:18 2013
New Revision: 1454417

URL: http://svn.apache.org/r1454417
Log:
Added IP review for NumberConverter.

Added:
    sis/ip-review/NumberConverter.xhtml   (with props)
    sis/ip-review/rev/29615/
    sis/ip-review/rev/29615/HEADER.html   (with props)
    sis/ip-review/rev/29615/NumberConverter.xhtml   (with props)

Added: sis/ip-review/NumberConverter.xhtml
URL: http://svn.apache.org/viewvc/sis/ip-review/NumberConverter.xhtml?rev=1454417&view=auto
==============================================================================
--- sis/ip-review/NumberConverter.xhtml (added)
+++ sis/ip-review/NumberConverter.xhtml Fri Mar  8 15:11:18 2013
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta charset="UTF-8"/>
+    <title>NumberConverter history</title>
+    <style type="text/css" media="all">
+      @import url("./reports.css");
+    </style>
+  </head>
+  <body>
+    <div>
+      <h1>NumberConverter history</h1>
+  <p>Click on the commit message for inspecting the <code>diff</code> and
how the code has been rewritten.</p>
+<p><b>Command line:</b></p>
+<blockquote><code>svn log -r31996:22627 http://svn.osgeo.org/geotools/trunk/modules/library/main/src/main/java/org/geotools/util/NumericConverterFactory.java</code></blockquote>
+<table>
+  <tr>
+    <th>Rev.</th>
+    <th>Date</th>
+    <th>Author</th>
+    <th class="last">Message</th>
+  </tr>
+<tr><td class="rev">30648</td><td>2008-06-12</td><td>acuster</td><td>Copyright
headers: lib/main, this time with feeling (and the el in Toolkit)</td></tr>
+<tr><td class="rev">30558</td><td>2008-06-06</td><td>acuster</td><td>Copyright
review: update headers on library/main</td></tr>
+<tr><td class="rev">30258</td><td>2008-05-08</td><td>acuster</td><td>Reshuffle
the top level repo: drop uDig, move up trunk, tags, and branches.</td></tr>
+<tr><td class="rev">30257</td><td>2008-05-08</td><td>acuster</td><td>Move
trunk/gt/ directory contents up to trunk/ and drop gt</td></tr>
+<tr><td class="rev">29615</td><td>2008-03-13</td><td class="unav">jgarnett</td><td><a
href="rev/29615/NumberConverter.xhtml">Added ColorConverterFactory so I could retire hacks
from Filters utility class; made the NumberConverterFactory agree with the needs of the SLD
utility class - it was tripping up over parsing floating point representation into intergers.
See GEOT-1726</a></td></tr>
+<tr><td class="rev">29148</td><td>2008-02-08</td><td class="unav">jdeolive</td><td><a
href="rev/29615/NumberConverter.xhtml">ensuring numeric conversions do not suffer from
precision issues</a></td></tr>
+<tr><td class="rev">28922</td><td>2008-01-24</td><td>acuster</td><td>Bump
the (at)since version to 2.5 since WKTParser was cut from 2.4</td></tr>
+<tr><td class="rev">28540</td><td>2007-12-29</td><td>acuster</td><td>Hide
buttons which are not yet used</td></tr>
+<tr><td class="rev">27927</td><td>2007-11-18</td><td class="unav">jdeolive</td><td><a
href="rev/29615/NumberConverter.xhtml">trimming whitespace when attempting to convert from
string to numeric</a></td></tr>
+<tr><td class="rev">26759</td><td>2007-08-29</td><td class="unav">saul.farber</td><td><a
href="rev/29615/NumberConverter.xhtml">fixup for string-based conversion to target class</a></td></tr>
+<tr><td class="rev">26756</td><td>2007-08-29</td><td class="unav">saul.farber</td><td><a
href="rev/29615/NumberConverter.xhtml">fixes to support all-string expression literal internals</a></td></tr>
+<tr><td class="rev">23637</td><td>2007-01-01</td><td class="unav">jdeolive</td><td><a
href="rev/29615/NumberConverter.xhtml">javadocs</a></td></tr>
+<tr><td class="rev">23075</td><td>2006-11-28</td><td class="unav">jdeolive</td><td><a
href="rev/29615/NumberConverter.xhtml">removed canEncode from Converter interface</a></td></tr>
+<tr><td class="rev">22817</td><td>2006-11-17</td><td>desruisseaux</td><td>Fixed
SVN properties for all Java files.</td></tr>
+<tr><td class="rev">22627</td><td>2006-11-07</td><td class="unav">jdeolive</td><td><a
href="rev/29615/NumberConverter.xhtml">added converter implementation</a></td></tr>
+</table>
+    </div>
+  </body>
+</html>

Propchange: sis/ip-review/NumberConverter.xhtml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/ip-review/NumberConverter.xhtml
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: sis/ip-review/rev/29615/HEADER.html
URL: http://svn.apache.org/viewvc/sis/ip-review/rev/29615/HEADER.html?rev=1454417&view=auto
==============================================================================
--- sis/ip-review/rev/29615/HEADER.html (added)
+++ sis/ip-review/rev/29615/HEADER.html Fri Mar  8 15:11:18 2013
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta charset="UTF-8"/>
+    <title>Revision 29615</title>
+  </head>
+  <body>
+    <div>
+      <h1>Revision 29615</h1>
+<table>
+  <tr><td><b>Author:</b></td><td>jgarnett</td></tr>
+  <tr><td><b>Date:</b></td><td>2008-03-13</td></tr>
+  <tr><td><b>Message:</b></td><td>Added ColorConverterFactory
so I could retire hacks from Filters utility class; made the NumberConverterFactory agree
with the needs of the SLD utility class - it was tripping up over parsing floating point representation
into intergers. See GEOT-1726</td></tr>
+</table>
+    </div>
+  </body>
+</html>

Propchange: sis/ip-review/rev/29615/HEADER.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/ip-review/rev/29615/HEADER.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: sis/ip-review/rev/29615/NumberConverter.xhtml
URL: http://svn.apache.org/viewvc/sis/ip-review/rev/29615/NumberConverter.xhtml?rev=1454417&view=auto
==============================================================================
--- sis/ip-review/rev/29615/NumberConverter.xhtml (added)
+++ sis/ip-review/rev/29615/NumberConverter.xhtml Fri Mar  8 15:11:18 2013
@@ -0,0 +1,740 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta charset="UTF-8"/>
+    <title>NumberConverter at revision 29615</title>
+    <style type="text/css" media="all">
+      @import url("../../reports.css");
+    </style>
+  </head>
+  <body>
+    <div>
+      <h1>NumberConverter at revision 29615</h1>
+
+<p>While the idea to provide a converter from numbers to other types was found in GeoTools,
+the code has been totally rewritten and share very few in common.
+For example the <code>String</code> inner class is declared as a derivative of
Justin's work
+by an <code>@author</code> javadoc tags. But the only code that share some similarity
with
+the original work is:</p>
+
+<blockquote><pre>public String convert(Number source) throws NonconvertibleObjectException
{
+    return (source != null) ? source.toString() : null;
+}</pre>
+</blockquote>
+
+<p>The original work was rather providing the above functionality inside relatively
large
+sequences of <code>if</code> … <code>else</code> statements,
which is a different approach
+than the Geotoolkit.org one (which separates all possible conversions into single methods).
+Even the "<code>(source != null) ? source.toString() : null</code>" part was
not written
+that way in the original code, and such simple statement is in about every Java softwares.</p>
+
+<blockquote><pre></pre>
+</blockquote>
+
+
+<p><b>Command line:</b></p>
+<blockquote><code>svn cat -r29615 http://svn.osgeo.org/geotools/trunk/modules/library/main/src/main/java/org/geotools/util/NumericConverterFactory.java</code></blockquote>
+<table class="changes">
+<tr><th>Revision 29147</th><th>Geotoolkit.org</th></tr>
+<tr><td><pre><span class="add">/*
+ *    GeoTools - OpenSource mapping toolkit
+ *    http://geotools.org
+ *    (C) 2002-2006, GeoTools Project Managment Committee (PMC)
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License as published by the Free Software Foundation;
+ *    version 2.1 of the License.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ */
+package org.geotools.util;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.text.NumberFormat;
+
+import org.geotools.factory.Hints;
+
+/**
+ * ConverterFactory which converts between the "standard" numeric types.
+ * &lt;p&gt;
+ * Supported types:
+ * &lt;ul&gt;
+ * &lt;li&gt;{@link java.lang.Long}
+ * &lt;li&gt;{@link java.lang.Integer}
+ * &lt;li&gt;{@link java.lang.Short}
+ * &lt;li&gt;{@link java.lang.Byte}
+ * &lt;li&gt;{@link java.lang.BigInteger}
+ * &lt;li&gt;{@link java.lang.Double}
+ * &lt;li&gt;{@link java.lang.Float}
+ * &lt;li&gt;{@link java.lang.BigDecimal}
+ * &lt;/ul&gt;
+ * &lt;/p&gt;
+ *
+ * @author Justin Deoliveira, The Open Planning Project
+ * @since 2.4
+ */
+public class NumericConverterFactory implements ConverterFactory {
+
+    public Converter createConverter(Class source, Class target, Hints hints) {
+
+        //check if source is a number or a string.  We can't convert to a number
+        // from anything else.
+        if ( !(Number.class.isAssignableFrom( source )) &amp;&amp;
+             !(String.class.isAssignableFrom( source )) )
+                return null;
+
+        //check if target is one of supported
+        if (
+            Long.class.equals( target ) ||
+            Integer.class.equals( target ) ||
+            Short.class.equals( target ) ||
+            Byte.class.equals( target ) ||
+            BigInteger.class.equals( target ) ||
+            BigDecimal.class.equals( target ) ||
+            Double.class.equals( target ) ||
+            Float.class.equals( target ) ||
+            Number.class.equals( target )
+        ) {
+            return new NumericConverter();
+        }
+
+        return null;
+    }
+
+    class NumericConverter implements Converter {
+
+        public Object convert(Object source, Class target) throws Exception {
+            if (source instanceof Number) {
+                Number s = (Number) source;
+
+                //integral
+                if ( Long.class.equals( target ) ) {
+                    return new Long( s.longValue() );
+                }
+                if ( Integer.class.equals( target ) ) {
+                    return new Integer( s.intValue() );
+                }
+                if ( Short.class.equals( target ) ) {
+                    return new Short( s.shortValue() );
+                }
+                if ( Byte.class.equals( target ) ) {
+                    return new Byte( s.byteValue() );
+                }
+                if ( BigInteger.class.equals( target ) ) {
+                    return BigInteger.valueOf( s.longValue() );
+                }
+
+                //floating point
+                // JD: we use the string reprensentation to avoid coordinate
+                // drift due to precision issues, there could be some
+                // performance issues with this.
+                if ( Double.class.equals( target ) ) {
+                    return new Double( s.toString() );
+                }
+                if ( Float.class.equals( target ) ) {
+                    return new Float( s.toString() );
+                }
+                if ( BigDecimal.class.equals( target ) ) {
+                    return new BigDecimal( s.toString() );
+                }
+
+                if (Number.class.equals( target )) {
+                    try {
+                        return new Integer(s.toString());
+                    } catch (Exception e) {
+                    }
+
+                    try {
+                        return new BigInteger(s.toString());
+                    } catch (Exception e) {
+                    }
+
+                    try {
+                        return new Double(s.toString());
+                    } catch (Exception e) {
+                    }
+
+                    try {
+                        return new BigDecimal(s.toString());
+                    } catch (Exception e) {
+                    }
+                }
+            } else if (source instanceof String) {
+                String s = (String) source;
+                //ensure we trim any space off the string
+                s = s.trim();
+
+            String integral = toIntegral(s);
+
+            //floating point
+            if ( Double.class.equals( target ) ) {
+                return new Double(s);
+            }
+            if ( Float.class.equals( target ) ) {
+                return new Float(s);
+            }
+            if ( BigDecimal.class.equals( target ) ) {
+                return new BigDecimal(s);
+            }
+
+
+
+            //textual
+            if ( Long.class.equals( target ) ) {
+                return new Long(integral);
+            }
+            if ( Integer.class.equals( target ) ) {
+                return new Integer(integral);
+            }
+            if ( Short.class.equals( target ) ) {
+                return new Short(integral);
+            }
+            if ( Byte.class.equals( target ) ) {
+                return new Byte(integral);
+            }
+            if ( BigInteger.class.equals( target ) ) {
+                return new BigInteger(integral);
+            }
+
+            // fallback.  If you ask for Number, you get our 'best guess'
+            if (Number.class.equals( target )) {
+                if( integral.equals(s)){
+                    // we think this is an integer of some sort
+                    try {
+                        return new Integer(integral);
+                    } catch (Exception e) {
+                    }
+
+                    try {
+                        return new BigInteger(integral);
+                    } catch (Exception e) {
+                    }
+                }
+                try {
+                    return new Double(s);
+                } catch (Exception e) {
+                }
+
+                try {
+                    return new BigDecimal(s);
+                } catch (Exception e) {
+                }
+            }
+                }
+                //nothing matched.  Return null.
+                return null;
+            }
+
+	}
+
+	/**
+	 * Extract the integral part out of a decimal format string.
+	 * @param s
+	 * @return integral component of decimal representation
+	 */
+	static String toIntegral( String s ) {
+	    //NumberFormat format = NumberFormat.getInstance();
+
+	    int radex = -1; // last non numeric character to account for "." vs "," seperators
+        for( int i=s.length()-1; i&gt;0; i--){
+            char ch = s.charAt(i);
+            if( !Character.isDigit(ch) &amp;&amp; '-' != ch){
+                radex = i;
+                break;
+            }
+        }
+        if( radex != -1 ){
+           // text is formatted in decimal but floating point format supplied
+            return s.substring(0, radex );
+        }
+        else {
+            return s;
+        }
+    }
+}</span></pre></td>
+<td><pre>/*
+ *    Geotoolkit.org - An Open Source Java GIS Toolkit
+ *    http://www.geotoolkit.org
+ *
+ *    (C) 2007-2012, Open Source Geospatial Foundation (OSGeo)
+ *    (C) 2009-2012, Geomatys
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License as published by the Free Software Foundation;
+ *    version 2.1 of the License.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ */
+package org.geotoolkit.util.converter;
+
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import net.jcip.annotations.Immutable;
+
+
+/**
+ * Handles conversions from {@link java.lang.Number} to various objects.
+ *
+ * @author Justin Deoliveira (TOPP)
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 3.02
+ *
+ * @since 2.4
+ * @module
+ */
+@Immutable
+abstract class NumberConverter&lt;T&gt; extends SimpleConverter&lt;Number,T&gt;
implements Serializable {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = -8715054480508622025L;
+
+    /**
+     * Returns the source class, which is always {@link Number}.
+     */
+    @Override
+    public final Class&lt;Number&gt; getSourceClass() {
+        return Number.class;
+    }
+
+    /**
+     * Returns {@code false} since subclasses do not preserve order.
+     */
+    @Override
+    public boolean isOrderPreserving() {
+        return false;
+    }
+
+
+    /**
+     * Converter from numbers to comparables. This special case exists because {@link Number}
+     * does not implement {@link java.lang.Comparable} directly, but all known subclasses
do.
+     *
+     * @author Martin Desruisseaux (Geomatys)
+     * @version 3.01
+     *
+     * @since 3.01
+     */
+    @Immutable
+    static final class Comparable extends NumberConverter&lt;java.lang.Comparable&lt;?&gt;&gt;
{
+        private static final long serialVersionUID = 3716134638218072176L;
+        public static final Comparable INSTANCE = new Comparable();
+        private Comparable() {
+        }
+
+        @Override
+        @SuppressWarnings({"rawtypes","unchecked"})
+        public Class&lt;java.lang.Comparable&lt;?&gt;&gt; getTargetClass()
{
+            return (Class) java.lang.Comparable.class;
+        }
+
+        @Override
+        public java.lang.Comparable&lt;?&gt; convert(final Number source) throws
NonconvertibleObjectException {
+            if (source == null || source instanceof java.lang.Comparable&lt;?&gt;)
{
+                return (java.lang.Comparable&lt;?&gt;) source;
+            }
+            return source.doubleValue();
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        protected Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+
+    /**
+     * Converter from numbers to strings.
+     *
+     * @author Justin Deoliveira (TOPP)
+     * @author Martin Desruisseaux (Geomatys)
+     * @version 3.00
+     *
+     * @since 2.4
+     */
+    @Immutable
+    static final class String extends NumberConverter&lt;java.lang.String&gt; {
+        private static final long serialVersionUID = 1460382215827540172L;
+        public static final String INSTANCE = new String();
+        private String() {
+        }
+
+        @Override
+        public Class&lt;java.lang.String&gt; getTargetClass() {
+            return java.lang.String.class;
+        }
+
+        @Override
+        public java.lang.String convert(final Number source) throws NonconvertibleObjectException
{
+            return (source != null) ? source.toString() : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        protected Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+
+    /**
+     * Converter from numbers to doubles.
+     *
+     * @author Martin Desruisseaux (Geomatys)
+     * @version 3.00
+     *
+     * @since 3.00
+     */
+    @Immutable
+    static final class Double extends NumberConverter&lt;java.lang.Double&gt; {
+        private static final long serialVersionUID = 1643009985070268985L;
+        public static final Double INSTANCE = new Double();
+        private Double() {
+        }
+
+        @Override
+        public Class&lt;java.lang.Double&gt; getTargetClass() {
+            return java.lang.Double.class;
+        }
+
+        @Override
+        public java.lang.Double convert(final Number source) throws NonconvertibleObjectException
{
+            return (source != null) ? java.lang.Double.valueOf(source.doubleValue()) : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        protected Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+
+    /**
+     * Converter from numbers to floats.
+     *
+     * @author Martin Desruisseaux (Geomatys)
+     * @version 3.00
+     *
+     * @since 3.00
+     */
+    @Immutable
+    static final class Float extends NumberConverter&lt;java.lang.Float&gt; {
+        private static final long serialVersionUID = -5900985555014433974L;
+        public static final Float INSTANCE = new Float();
+        private Float() {
+        }
+
+        @Override
+        public Class&lt;java.lang.Float&gt; getTargetClass() {
+            return java.lang.Float.class;
+        }
+
+        @Override
+        public java.lang.Float convert(final Number source) throws NonconvertibleObjectException
{
+            return (source != null) ? java.lang.Float.valueOf(source.floatValue()) : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        protected Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+
+    /**
+     * Converter from numbers to longs.
+     *
+     * @author Martin Desruisseaux (Geomatys)
+     * @version 3.00
+     *
+     * @since 3.00
+     */
+    @Immutable
+    static final class Long extends NumberConverter&lt;java.lang.Long&gt; {
+        private static final long serialVersionUID = -5320144566275003574L;
+        public static final Long INSTANCE = new Long();
+        private Long() {
+        }
+
+        @Override
+        public Class&lt;java.lang.Long&gt; getTargetClass() {
+            return java.lang.Long.class;
+        }
+
+        @Override
+        public java.lang.Long convert(final Number source) throws NonconvertibleObjectException
{
+            return (source != null) ? java.lang.Long.valueOf(source.longValue()) : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        protected Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+
+    /**
+     * Converter from numbers to integers.
+     *
+     * @author Martin Desruisseaux (Geomatys)
+     * @version 3.00
+     *
+     * @since 3.00
+     */
+    @Immutable
+    static final class Integer extends NumberConverter&lt;java.lang.Integer&gt; {
+        private static final long serialVersionUID = 2661178278691398269L;
+        public static final Integer INSTANCE = new Integer();
+        private Integer() {
+        }
+
+        @Override
+        public Class&lt;java.lang.Integer&gt; getTargetClass() {
+            return java.lang.Integer.class;
+        }
+
+        @Override
+        public java.lang.Integer convert(final Number source) throws NonconvertibleObjectException
{
+            return (source != null) ? java.lang.Integer.valueOf(source.intValue()) : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        protected Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+
+    /**
+     * Converter from numbers to shorts.
+     *
+     * @author Martin Desruisseaux (Geomatys)
+     * @version 3.00
+     *
+     * @since 3.00
+     */
+    @Immutable
+    static final class Short extends NumberConverter&lt;java.lang.Short&gt; {
+        private static final long serialVersionUID = -5943559376400249179L;
+        public static final Short INSTANCE = new Short();
+        private Short() {
+        }
+
+        @Override
+        public Class&lt;java.lang.Short&gt; getTargetClass() {
+            return java.lang.Short.class;
+        }
+
+        @Override
+        public java.lang.Short convert(final Number source) throws NonconvertibleObjectException
{
+            return (source != null) ? java.lang.Short.valueOf(source.shortValue()) : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        protected Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+
+    /**
+     * Converter from numbers to shorts.
+     *
+     * @author Martin Desruisseaux (Geomatys)
+     * @version 3.00
+     *
+     * @since 3.00
+     */
+    @Immutable
+    static final class Byte extends NumberConverter&lt;java.lang.Byte&gt; {
+        private static final long serialVersionUID = 1381038535870541045L;
+        public static final Byte INSTANCE = new Byte();
+        private Byte() {
+        }
+
+        @Override
+        public Class&lt;java.lang.Byte&gt; getTargetClass() {
+            return java.lang.Byte.class;
+        }
+
+        @Override
+        public java.lang.Byte convert(final Number source) throws NonconvertibleObjectException
{
+            return (source != null) ? java.lang.Byte.valueOf(source.byteValue()) : null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        protected Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+
+    /**
+     * Converter from numbers to booleans. Values in the range (-1..1) exclusive
+     * and NaN values are understood as "false", and all other values as "true".
+     *
+     * @author Justin Deoliveira (TOPP)
+     * @author Martin Desruisseaux (Geomatys)
+     * @version 3.00
+     *
+     * @since 2.4
+     */
+    @Immutable
+    static final class Boolean extends NumberConverter&lt;java.lang.Boolean&gt; {
+        private static final long serialVersionUID = -7522980351031833731L;
+        public static final Boolean INSTANCE = new Boolean();
+        private Boolean() {
+        }
+
+        @Override
+        public Class&lt;java.lang.Boolean&gt; getTargetClass() {
+            return java.lang.Boolean.class;
+        }
+
+        @Override
+        public java.lang.Boolean convert(final Number source) throws NonconvertibleObjectException
{
+            return (source != null) ? java.lang.Boolean.valueOf(source.intValue() != 0) :
null;
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        protected Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+
+    /**
+     * Converter from numbers to {@link java.math.BigDecimal}.
+     *
+     * @author Martin Desruisseaux (Geomatys)
+     * @version 3.02
+     *
+     * @since 3.02
+     */
+    @Immutable
+    static final class BigDecimal extends NumberConverter&lt;java.math.BigDecimal&gt;
{
+        private static final long serialVersionUID = -6318144992861058878L;
+        public static final BigDecimal INSTANCE = new BigDecimal();
+        private BigDecimal() {
+        }
+
+        @Override
+        public Class&lt;java.math.BigDecimal&gt; getTargetClass() {
+            return java.math.BigDecimal.class;
+        }
+
+        @Override
+        public java.math.BigDecimal convert(final Number source) throws NonconvertibleObjectException
{
+            if (source == null) {
+                return null;
+            }
+            if (source instanceof java.math.BigDecimal) {
+                return (java.math.BigDecimal) source;
+            }
+            if (source instanceof java.math.BigInteger) {
+                return new java.math.BigDecimal((java.math.BigInteger) source);
+            }
+            if (Numbers.isInteger(source.getClass())) {
+                return java.math.BigDecimal.valueOf(source.longValue());
+            }
+            return java.math.BigDecimal.valueOf(source.doubleValue());
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        protected Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+
+    /**
+     * Converter from numbers to {@link java.math.BigInteger}.
+     *
+     * @author Martin Desruisseaux (Geomatys)
+     * @version 3.02
+     *
+     * @since 3.02
+     */
+    @Immutable
+    static final class BigInteger extends NumberConverter&lt;java.math.BigInteger&gt;
{
+        private static final long serialVersionUID = 5940724099300523246L;
+        public static final BigInteger INSTANCE = new BigInteger();
+        private BigInteger() {
+        }
+
+        @Override
+        public Class&lt;java.math.BigInteger&gt; getTargetClass() {
+            return java.math.BigInteger.class;
+        }
+
+        @Override
+        public java.math.BigInteger convert(final Number source) throws NonconvertibleObjectException
{
+            if (source == null) {
+                return null;
+            }
+            if (source instanceof java.math.BigInteger) {
+                return (java.math.BigInteger) source;
+            }
+            if (source instanceof java.math.BigDecimal) {
+                return ((java.math.BigDecimal) source).toBigInteger();
+            }
+            return java.math.BigInteger.valueOf(source.longValue());
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        protected Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+
+    /**
+     * Converter from numbers to colors. Colors with an alpha of 0 (which would normally
+     * be fully transparent pixel) are interpreted as color without alpha component.
+     *
+     * @author Justin Deoliveira (TOPP)
+     * @author Martin Desruisseaux (Geomatys)
+     * @version 3.00
+     *
+     * @since 2.4
+     */
+    @Immutable
+    static final class Color extends NumberConverter&lt;java.awt.Color&gt; {
+        private static final long serialVersionUID = 8866612442279600953L;
+        public static final Color INSTANCE = new Color();
+        private Color() {
+        }
+
+        @Override
+        public Class&lt;java.awt.Color&gt; getTargetClass() {
+            return java.awt.Color.class;
+        }
+
+        @Override
+        public java.awt.Color convert(final Number source) throws NonconvertibleObjectException
{
+            if (source == null) {
+                return null;
+            }
+            final int rgba = source.intValue();
+            final int alpha = rgba &amp; 0xFF000000;
+            return new java.awt.Color(rgba, alpha != 0);
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        protected Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+}</pre></td></tr>
+</table>
+    </div>
+  </body>
+</html>

Propchange: sis/ip-review/rev/29615/NumberConverter.xhtml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/ip-review/rev/29615/NumberConverter.xhtml
------------------------------------------------------------------------------
    svn:mime-type = text/html



Mime
View raw message