sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1454395 - in /sis/ip-review: CollectionConverter.xhtml rev/27557/ rev/27557/CollectionConverter.xhtml rev/27557/HEADER.html
Date Fri, 08 Mar 2013 14:13:25 GMT
Author: desruisseaux
Date: Fri Mar  8 14:13:25 2013
New Revision: 1454395

URL: http://svn.apache.org/r1454395
Log:
Added IP review for CollectionConverter.

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

Added: sis/ip-review/CollectionConverter.xhtml
URL: http://svn.apache.org/viewvc/sis/ip-review/CollectionConverter.xhtml?rev=1454395&view=auto
==============================================================================
--- sis/ip-review/CollectionConverter.xhtml (added)
+++ sis/ip-review/CollectionConverter.xhtml Fri Mar  8 14:13:25 2013
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta charset="UTF-8"/>
+    <title>CollectionConverter history</title>
+    <style type="text/css" media="all">
+      @import url("./reports.css");
+    </style>
+  </head>
+  <body>
+    <div>
+      <h1>CollectionConverter 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:27557 http://svn.osgeo.org/geotools/trunk/modules/library/main/src/main/java/org/geotools/util/CollectionConverterFactory.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">30511</td><td>2008-06-04</td><td>acuster</td><td>Header
cleanup 0 -- prep for Cedric's script --- modules/library: resolve conflicts; add missing</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">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">27572</td><td>2007-10-22</td><td>desruisseaux</td><td>Applied
svn properties prior to GEOT-1516.</td></tr>
+<tr><td class="rev">27557</td><td>2007-10-19</td><td class="unav">jdeolive</td><td><a
href="rev/27557/CollectionConverter.xhtml">added converter for converting between various
collection and array types</a></td></tr>
+</table>
+    </div>
+  </body>
+</html>

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

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

