sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1411572 - in /sis/branches/JDK7/sis-utility/src: main/java/org/apache/sis/internal/util/ main/java/org/apache/sis/util/collection/ test/java/org/apache/sis/util/collection/
Date Tue, 20 Nov 2012 07:58:46 GMT
Author: desruisseaux
Date: Tue Nov 20 07:58:45 2012
New Revision: 1411572

URL: http://svn.apache.org/viewvc?rev=1411572&view=rev
Log:
Moved ColumnConstants as a package-privated class close to the other TreeTable-related classes.

Added:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/ColumnConstant.java
      - copied, changed from r1411285, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/ColumnConstant.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTables.java
  (with props)
Removed:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/ColumnConstant.java
Modified:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTable.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/DefaultTreeTableTest.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/TreeTableFormatTest.java

Copied: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/ColumnConstant.java
(from r1411285, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/ColumnConstant.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/ColumnConstant.java?p2=sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/ColumnConstant.java&p1=sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/ColumnConstant.java&r1=1411285&r2=1411572&rev=1411572&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/ColumnConstant.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/ColumnConstant.java
Tue Nov 20 07:58:45 2012
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sis.internal.util;
+package org.apache.sis.util.collection;
 
 import java.util.Map;
 import java.util.Collections;
@@ -22,7 +22,6 @@ import java.io.Serializable;
 import java.io.InvalidObjectException;
 import org.opengis.util.InternationalString;
 import org.apache.sis.util.resources.Vocabulary;
-import org.apache.sis.util.collection.TableColumn;
 
 
 /**
@@ -35,7 +34,7 @@ import org.apache.sis.util.collection.Ta
  * @version 0.3
  * @module
  */
-public final class ColumnConstant<V> implements TableColumn<V>, Serializable
{
+final class ColumnConstant<V> implements TableColumn<V>, Serializable {
     /**
      * For cross-version compatibility.
      */
@@ -51,18 +50,10 @@ public final class ColumnConstant<V> imp
             CharSequence.class, Vocabulary.Keys.Name);
 
     /**
-     * Frequently-used constant for a column of object types.
-     * The values are instances of {@link Class}.
-     */
-    @SuppressWarnings("unchecked")
-    public static final TableColumn<Class<?>> TYPE = new ColumnConstant<>("TYPE",
-            (Class) Class.class, Vocabulary.Keys.Type);
-
-    /**
      * A map containing only the {@link #NAME} column.
      * This is the default set of columns when parsing a table tree.
      */
-    public static final Map<TableColumn<?>,Integer> NAME_MAP =
+    static final Map<TableColumn<?>,Integer> NAME_MAP =
             Collections.<TableColumn<?>,Integer>singletonMap(NAME, 0);
 
     /**
@@ -87,7 +78,7 @@ public final class ColumnConstant<V> imp
      * @param type Base type of all values in the column identified by this instance.
      * @param resourceKey The resource key for the column header.
      */
-    private ColumnConstant(final String name, final Class<V> type, final int resourceKey)
{
+    ColumnConstant(final String name, final Class<V> type, final int resourceKey) {
         this.name        = name;
         this.type        = type;
         this.resourceKey = resourceKey;

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java?rev=1411572&r1=1411571&r2=1411572&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java
Tue Nov 20 07:58:45 2012
@@ -217,6 +217,20 @@ public class DefaultTreeTable implements
         this.root = root;
     }
 
+    /**
+     * Returns a string representation of this tree table.
+     * The default implementation delegates to {@link TreeTables#toString(TreeTable)}.
+     * This is okay for debugging or occasional usages. However for more extensive usages,
+     * developers are encouraged to create and configure their own {@link TreeTableFormat}
+     * instance.
+     *
+     * @return A string representation of this tree table.
+     */
+    @Override
+    public String toString() {
+        return TreeTables.toString(this);
+    }
+
 
 
 

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTable.java?rev=1411572&r1=1411571&r2=1411572&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTable.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTable.java
Tue Nov 20 07:58:45 2012
@@ -23,7 +23,7 @@ import java.util.List;
  * The root of a tree of nodes, together with the definition of table columns.
  * The {@link #getColumns()} method gives the list of all columns that can be found
  * in a {@code TreeTable}. Usually some or all of those columns are also available as
- * {@link TableColumn} constants defined close to the method creating the tree tables.
+ * {@link TableColumn} constants defined in {@link TreeTables}.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java?rev=1411572&r1=1411571&r2=1411572&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
Tue Nov 20 07:58:45 2012
@@ -33,7 +33,6 @@ import org.apache.sis.util.Workaround;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
-import org.apache.sis.internal.util.ColumnConstant;
 import org.apache.sis.internal.util.LocalizedParseException;
 
 import static org.apache.sis.util.Characters.NO_BREAK_SPACE;

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTables.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTables.java?rev=1411572&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTables.java
(added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTables.java
Tue Nov 20 07:58:45 2012
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.util.collection;
+
+import java.text.Format;
+import org.apache.sis.util.Static;
+import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.resources.Vocabulary;
+
+
+/**
+ * Static methods working on {@link TreeTable} objects and their nodes.
+ * This class provides convenience factory methods for creating nodes with
+ * some frequently-used columns.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+public final class TreeTables extends Static {
+    /**
+     * Frequently-used constant for a column of object names.
+     * The values are typically instances of {@link String} or
+     * {@link org.opengis.util.InternationalString}, depending
+     * if the data provide localization support or not.
+     */
+    public static final TableColumn<CharSequence> NAME = ColumnConstant.NAME;
+
+    /**
+     * Frequently-used constant for a column of object types.
+     * The values are instances of {@link Class}.
+     */
+    @SuppressWarnings("unchecked")
+    public static final TableColumn<Class<?>> TYPE = new ColumnConstant<>("TYPE",
+            (Class) Class.class, Vocabulary.Keys.Type);
+
+    /**
+     * Shared {@code TreeTableFormat} instance for {@link #toString()} implementation.
+     */
+    private static Format format;
+
+    /**
+     * Do not allow instantiation of this class.
+     */
+    private TreeTables() {
+    }
+
+    /**
+     * Creates a node with a single column for object names.
+     * The node will have the following columns:
+     *
+     * <table>
+     *   <tr><th>Header</th> <th>Type</th>                
<th>Initial value</th></tr>
+     *   <tr><td>"Name"</td> <td>{@link CharSequence}</td>
<td>{@code name}</td></tr>
+     * </table>
+     *
+     * @param  name The initial value for the "Name" column (can be {@code null}).
+     * @return A new node with a name column initialized to the given value.
+     */
+    public static TreeTable.Node createNode(final CharSequence name) {
+        return new DefaultTreeTable.Node(ColumnConstant.NAME_MAP, (name != null) ? new CharSequence[]
{name} : null);
+    }
+
+    /**
+     * Returns a string representation of the given tree table.
+     * The default implementation uses a shared instance of {@link TreeTableFormat}.
+     * This is okay for debugging or occasional usages. However for more extensive usages,
+     * developers are encouraged to create and configure their own {@code TreeTableFormat}
+     * instance.
+     *
+     * @param  table The tree table to format.
+     * @return A string representation of the given tree table.
+     */
+    public static synchronized String toString(final TreeTable table) {
+        ArgumentChecks.ensureNonNull("table", table);
+        if (format == null) {
+            format = new TreeTableFormat(null, null);
+        }
+        return format.format(table);
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTables.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTables.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/DefaultTreeTableTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/DefaultTreeTableTest.java?rev=1411572&r1=1411571&r2=1411572&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/DefaultTreeTableTest.java
(original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/DefaultTreeTableTest.java
Tue Nov 20 07:58:45 2012
@@ -23,7 +23,7 @@ import org.apache.sis.test.TestStep;
 
 import static org.junit.Assert.*;
 import static org.apache.sis.test.TestUtilities.getSingleton;
-import static org.apache.sis.internal.util.ColumnConstant.*;
+import static org.apache.sis.util.collection.TreeTables.*;
 
 
 /**

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/TreeTableFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/TreeTableFormatTest.java?rev=1411572&r1=1411571&r2=1411572&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/TreeTableFormatTest.java
(original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/TreeTableFormatTest.java
Tue Nov 20 07:58:45 2012
@@ -22,7 +22,7 @@ import org.apache.sis.test.TestCase;
 import org.apache.sis.test.DependsOn;
 
 import static org.apache.sis.test.Assert.*;
-import static org.apache.sis.internal.util.ColumnConstant.*;
+import static org.apache.sis.util.collection.ColumnConstant.*;
 
 
 /**
@@ -33,7 +33,10 @@ import static org.apache.sis.internal.ut
  * @version 0.3
  * @module
  */
-@DependsOn(org.apache.sis.io.TableFormatterTest.class)
+@DependsOn({
+    DefaultTreeTableTest.class,
+    org.apache.sis.io.TableFormatterTest.class
+})
 public final strictfp class TreeTableFormatTest extends TestCase {
     /**
      * Creates a node with a single column for object names.



Mime
View raw message