Author: desruisseaux
Date: Sat Mar 9 23:17:05 2013
New Revision: 1454769
URL: http://svn.apache.org/r1454769
Log:
Ported the FallbackConverter.toString() method, which is helpful for debugging.
Added:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/Column.java
(with props)
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java
(with props)
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/ClassPair.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FallbackConverter.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TableColumn.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FallbackConverterTest.java
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/ClassPair.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/ClassPair.java?rev=1454769&r1=1454768&r2=1454769&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/ClassPair.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/ClassPair.java
[UTF-8] Sat Mar 9 23:17:05 2013
@@ -47,15 +47,6 @@ class ClassPair<S,T> {
protected final Class<T> targetClass;
/**
- * Creates an entry for the given converter.
- *
- * @param converter The converter.
- */
- ClassPair(final ObjectConverter<S,T> converter) {
- this(converter.getSourceClass(), converter.getTargetClass());
- }
-
- /**
* Creates an entry for the given source and target classes.
*
* @param sourceClass The {@linkplain ObjectConverter#getSourceClass()
source class}.
Added:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/Column.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/Column.java?rev=1454769&view=auto
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/Column.java
(added)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/Column.java
[UTF-8] Sat Mar 9 23:17:05 2013
@@ -0,0 +1,95 @@
+/*
+ * 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.internal.converter;
+
+import java.io.Serializable;
+import java.io.InvalidObjectException;
+import org.opengis.util.InternationalString;
+import org.apache.sis.util.Debug;
+import org.apache.sis.util.resources.Vocabulary;
+import org.apache.sis.util.collection.TreeTable;
+import org.apache.sis.util.collection.TableColumn;
+import org.apache.sis.util.collection.TreeTableFormat;
+
+
+/**
+ * Columns in the string representation of converter chains.
+ * This is used mostly for debugging purpose.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3
+ * @version 0.3
+ * @module
+ */
+final class Column extends TableColumn<Class<?>> implements Serializable {
+ /**
+ * For cross-version compatibility.
+ */
+ private static final long serialVersionUID = -828524683891584679L;
+
+ /**
+ * The column for the source type.
+ */
+ static final Column SOURCE = new Column(false);
+
+ /**
+ * The column for the target type.
+ */
+ static final Column TARGET = new Column(true);
+
+ /**
+ * {@code false} for the source, or {@code true} for the target.
+ */
+ private final boolean target;
+
+ /**
+ * Creates a new column.
+ */
+ @SuppressWarnings("unchecked")
+ private Column(final boolean target) {
+ super((Class) Class.class, target ? "target" : "source");
+ this.target = target;
+ }
+
+ /**
+ * Returns the header label.
+ */
+ @Override
+ public InternationalString getHeader() {
+ return Vocabulary.formatInternational(target ?
Vocabulary.Keys.Destination : Vocabulary.Keys.Source);
+ }
+
+ /**
+ * Resources to the singleton instance on deserialization.
+ */
+ private Object readResolve() throws InvalidObjectException {
+ return target ? TARGET : SOURCE;
+ }
+
+ /**
+ * Formats the given tree table. This method is used for the
implementation of
+ * {@link FallbackConverter#toString()} and {@link
ConverterRegistry#toString()}
+ * methods. Since they are mostly for debugging purpose, we do not bother
to cache
+ * the {@link TreeTableFormat} instance.
+ */
+ @Debug
+ static String format(final TreeTable table) {
+ final TreeTableFormat format = new TreeTableFormat(null, null);
+ format.setColumnSeparatorPattern("[ ] ⇨ ");
+ return format.format(table);
+ }
+}
Propchange:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/Column.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/Column.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FallbackConverter.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FallbackConverter.java?rev=1454769&r1=1454768&r2=1454769&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FallbackConverter.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FallbackConverter.java
[UTF-8] Sat Mar 9 23:17:05 2013
@@ -24,7 +24,10 @@ import org.apache.sis.util.Classes;
import org.apache.sis.util.ObjectConverter;
import org.apache.sis.math.FunctionProperty;
import org.apache.sis.util.UnconvertibleObjectException;
+import org.apache.sis.util.collection.DefaultTreeTable;
+import org.apache.sis.util.collection.TreeTable;
import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.Debug;
/**
@@ -404,4 +407,66 @@ final class FallbackConverter<S,T> exten
public ObjectConverter<T, S> inverse() throws
UnsupportedOperationException {
throw new
UnsupportedOperationException(Errors.format(Errors.Keys.NonInvertibleConversion));
}
+
+ /**
+ * Creates a node for the given converter and adds it to the given tree.
+ * This method invokes itself recursively for scanning through fallbacks.
+ *
+ * <p>This method creates a simplified tree, in that the cascading of
fallbacks converter
+ * of same {@link #targetClass} are hidden: only their leaves are created.
The purpose is
+ * to help the developer to focus more on the important elements (the leaf
converters)
+ * and be less distracted by the amount of {@code FallbackConverter}s
traversed in order
+ * to reach those leaves.</p>
+ *
+ * @param converter The converter for which to create a tree.
+ * @param addTo The node in which to add the converter.
+ */
+ private void toTree(final ObjectConverter<?,?> converter, final
TreeTable.Node addTo) {
+ FallbackConverter<?,?> more = null;
+ if (converter instanceof FallbackConverter<?,?>) {
+ more = (FallbackConverter<?,?>) converter;
+ if (more.targetClass == targetClass) { // Simplification case
(omit the node).
+ more.toTree(addTo);
+ return;
+ }
+ }
+ final TreeTable.Node node = addTo.newChild();
+ node.setValue(Column.SOURCE, converter.getSourceClass());
+ node.setValue(Column.TARGET, converter.getTargetClass());
+ if (more != null) {
+ more.toTree(node);
+ }
+ }
+
+ /**
+ * Adds a simplified tree representation of this {@code FallbackConverter}
+ * to the given node.
+ *
+ * @param addTo The node in which to add the converter.
+ */
+ final void toTree(final TreeTable.Node addTo) {
+ final ObjectConverter<S,? extends T> primary, fallback;
+ synchronized (this) {
+ primary = this.primary;
+ fallback = this.fallback;
+ }
+ toTree(primary, addTo);
+ toTree(fallback, addTo);
+ }
+
+ /**
+ * Returns a tree representation of this converter.
+ * The tree leaves represent the backing converters.
+ */
+ @Debug
+ @Override
+ public String toString() {
+ final DefaultTreeTable table = new DefaultTreeTable(Column.SOURCE,
Column.TARGET);
+ final DefaultTreeTable.Node root = new DefaultTreeTable.Node(table);
+ root.setValue(Column.SOURCE, sourceClass);
+ root.setValue(Column.TARGET, targetClass);
+ table.setRoot(root);
+ toTree(root);
+ return Column.format(table);
+ }
}
Added:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java?rev=1454769&view=auto
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java
(added)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java
[UTF-8] Sat Mar 9 23:17:05 2013
@@ -0,0 +1,76 @@
+/*
+ * 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.io;
+
+import java.text.Format;
+import java.text.FieldPosition;
+import java.text.ParsePosition;
+import java.io.InvalidObjectException;
+import net.jcip.annotations.ThreadSafe;
+import org.apache.sis.util.Classes;
+
+
+/**
+ * Used by {@link CompoundFormat} for formatting the names of object of type
{@link Class}.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3
+ * @version 0.3
+ * @module
+ */
+@ThreadSafe
+final class ClassFormat extends Format {
+ /**
+ * For cross-version compatibility.
+ */
+ private static final long serialVersionUID = 2321788892790539107L;
+
+ /**
+ * The unique instance.
+ */
+ static final ClassFormat INSTANCE = new ClassFormat();
+
+ /**
+ * For the unique {@link #INSTANCE} only.
+ */
+ private ClassFormat() {
+ }
+
+ /**
+ * Formats the given class. The given {@code obj} must be an instance of
{@link Class},
+ * otherwise a {@link ClassCastException} will be thrown.
+ */
+ @Override
+ public StringBuffer format(final Object obj, final StringBuffer
toAppendTo, final FieldPosition pos) {
+ return toAppendTo.append(Classes.getShortName((Class<?>) obj));
+ }
+
+ /**
+ * Can not parse unqualified class name.
+ */
+ @Override
+ public Object parseObject(final String source, final ParsePosition pos) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Resolves to the singleton instance on deserialization.
+ */
+ private Object readResolve() throws InvalidObjectException {
+ return INSTANCE;
+ }
+}
Propchange:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java?rev=1454769&r1=1454768&r2=1454769&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
[UTF-8] Sat Mar 9 23:17:05 2013
@@ -387,6 +387,8 @@ public abstract class CompoundFormat<T>
return format;
} else if (valueType == Angle.class) {
return AngleFormat.getInstance(locale);
+ } else if (valueType == Class.class) {
+ return ClassFormat.INSTANCE;
}
return null;
}
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java?rev=1454769&r1=1454768&r2=1454769&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
[UTF-8] Sat Mar 9 23:17:05 2013
@@ -20,6 +20,7 @@ import java.text.Format;
import java.text.FieldPosition;
import java.text.ParsePosition;
import java.text.ParseException;
+import java.io.InvalidObjectException;
import net.jcip.annotations.ThreadSafe;
import org.apache.sis.util.Numbers;
import org.apache.sis.util.CharSequences;
@@ -131,4 +132,12 @@ final class DefaultFormat extends Format
return null;
}
}
+
+ /**
+ * Resolves to the singleton instance on deserialization.
+ */
+ private Object readResolve() throws InvalidObjectException {
+ final Format format = getInstance(type);
+ return (format != null) ? format : this;
+ }
}
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TableColumn.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TableColumn.java?rev=1454769&r1=1454768&r2=1454769&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TableColumn.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/TableColumn.java
[UTF-8] Sat Mar 9 23:17:05 2013
@@ -121,7 +121,6 @@ public class TableColumn<V> implements C
* the column elements are typically instances of {@link String} or {@link
InternationalString},
* depending on whether the data provide localization support or not.
*/
- @SuppressWarnings("unchecked")
public static final TableColumn<CharSequence> VALUE_AS_TEXT = new
Constant<>("VALUE_AS_TEXT",
CharSequence.class, Vocabulary.Keys.Value);
@@ -129,13 +128,12 @@ public class TableColumn<V> implements C
* Frequently-used constant for a column of object numerical values.
* The column {@linkplain #getHeader() header} is "<cite>Value</cite>"
(eventually localized).
*/
- @SuppressWarnings("unchecked")
public static final TableColumn<Number> VALUE_AS_NUMBER = new
Constant<>("VALUE_AS_NUMBER",
Number.class, Vocabulary.Keys.Value);
/**
* A map containing only the {@link #NAME} column.
- * This is the default set of columns when parsing a table tree.
+ * This is the default set of columns when parsing a tree table.
*/
static final Map<TableColumn<?>,Integer> NAME_MAP =
Collections.<TableColumn<?>,Integer>singletonMap(NAME, 0);
@@ -249,7 +247,6 @@ public class TableColumn<V> implements C
public TableColumn(final Class<V> type, final CharSequence header) {
ArgumentChecks.ensureNonNull("type", this.type = type);
ArgumentChecks.ensureNonNull("header", this.header = header);
- this.header = Types.toInternationalString(header);
}
/**
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java?rev=1454769&r1=1454768&r2=1454769&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
[UTF-8] Sat Mar 9 23:17:05 2013
@@ -105,6 +105,11 @@ public final class Vocabulary extends In
public static final int DaylightTime = 24;
/**
+ * Destination
+ */
+ public static final int Destination = 38;
+
+ /**
* Directory
*/
public static final int Directory = 36;
@@ -205,6 +210,11 @@ public final class Vocabulary extends In
public static final int Scale = 23;
/**
+ * Source
+ */
+ public static final int Source = 39;
+
+ /**
* Standard deviation
*/
public static final int StandardDeviation = 8;
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties?rev=1454769&r1=1454768&r2=1454769&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
[ISO-8859-1] (original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
[ISO-8859-1] Sat Mar 9 23:17:05 2013
@@ -24,6 +24,7 @@ Code_1 = {0} code
CurrentDateTime = Current date and time
CurrentDirectory = Current directory
DaylightTime = Daylight time
+Destination = Destination
Directory = Directory
JavaExtensions = Java extensions
JavaHome = Java home directory
@@ -44,6 +45,7 @@ Paths = Paths
Root = Root
RootMeanSquare = Root Mean Square
Scale = Scale
+Source = Source
StandardDeviation = Standard deviation
TemporaryFiles = Temporary files
Timezone = Timezone
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties?rev=1454769&r1=1454768&r2=1454769&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
[ISO-8859-1] (original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
[ISO-8859-1] Sat Mar 9 23:17:05 2013
@@ -24,6 +24,7 @@ Code_1 = Code {0}
CurrentDateTime = Date et heure courantes
CurrentDirectory = R\u00e9pertoire courant
DaylightTime = Heure normale
+Destination = Destination
Directory = R\u00e9pertoire
JavaExtensions = Extensions du Java
JavaHome = R\u00e9pertoire du Java
@@ -44,6 +45,7 @@ Paths = Chemins
Root = Racine
RootMeanSquare = Moyenne quadratique
Scale = \u00c9chelle
+Source = Source
StandardDeviation = \u00c9cart type
TemporaryFiles = Fichiers temporaires
Timezone = Fuseau horaire
Modified:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FallbackConverterTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FallbackConverterTest.java?rev=1454769&r1=1454768&r2=1454769&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FallbackConverterTest.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FallbackConverterTest.java
[UTF-8] Sat Mar 9 23:17:05 2013
@@ -130,17 +130,16 @@ public final strictfp class FallbackConv
* above tests performs the same check in a more programmatic way.
However this
* is a convenient visual check and a useful debugging tool.
*/
- if (false) // TODO: FallbackConverter.toString() not yet implemented.
assertMultilinesEquals(
- "String ⇨ Object\n" +
- " ├─String ⇨ Number\n" +
+ "String ⇨ Object\n" +
+ " ├─String ⇨ Number\n" +
" │ ├─String ⇨ Number\n" +
" │ ├─String ⇨ Short\n" +
" │ ├─String ⇨ Long\n" +
" │ ├─String ⇨ Float\n" +
" │ ├─String ⇨ Integer\n" +
" │ └─String ⇨ Double\n" +
- " └─String ⇨ Boolean\n", c.toString());
+ " └─String ⇨ Boolean\n", c.toString());
}
/**