Added: sis/ip-review/rev/27557/CollectionConverter.xhtml
URL: http://svn.apache.org/viewvc/sis/ip-review/rev/27557/CollectionConverter.xhtml?rev=1454395&view=auto
==============================================================================
--- sis/ip-review/rev/27557/CollectionConverter.xhtml (added)
+++ sis/ip-review/rev/27557/CollectionConverter.xhtml Fri Mar  8 14:13:25 2013
@@ -0,0 +1,332 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta charset="UTF-8"/>
+    <title>CollectionConverter changes at revision 27557</title>
+    <style type="text/css" media="all">
+      @import url("../../reports.css");
+    </style>
+  </head>
+  <body>
+    <div>
+      <h1>CollectionConverter changes at revision 27557</h1>
+
+<p>While the idea to provide a converter from collection to other collection types
was found in GeoTools,
+the code has been totally rewritten and share nothing in common.
+The table below compares the GeoTools code with the Geotoolkit.org one.</p>
+
+<p><b>Command line:</b></p>
+<blockquote><code>svn cat -r27557 http://svn.osgeo.org/geotools/trunk/modules/library/main/src/main/java/org/geotools/util/CollectionConverterFactory.java</code></blockquote>
+<table class="changes">
+<tr><th>Revision 27557</th><th>Geotoolkit.org</th></tr>
+<tr><td><pre><span class="add">package org.geotools.util;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.geotools.factory.Hints;
+
+/**
+ * Converts among arrays and different collection classes.
+ * &lt;p&gt;
+ * THe following conversions are supported:
+ * &lt;ul&gt;
+ *   &lt;li&gt;Collection to Collection where collections are different types ( ex
list to set )
+ *   &lt;li&gt;Collection to Array
+ *   &lt;li&gt;Array to Collection
+ *   &lt;li&gt;Array to Array where the declared type of the target array is assignable
from
+ *   the declared type of the source array
+ * &lt;/ul&gt;
+ * &lt;/p&gt;
+ *
+ * @author Justin Deoliveira, The Open Planning Project
+ *
+ */
+public class CollectionConverterFactory implements ConverterFactory {
+
+    /**
+     * Converter for collection to collection
+     */
+    protected static final Converter CollectionToCollection = new Converter() {
+
+        public Object convert(Object source, Class target) throws Exception {
+            //if source is already an instance nevermind
+            if ( target.isInstance( source ) ) {
+                return source;
+            }
+
+            //dynamically create and add
+            Collection converted = newCollection( target );
+            if ( converted != null ) {
+                converted.addAll( (Collection) source );
+            }
+
+            return converted;
+        }
+
+    };
+
+    /**
+     * Converter for collection to array.
+     */
+    protected static final Converter CollectionToArray = new Converter() {
+
+        public Object convert(Object source, Class target) throws Exception {
+            Collection s = (Collection) source;
+            Object array = Array.newInstance(target.getComponentType(), s.size());
+
+            try {
+                int x = 0;
+                for ( Iterator i = s.iterator(); i.hasNext(); x++ ) {
+                    Array.set( array, x, i.next() );
+                }
+
+                return array;
+            }
+            catch( Exception e ) {
+                //Means an incompatable type assignment
+
+            }
+
+            return null;
+        }
+
+    };
+
+    /**
+     * Converter for array to collection.
+     */
+    protected static final Converter ArrayToCollection = new Converter() {
+
+        public Object convert(Object source, Class target) throws Exception {
+            Collection collection = newCollection(target);
+            if ( collection != null ) {
+                int length = Array.getLength(source);
+                for ( int i = 0; i &lt; length; i++ ) {
+                    collection.add( Array.get( source, i) );
+                }
+            }
+
+            return collection;
+        }
+
+    };
+
+    /**
+     * Converter for array to array.
+     */
+    protected static final Converter ArrayToArray = new Converter() {
+
+        public Object convert(Object source, Class target) throws Exception {
+          //get the individual component types
+            Class s = source.getClass().getComponentType();
+            Class t = target.getComponentType();
+
+            //make sure the source can be assiigned to the target
+            if ( t.isAssignableFrom(s) ) {
+                int length = Array.getLength(source);
+                Object converted = Array.newInstance( t, length );
+
+                for ( int i = 0; i &lt; length; i++ ) {
+                    Array.set(converted, i, Array.get( source, i ) );
+                }
+
+                return converted;
+            }
+
+            return null;
+        }
+    };
+
+    protected static Collection newCollection( Class target ) throws Exception {
+        if ( target.isInterface() ) {
+            //try the common ones
+            if ( List.class.isAssignableFrom( target ) ) {
+                return new ArrayList();
+            }
+            if ( SortedSet.class.isAssignableFrom( target ) ) {
+                return new TreeSet();
+            }
+            else if ( Set.class.isAssignableFrom( target ) ) {
+                return new HashSet();
+            }
+
+            //could not figure out
+            return null;
+        }
+        else {
+            //instantiate directly
+            return (Collection) target.newInstance();
+        }
+    }
+    public Converter createConverter(Class source, Class target, Hints hints) {
+        if ( ( Collection.class.isAssignableFrom( source ) || source.isArray() )
+            &amp;&amp; ( Collection.class.isAssignableFrom( target ) || target.isArray()
) ) {
+
+            //both collections?
+            if ( Collection.class.isAssignableFrom( source ) &amp;&amp;
+                    Collection.class.isAssignableFrom( target ) ) {
+               return CollectionToCollection;
+            }
+
+            //both arrays?
+            if ( source.getClass().isArray() &amp;&amp; target.isArray() ) {
+                return ArrayToArray;
+            }
+
+            //collection to array?
+            if ( Collection.class.isAssignableFrom( source ) &amp;&amp; target.isArray()
) {
+               return CollectionToArray;
+            }
+
+            //array to collection?
+            if ( source.getClass().isArray() &amp;&amp; Collection.class.isAssignableFrom(
target ) ) {
+                return ArrayToCollection;
+            }
+        }
+
+        return null;
+    }
+}</span></pre></td>
+
+<td><pre>/*
+ *    Geotoolkit.org - An Open Source Java GIS Toolkit
+ *    http://www.geotoolkit.org
+ *
+ *    (C) 2009-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.util.Collection;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import net.jcip.annotations.Immutable;
+
+
+/**
+ * Handles conversions from {@link java.util.Collection} to various objects.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 3.02
+ *
+ * @since 3.02
+ * @module
+ */
+@Immutable
+abstract class CollectionConverter&lt;T&gt; extends SimpleConverter&lt;Collection&lt;?&gt;,T&gt;
implements Serializable {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = -4515250904953131514L;
+
+    /**
+     * Returns the source class, which is always {@link String}.
+     */
+    @Override
+    @SuppressWarnings({"unchecked","rawtypes"})
+    public final Class&lt;Collection&lt;?&gt;&gt; getSourceClass() {
+        return (Class) Collection.class;
+    }
+
+
+    /**
+     * Converter from {@link java.util.Collection} to {@link java.util.List}.
+     *
+     * @author Martin Desruisseaux (Geomatys)
+     * @version 3.02
+     *
+     * @since 3.02
+     */
+    @Immutable
+    static final class List extends CollectionConverter&lt;java.util.List&lt;?&gt;&gt;
{
+        private static final long serialVersionUID = 5492247760609833586L;
+        public static final List INSTANCE = new List();
+        private List() {
+        }
+
+        @Override
+        @SuppressWarnings({"unchecked","rawtypes"})
+        public Class&lt;java.util.List&lt;?&gt;&gt; getTargetClass() {
+            return (Class) java.util.List.class;
+        }
+
+        @Override
+        public java.util.List&lt;?&gt; convert(final Collection&lt;?&gt;
source) {
+            if (source == null) {
+                return null;
+            }
+            if (source instanceof java.util.List&lt;?&gt;) {
+                return (java.util.List&lt;?&gt;) source;
+            }
+            return new ArrayList&lt;&gt;(source);
+        }
+
+        /** Returns the singleton instance on deserialization. */
+        protected Object readResolve() throws ObjectStreamException {
+            return INSTANCE;
+        }
+    }
+
+
+    /**
+     * Converter from {@link java.util.Collection} to {@link java.util.Set}.
+     *
+     * @author Martin Desruisseaux (Geomatys)
+     * @version 3.02
+     *
+     * @since 3.02
+     */
+    @Immutable
+    static final class Set extends CollectionConverter&lt;java.util.Set&lt;?&gt;&gt;
{
+        private static final long serialVersionUID = -4200659837453206164L;
+        public static final Set INSTANCE = new Set();
+        private Set() {
+        }
+
+        @Override
+        @SuppressWarnings({"unchecked","rawtypes"})
+        public Class&lt;java.util.Set&lt;?&gt;&gt; getTargetClass() {
+            return (Class) java.util.Set.class;
+        }
+
+        @Override
+        public java.util.Set&lt;?&gt; convert(final Collection&lt;?&gt; source)
{
+            if (source == null) {
+                return null;
+            }
+            if (source instanceof java.util.Set&lt;?&gt;) {
+                return (java.util.Set&lt;?&gt;) source;
+            }
+            return new LinkedHashSet&lt;&gt;(source);
+        }
+
+        /** 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/27557/CollectionConverter.xhtml
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: sis/ip-review/rev/27557/HEADER.html
URL: http://svn.apache.org/viewvc/sis/ip-review/rev/27557/HEADER.html?rev=1454395&view=auto
==============================================================================
--- sis/ip-review/rev/27557/HEADER.html (added)
+++ sis/ip-review/rev/27557/HEADER.html Fri Mar  8 14:13:25 2013
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta charset="UTF-8"/>
+    <title>Revision 27557</title>
+  </head>
+  <body>
+    <div>
+      <h1>Revision 27557</h1>
+<table>
+  <tr><td><b>Author:</b></td><td>jdeolive</td></tr>
+  <tr><td><b>Date:</b></td><td>2007-10-19</td></tr>
+  <tr><td><b>Message:</b></td><td>added converter for
converting between various collection and array types</td></tr>
+</table>
+    </div>
+  </body>
+</html>

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

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



Mime
View raw message