You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2016/11/01 21:03:08 UTC
svn commit: r1767577 [14/15] - in /sis/trunk: ./ application/
application/sis-console/src/main/java/org/apache/sis/console/
application/sis-openoffice/
application/sis-openoffice/src/main/java/org/apache/sis/openoffice/ core/
core/sis-feature/src/main/...
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -16,6 +16,7 @@
*/
package org.apache.sis.util;
+import java.text.Normalizer;
import org.apache.sis.util.resources.Errors;
import static java.lang.Character.*;
@@ -34,7 +35,7 @@ import static java.lang.Character.*;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.3
+ * @version 0.8
* @module
*
* @see CharSequences
@@ -42,6 +43,9 @@ import static java.lang.Character.*;
public final class StringBuilders extends Static {
/**
* Letters in the range 00C0 (192) to 00FF (255) inclusive with their accent removed, when possible.
+ * This string partially duplicates the work done by {@link Normalizer} with additional replacements.
+ * We use it for more direct character replacements (compared to using {@code Normalizer} than removing
+ * combining marks) for those common and easy cases.
*/
private static final String ASCII = "AAAAAA�CEEEEIIIIDNOOOOO*OUUUUY�saaaaaa�ceeeeiiiionooooo/ouuuuy�y";
// Original letters (with accent) = "����������������������������������������������������������������";
@@ -55,10 +59,10 @@ public final class StringBuilders extend
/**
* Replaces every occurrences of the given character in the given buffer.
*
- * @param buffer The string in which to perform the replacements.
- * @param toSearch The character to replace.
- * @param replaceBy The replacement for the searched character.
- * @throws NullArgumentException If the {@code buffer} arguments is null.
+ * @param buffer the string in which to perform the replacements.
+ * @param toSearch the character to replace.
+ * @param replaceBy the replacement for the searched character.
+ * @throws NullArgumentException if the {@code buffer} arguments is null.
*
* @see String#replace(char, char)
*/
@@ -78,11 +82,11 @@ public final class StringBuilders extend
* This method invokes {@link StringBuilder#replace(int, int, String)}
* for each occurrence of {@code search} found in the buffer.
*
- * @param buffer The string in which to perform the replacements.
- * @param toSearch The string to replace.
- * @param replaceBy The replacement for the searched string.
- * @throws NullArgumentException If any of the arguments is null.
- * @throws IllegalArgumentException If the {@code toSearch} argument is empty.
+ * @param buffer the string in which to perform the replacements.
+ * @param toSearch the string to replace.
+ * @param replaceBy the replacement for the searched string.
+ * @throws NullArgumentException if any of the arguments is null.
+ * @throws IllegalArgumentException if the {@code toSearch} argument is empty.
*
* @see String#replace(char, char)
* @see CharSequences#replace(CharSequence, CharSequence, CharSequence)
@@ -107,10 +111,10 @@ public final class StringBuilders extend
* The substring to be replaced begins at the specified {@code start} and extends to the
* character at index {@code end - 1}.
*
- * @param buffer The buffer in which to perform the replacement.
- * @param start The beginning index in the {@code buffer}, inclusive.
- * @param end The ending index in the {@code buffer}, exclusive.
- * @param chars The array that will replace previous contents.
+ * @param buffer the buffer in which to perform the replacement.
+ * @param start the beginning index in the {@code buffer}, inclusive.
+ * @param end the ending index in the {@code buffer}, exclusive.
+ * @param chars the array that will replace previous contents.
* @throws NullArgumentException if the {@code buffer} or {@code chars} argument is null.
*
* @see StringBuilder#replace(int, int, String)
@@ -140,10 +144,10 @@ public final class StringBuilders extend
* {@link StringBuilder#delete(int, int)} for each occurrence of {@code search} found in
* the buffer.
*
- * @param buffer The string in which to perform the removals.
- * @param toSearch The string to remove.
- * @throws NullPointerException If any of the arguments is null.
- * @throws IllegalArgumentException If the {@code toSearch} argument is empty.
+ * @param buffer the string in which to perform the removals.
+ * @param toSearch the string to remove.
+ * @throws NullPointerException if any of the arguments is null.
+ * @throws IllegalArgumentException if the {@code toSearch} argument is empty.
*
* @see StringBuilder#delete(int, int)
*/
@@ -170,8 +174,8 @@ public final class StringBuilders extend
* This method is useful after a {@linkplain StringBuilder#append(double) double value has
* been appended to the buffer}, in order to make it appears like an integer when possible.
*
- * @param buffer The buffer to trim if possible.
- * @throws NullArgumentException If the given {@code buffer} is null.
+ * @param buffer the buffer to trim if possible.
+ * @throws NullArgumentException if the given {@code buffer} is null.
*
* @see CharSequences#trimFractionalPart(CharSequence)
*/
@@ -191,15 +195,16 @@ public final class StringBuilders extend
/**
* Replaces some Unicode characters by ASCII characters on a "best effort basis".
- * For example the {@code '�'} character is replaced by {@code 'e'} (without accent).
+ * For example the \u201c\u2008�\u2008\u201d character is replaced by \u201c\u2008e\u2008\u201d (without accent),
+ * the \u201c\u2008\u2033\u2008\u201d symbol for minutes of angle is replaced by straight double quotes \u201c\u2008"\u2008\u201d,
+ * and combined characters like \u338f, \u338e, \u339d, \u339e, \u33a2, \u33a6, \u3396, \u33a7, \u33a9, \u3390, <i>etc.</i> are replaced
+ * by the corresponding sequences of characters.
*
- * <p>The current implementation replaces the characters in the range {@code 00C0}
- * to {@code 00FF} (inclusive) and some space and punctuation characters.</p>
- *
- * @param buffer The text to scan for Unicode characters to replace by ASCII characters.
- * @throws NullArgumentException If the given {@code buffer} is null.
+ * @param buffer the text to scan for Unicode characters to replace by ASCII characters.
+ * @throws NullArgumentException if the given {@code buffer} is null.
*
* @see CharSequences#toASCII(CharSequence)
+ * @see Normalizer#normalize(CharSequence, Normalizer.Form)
*/
public static void toASCII(final StringBuilder buffer) {
ArgumentChecks.ensureNonNull("buffer", buffer);
@@ -211,6 +216,7 @@ public final class StringBuilders extend
*/
static CharSequence toASCII(CharSequence text, StringBuilder buffer) {
if (text != null) {
+ boolean doneNFKD = false;
/*
* Scan the buffer in reverse order because we may suppress some characters.
*/
@@ -219,41 +225,68 @@ public final class StringBuilders extend
final int c = codePointBefore(text, i);
final int n = charCount(c);
final int r = c - 0xC0;
- i -= n; // After this line, 'i' is the index of character 'c'.
+ i -= n; // After this line, 'i' is the index of character 'c'.
if (r >= 0) {
- final char cr; // The character replacement.
+ final char cr; // The character replacement.
if (r < ASCII.length()) {
cr = ASCII.charAt(r);
} else {
switch (getType(c)) {
case FORMAT:
- case CONTROL: buffer.delete(i, i + n); continue; // Character.isIdentifierIgnorable
+ case CONTROL: // Character.isIdentifierIgnorable
+ case NON_SPACING_MARK: cr = 0; break;
case PARAGRAPH_SEPARATOR: // Fall through
case LINE_SEPARATOR: cr = '\n'; break;
case SPACE_SEPARATOR: cr = ' '; break;
case INITIAL_QUOTE_PUNCTUATION: cr = (c == '\u2018') ? '\'' : '"'; break;
case FINAL_QUOTE_PUNCTUATION: cr = (c == '\u2019') ? '\'' : '"'; break;
- case OTHER_PUNCTUATION: {
+ case OTHER_PUNCTUATION:
+ case MATH_SYMBOL: {
switch (c) {
+ case '\u22c5': cr = '*'; break;
+ case '\u2215': cr = '/'; break;
case '\u2032': cr = '\''; break;
case '\u2033': cr = '"'; break;
default: continue;
}
break;
}
- default: continue;
+ default: {
+ /*
+ * For any unknown character, try to decompose the string in a sequence of simpler
+ * letters with their modifiers and restart the whole process from the beginning.
+ * If the character is still unknown after decomposition, leave it unchanged.
+ */
+ if (!doneNFKD) {
+ doneNFKD = true;
+ final String decomposed = Normalizer.normalize(text, Normalizer.Form.NFKD);
+ if (!decomposed.contentEquals(text)) {
+ if (buffer == null) {
+ text = buffer = new StringBuilder(decomposed.length());
+ } else {
+ buffer.setLength(0);
+ }
+ i = buffer.append(decomposed).length();
+ }
+ }
+ continue;
+ }
}
}
if (buffer == null) {
buffer = new StringBuilder(text.length()).append(text);
text = buffer;
}
- if (n == 2) {
- buffer.deleteCharAt(i + 1); // Remove the low surrogate of a surrogate pair.
+ if (cr == 0) {
+ buffer.delete(i, i + n);
+ } else {
+ if (n == 2) {
+ buffer.deleteCharAt(i + 1); // Remove the low surrogate of a surrogate pair.
+ }
+ // Nothing special to do about codepoint here, since 'c' is in
+ // the basic plane (verified by the r < ASCII.length() check).
+ buffer.setCharAt(i, cr);
}
- // Nothing special to do about codepoint here, since 'c' is in
- // the basic plane (verified by the r < ASCII.length() check).
- buffer.setCharAt(i, cr);
}
}
}
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -35,7 +35,7 @@ import org.apache.sis.math.MathFunctions
* This is an element in a linked list. When the reference is disposed, it is removed
* from the enclosing collection.
*
- * @param <E> The type of elements in the collection.
+ * @param <E> the type of elements in the collection.
*
* @author Martin Desruisseaux (MPO, IRD, Geomatys)
* @since 0.3
@@ -90,9 +90,9 @@ abstract class WeakEntry<E> extends Weak
* Counts the number of entries in the given table.
* This method does not verify if the referenced object has been garbage collected.
*
- * @param <E> The type of elements in the collection.
- * @param table The table in which to count the number of entries.
- * @return Number of entries in the given table.
+ * @param <E> the type of elements in the collection.
+ * @param table the table in which to count the number of entries.
+ * @return number of entries in the given table.
*/
static <E> int count(final WeakEntry<E>[] table) {
int n = 0;
@@ -108,8 +108,8 @@ abstract class WeakEntry<E> extends Weak
/**
* Removes this entry from the given table of entries.
*
- * @param table The table from which to remove this entry.
- * @param removeAt The index of this entry in the given table.
+ * @param table the table from which to remove this entry.
+ * @param removeAt the index of this entry in the given table.
* @return {@code true} if this entry has been found and removed, or {@code false} otherwise.
*/
final boolean removeFrom(final WeakEntry<E>[] table, final int removeAt) {
@@ -134,12 +134,12 @@ abstract class WeakEntry<E> extends Weak
/**
* Rehashes the given table.
*
- * @param oldTable The table to rehash.
- * @param count Number of elements in the table (including chained elements).
- * @param callerMethod The method invoking this one, for logging purpose only. The caller class
+ * @param oldTable the table to rehash.
+ * @param count number of elements in the table (including chained elements).
+ * @param callerMethod the method invoking this one, for logging purpose only. The caller class
* will be inferred from the enclosing class of the {@code oldTable} component type. This
* uses the knowledge that all our implementations of {@code WeakEntry} are inner classes.
- * @return The new table array, or {@code oldTable} if no rehash were needed.
+ * @return the new table array, or {@code oldTable} if no rehash were needed.
*/
static <E> WeakEntry<E>[] rehash(final WeakEntry<E>[] oldTable, final int count, final String callerMethod) {
/*
@@ -188,8 +188,8 @@ abstract class WeakEntry<E> extends Weak
* If the number of elements is lower than this threshold, then the table should be
* rehashed for saving space.
*
- * @param capacity The table capacity.
- * @return Minimal number of elements for not rehashing.
+ * @param capacity the table capacity.
+ * @return minimal number of elements for not rehashing.
*/
static int lowerCapacityThreshold(final int capacity) {
return capacity >>> 2;
@@ -199,8 +199,8 @@ abstract class WeakEntry<E> extends Weak
* If the number of elements is upper than this threshold, then the table should be
* rehashed for better performance.
*
- * @param capacity The table capacity.
- * @return Maximal number of elements for not rehashing.
+ * @param capacity the table capacity.
+ * @return maximal number of elements for not rehashing.
*/
static int upperCapacityThreshold(final int capacity) {
return capacity - (capacity >>> 2);
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakHashSet.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakHashSet.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakHashSet.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakHashSet.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -69,7 +69,7 @@ import java.util.Objects;
* the caller. But if a sequence of two or more method calls need to appear atomic from other threads perspective,
* then the caller can synchronize on {@code this}.
*
- * @param <E> The type of elements in the set.
+ * @param <E> the type of elements in the set.
*
* @author Martin Desruisseaux (MPO, IRD, Geomatys)
* @since 0.3
@@ -134,7 +134,7 @@ public class WeakHashSet<E> extends Abst
/**
* Creates a {@code WeakHashSet} for elements of the specified type.
*
- * @param type The type of the element to be included in this set.
+ * @param type the type of the element to be included in this set.
*/
public WeakHashSet(final Class<E> type) {
elementType = type;
@@ -198,7 +198,7 @@ public class WeakHashSet<E> extends Abst
/**
* Returns the count of element in this set.
*
- * @return Number of elements in this set.
+ * @return number of elements in this set.
*/
@Override
public synchronized int size() {
@@ -211,9 +211,9 @@ public class WeakHashSet<E> extends Abst
* If this set already contains the specified element, the call leaves
* this set unchanged and returns {@code false}.
*
- * @param element Element to be added to this set.
+ * @param element element to be added to this set.
* @return {@code true} if this set did not already contain the specified element.
- * @throws NullArgumentException If the given object is {@code null}.
+ * @throws NullArgumentException if the given object is {@code null}.
*/
@Override
public synchronized boolean add(final E element) throws NullArgumentException {
@@ -225,7 +225,7 @@ public class WeakHashSet<E> extends Abst
* Removes a single instance of the specified element from this set, if it is present
* Null values are considered never present.
*
- * @param element element to be removed from this set, if present. Can be {@code null}.
+ * @param element element to be removed from this set, if present. Can be {@code null}.
* @return {@code true} if the set contained the specified element.
*/
@Override
@@ -238,8 +238,8 @@ public class WeakHashSet<E> extends Abst
* contain any object equals to {@code element}, then this method returns {@code null}.
* Null values are considered never present.
*
- * @param element The element to get.
- * @return An element equals to the given one if already presents in the set,
+ * @param element the element to get.
+ * @return an element equals to the given one if already presents in the set,
* or {@code null} otherwise.
*
* @see #unique(Object)
@@ -252,7 +252,7 @@ public class WeakHashSet<E> extends Abst
* Returns {@code true} if this set contains the specified element.
* Null values are considered never present.
*
- * @param element Object to be checked for containment in this set. Can be {@code null}.
+ * @param element object to be checked for containment in this set. Can be {@code null}.
* @return {@code true} if this set contains the specified element.
*/
@Override
@@ -277,10 +277,10 @@ public class WeakHashSet<E> extends Abst
* return element;
* }
*
- * @param <T> The type of the element to get. Can be {@code null}.
- * @param element The element to get or to add in the set if not already presents,
- * or {@code null} if the given element was null.
- * @return An element equals to the given one if already presents in the set,
+ * @param <T> the type of the element to get. Can be {@code null}.
+ * @param element the element to get or to add in the set if not already presents,
+ * or {@code null} if the given element was null.
+ * @return an element equals to the given one if already presents in the set,
* or the given {@code object} otherwise.
*/
public synchronized <T extends E> T unique(final T element) {
@@ -357,7 +357,7 @@ public class WeakHashSet<E> extends Abst
* order. Note that this array contains strong references. Consequently, no
* object reclamation will occur as long as a reference to this array is hold.
*
- * @return All elements in this set.
+ * @return all elements in this set.
*/
@Override
public synchronized E[] toArray() {
@@ -381,7 +381,7 @@ public class WeakHashSet<E> extends Abst
* No element from this set will be garbage collected as long as a
* reference to the iterator is hold.
*
- * @return An iterator over all elements in this set.
+ * @return an iterator over all elements in this set.
*/
@Override
public Iterator<E> iterator() {
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakValueHashMap.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakValueHashMap.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakValueHashMap.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakValueHashMap.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -56,7 +56,7 @@ import java.util.Objects;
* V value;
* synchronized (map) {
* value = map.get(key);
- * if (value != null) {
+ * if (value == null) {
* value = ...; // Create the value here.
* map.put(key, value);
* }
@@ -75,8 +75,8 @@ import java.util.Objects;
* of the caller. But if a sequence of two or more method calls need to appear atomic from other threads perspective,
* then the caller can synchronize on {@code this}.
*
- * @param <K> The class of key elements.
- * @param <V> The class of value elements.
+ * @param <K> the class of key elements.
+ * @param <V> the class of value elements.
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @since 0.3
@@ -233,7 +233,7 @@ public class WeakValueHashMap<K,V> exten
/**
* Creates a new {@code WeakValueHashMap}.
*
- * @param keyType The type of keys in the map.
+ * @param keyType the type of keys in the map.
*/
public WeakValueHashMap(final Class<K> keyType) {
this(keyType, false);
@@ -247,9 +247,9 @@ public class WeakValueHashMap<K,V> exten
* <p>Reference-equality semantic is rarely used. See the {@link java.util.IdentityHashMap} class javadoc
* for a discussion about drawbacks and use cases when reference-equality semantic is useful.</p>
*
- * @param keyType The type of keys in the map.
- * @param identity {@code true} if the map shall use reference-equality in place of object-equality
- * when comparing keys, or {@code false} for the standard behavior.
+ * @param keyType the type of keys in the map.
+ * @param identity {@code true} if the map shall use reference-equality in place of object-equality
+ * when comparing keys, or {@code false} for the standard behavior.
*
* @since 0.4
*/
@@ -309,7 +309,7 @@ public class WeakValueHashMap<K,V> exten
/**
* Returns the number of key-value mappings in this map.
*
- * @return The number of entries in this map.
+ * @return the number of entries in this map.
*/
@Override
public synchronized int size() {
@@ -320,7 +320,7 @@ public class WeakValueHashMap<K,V> exten
/**
* Returns the hash code value for the given key.
*
- * @param key The key (can not be null).
+ * @param key the key (can not be null).
*/
final int keyHashCode(final Object key) {
switch (comparisonMode) {
@@ -334,8 +334,8 @@ public class WeakValueHashMap<K,V> exten
/**
* Returns {@code true} if the two given keys are equal.
*
- * @param k1 The first key (can not be null).
- * @paral k2 The second key.
+ * @param k1 the first key (can not be null).
+ * @paral k2 the second key.
*/
final boolean keyEquals(final Object k1, final Object k2) {
switch (comparisonMode) {
@@ -350,7 +350,7 @@ public class WeakValueHashMap<K,V> exten
* Returns {@code true} if this map contains a mapping for the specified key.
* Null keys are considered never present.
*
- * @param key key whose presence in this map is to be tested.
+ * @param key key whose presence in this map is to be tested.
* @return {@code true} if this map contains a mapping for the specified key.
*/
@Override
@@ -362,7 +362,7 @@ public class WeakValueHashMap<K,V> exten
* Returns {@code true} if this map maps one or more keys to this value.
* Null values are considered never present.
*
- * @param value value whose presence in this map is to be tested.
+ * @param value value whose presence in this map is to be tested.
* @return {@code true} if this map maps one or more keys to this value.
*/
@Override
@@ -375,8 +375,8 @@ public class WeakValueHashMap<K,V> exten
* Returns {@code null} if the map contains no mapping for this key.
* Null keys are considered never present.
*
- * @param key Key whose associated value is to be returned.
- * @return The value to which this map maps the specified key.
+ * @param key key whose associated value is to be returned.
+ * @return the value to which this map maps the specified key.
*/
@Override
@SuppressWarnings("unchecked")
@@ -436,9 +436,9 @@ public class WeakValueHashMap<K,V> exten
* Associates the specified value with the specified key in this map.
* The value is associated using a {@link WeakReference}.
*
- * @param key key with which the specified value is to be associated.
- * @param value value to be associated with the specified key.
- * @return The previous value associated with specified key, or {@code null} if there was no mapping for key.
+ * @param key key with which the specified value is to be associated.
+ * @param value value to be associated with the specified key.
+ * @return the previous value associated with specified key, or {@code null} if there was no mapping for key.
*
* @throws NullArgumentException if the key or the value is {@code null}.
*/
@@ -457,9 +457,9 @@ public class WeakValueHashMap<K,V> exten
* value is returned. Otherwise the specified value is associated to the key using a {@link WeakReference}
* and {@code null} is returned.
*
- * @param key key with which the specified value is to be associated.
- * @param value value to be associated with the specified key.
- * @return The current value associated with specified key, or {@code null} if there was no mapping for key.
+ * @param key key with which the specified value is to be associated.
+ * @param value value to be associated with the specified key.
+ * @return the current value associated with specified key, or {@code null} if there was no mapping for key.
*
* @throws NullArgumentException if the key or the value is {@code null}.
*
@@ -476,7 +476,7 @@ public class WeakValueHashMap<K,V> exten
/**
* Removes the mapping for this key from this map if present.
*
- * @param key key whose mapping is to be removed from the map.
+ * @param key key whose mapping is to be removed from the map.
* @return previous value associated with specified key, or {@code null} if there was no entry for key.
*/
@Override
@@ -527,8 +527,7 @@ public class WeakValueHashMap<K,V> exten
/**
* Returns a view of this set as an array. Note that this array contains strong references.
- * Consequently, no object reclamation will occur as long as a reference to this array is
- * hold.
+ * Consequently, no object reclamation will occur as long as a reference to this array is hold.
*/
@Override
@SuppressWarnings("unchecked")
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -388,6 +388,12 @@ public final class Errors extends Indexe
public static final short IncompatiblePropertyValue_1 = 63;
/**
+ * The \u201c{0}\u201d unit of measurement has dimension of \u2018{1}\u2019 ({2}). It is incompatible with
+ * dimension of \u2018{3}\u2019 ({4}).
+ */
+ public static final short IncompatibleUnitDimension_5 = 163;
+
+ /**
* Unit \u201c{0}\u201d is incompatible with current value.
*/
public static final short IncompatibleUnit_1 = 64;
@@ -574,11 +580,21 @@ public final class Errors extends Indexe
public static final short NonLinearUnit_1 = 100;
/**
+ * The scale of measurement for \u201c{0}\u201d unit is not a ratio scale.
+ */
+ public static final short NonRatioUnit_1 = 162;
+
+ /**
* \u201c{0}\u201d is not a scale unit.
*/
public static final short NonScaleUnit_1 = 101;
/**
+ * \u201c{0}\u201d is not a fundamental or derived unit.
+ */
+ public static final short NonSystemUnit_1 = 161;
+
+ /**
* \u201c{0}\u201d is not a time unit.
*/
public static final short NonTemporalUnit_1 = 102;
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] Tue Nov 1 21:03:06 2016
@@ -90,6 +90,7 @@ IncompatibleFormat_2 = Can
IncompatiblePropertyValue_1 = Property \u201c{0}\u201d has an incompatible value.
IncompatibleUnit_1 = Unit \u201c{0}\u201d is incompatible with current value.
IncompatibleUnits_2 = Units \u201c{0}\u201d and \u201c{1}\u201d are incompatible.
+IncompatibleUnitDimension_5 = The \u201c{0}\u201d unit of measurement has dimension of \u2018{1}\u2019 ({2}). It is incompatible with dimension of \u2018{3}\u2019 ({4}).
InconsistentAttribute_2 = Value \u201c{1}\u201d of attribute \u2018{0}\u2019 is inconsistent with other attributes.
InconsistentNamespace_2 = Expected \u201c{0}\u201d namespace for \u201c{1}\u201d.
InconsistentTableColumns = Inconsistent table columns.
@@ -126,6 +127,8 @@ NonAngularUnit_1 = \u20
NonLinearUnit_1 = \u201c{0}\u201d is not a linear unit.
NonScaleUnit_1 = \u201c{0}\u201d is not a scale unit.
NonTemporalUnit_1 = \u201c{0}\u201d is not a time unit.
+NonSystemUnit_1 = \u201c{0}\u201d is not a fundamental or derived unit.
+NonRatioUnit_1 = The scale of measurement for \u201c{0}\u201d unit is not a ratio scale.
NotABackwardReference_1 = No element for the \u201c{0}\u201d identifier, or the identifier is a forward reference.
NotAKeyValuePair_1 = \u201c{0}\u201d is not a key-value pair.
NotANumber_1 = Argument \u2018{0}\u2019 shall not be NaN (Not-a-Number).
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] Tue Nov 1 21:03:06 2016
@@ -87,6 +87,7 @@ IncompatibleFormat_2 = Le f
IncompatiblePropertyValue_1 = La valeur de la propri\u00e9t\u00e9 \u00ab\u202f{0}\u202f\u00bb n\u2019est pas compatible.
IncompatibleUnit_1 = L\u2019unit\u00e9 \u00ab\u202f{0}\u202f\u00bb n\u2019est pas compatible avec la valeur actuelle.
IncompatibleUnits_2 = Les unit\u00e9s \u00ab\u202f{0}\u202f\u00bb et \u00ab\u202f{1}\u202f\u00bb ne sont pas compatibles.
+IncompatibleUnitDimension_5 = L\u2019unit\u00e9 de mesure \u00ab\u202f{0}\u202f\u00bb a la dimension de \u2018{1}\u2019 ({2}). Elle est incompatible avec la dimension de \u2018{3}\u2019 ({4}).
InconsistentAttribute_2 = La valeur \u00ab\u202f{1}\u202f\u00bb de l\u2019attribut \u2018{0}\u2019 n\u2019est pas coh\u00e9rente avec celles des autres attributs.
InconsistentNamespace_2 = L\u2019espace de nom \u201c{0}\u201d \u00e9tait attendu pour \u201c{1}\u201d.
InconsistentTableColumns = Les colonnes des tables ne sont pas coh\u00e9rentes.
@@ -123,6 +124,8 @@ NonAngularUnit_1 = \u00
NonLinearUnit_1 = \u00ab\u202f{0}\u202f\u00bb n\u2019est pas une unit\u00e9 de longueurs.
NonScaleUnit_1 = \u00ab\u202f{0}\u202f\u00bb n\u2019est pas une unit\u00e9 d\u2019\u00e9chelles.
NonTemporalUnit_1 = \u00ab\u202f{0}\u202f\u00bb n\u2019est pas une unit\u00e9 de temps.
+NonSystemUnit_1 = \u00ab\u202f{0}\u202f\u00bb n\u2019est pas une unit\u00e9 fondamentale ou d\u00e9riv\u00e9e.
+NonRatioUnit_1 = L\u2019\u00e9chelle de mesure de l\u2019unit\u00e9 \u00ab\u202f{0}\u202f\u00bb n\u2019est pas une \u00e9chelle de rapports.
NotABackwardReference_1 = Il n\u2019y a pas d\u2019\u00e9l\u00e9ment pour l\u2019identifiant \u201c{0}\u201d, ou l\u2019identifiant est une r\u00e9f\u00e9rence vers l\u2019avant.
NotAKeyValuePair_1 = \u00ab\u202f{0}\u202f\u00bb n\u2019est pas une paire cl\u00e9-valeur.
NotANumber_1 = L\u2019argument \u2018{0}\u2019 ne doit pas \u00eatre NaN (Not-a-Number).
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -30,7 +30,6 @@ import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.lang.reflect.Modifier;
-import javax.measure.unit.Unit;
import org.opengis.util.CodeList;
import org.opengis.util.InternationalString;
import org.apache.sis.util.Debug;
@@ -41,7 +40,6 @@ import org.apache.sis.util.CharSequences
import org.apache.sis.util.iso.Types;
import org.apache.sis.util.logging.Logging;
import org.apache.sis.internal.system.Loggers;
-import org.apache.sis.internal.util.PatchedUnitFormat;
/**
@@ -410,8 +408,6 @@ public class IndexedResourceBundle exten
replacement = Classes.getShortName(getPublicType((Class<?>) element));
} else if (element instanceof CodeList<?>) {
replacement = Types.getCodeTitle((CodeList<?>) element).toString(getLocale());
- } else if (element instanceof Unit<?>) {
- replacement = PatchedUnitFormat.toString((Unit<?>) element);
}
// No need to check for Numbers or Dates instances, since they are
// properly formatted in the ResourceBundle locale by MessageFormat.
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/package-info.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/package-info.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/package-info.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/resources/package-info.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -84,7 +84,7 @@
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.4
+ * @version 0.8
* @module
*
* @see java.util.ResourceBundle
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/xml/ValueConverter.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/xml/ValueConverter.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/xml/ValueConverter.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/xml/ValueConverter.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -26,7 +26,8 @@ import java.util.Locale;
import java.util.UUID;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
-import javax.measure.unit.Unit;
+import javax.measure.Unit;
+import javax.measure.format.ParserException;
import org.apache.sis.measure.Units;
import org.apache.sis.util.Locales;
@@ -95,14 +96,14 @@ public class ValueConverter {
* {@code toXXX(\u2026)} methods, like the example provided in this <a href="#skip-navbar_top">class
* javadoc</a>.</p>
*
- * @param <T> The compile-time type of the {@code sourceType} argument.
- * @param context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
- * @param value The value that can't be converted.
- * @param sourceType The base type of the value to convert. This is determined by the argument
- * type of the method that caught the exception. For example the source type is always
- * {@code URI.class} if the exception has been caught by the {@link #toURL(MarshalContext, URI)} method.
- * @param targetType The expected type of the converted object.
- * @param exception The exception that occurred during the conversion attempt.
+ * @param <T> the compile-time type of the {@code sourceType} argument.
+ * @param context context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
+ * @param value the value that can't be converted.
+ * @param sourceType the base type of the value to convert. This is determined by the argument type of the method
+ * that caught the exception. For example the source type is always {@code URI.class}
+ * if the exception has been caught by the {@link #toURL(MarshalContext, URI)} method.
+ * @param targetType the expected type of the converted object.
+ * @param exception the exception that occurred during the conversion attempt.
* @return {@code true} if the (un)marshalling process should continue despite this error,
* or {@code false} (the default) if the exception should be propagated, thus causing
* the (un)marshalling to fail.
@@ -131,10 +132,10 @@ public class ValueConverter {
* </ul></li>
* </ul>
*
- * @param context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
- * @param value The locale to convert to a language code, or {@code null}.
- * @return The language code, or {@code null} if the given value was null or does not contains a language code.
- * @throws MissingResourceException If no language code can be found for the given locale.
+ * @param context context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
+ * @param value the locale to convert to a language code, or {@code null}.
+ * @return the language code, or {@code null} if the given value was null or does not contains a language code.
+ * @throws MissingResourceException if no language code can be found for the given locale.
*
* @see Locale#getISO3Language()
* @see Locale#getLanguage()
@@ -163,10 +164,10 @@ public class ValueConverter {
*
* <p>The default implementation returns {@link Locale#getCountry()} if non-empty, or {@code null} otherwise.</p>
*
- * @param context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
- * @param value The locale to convert to a country code, or {@code null}.
- * @return The country code, or {@code null} if the given value was null or does not contains a country code.
- * @throws MissingResourceException If no country code can be found for the given locale.
+ * @param context context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
+ * @param value the locale to convert to a country code, or {@code null}.
+ * @return the country code, or {@code null} if the given value was null or does not contains a country code.
+ * @throws MissingResourceException if no country code can be found for the given locale.
*
* @see Locale#getISO3Country()
* @see Locale#getCountry()
@@ -229,9 +230,9 @@ public class ValueConverter {
* </tr>
* </table>
*
- * @param context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
- * @param value The locale to convert to a character set code, or {@code null}.
- * @return The country code, or {@code null} if the given value was null.
+ * @param context context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
+ * @param value the locale to convert to a character set code, or {@code null}.
+ * @return the country code, or {@code null} if the given value was null.
*
* @see Charset#name()
*
@@ -250,11 +251,11 @@ public class ValueConverter {
* character and the country code (again either as 2 or 3 letters), optionally followed
* by {@code '_'} and the variant.
*
- * @param context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
- * @param value The string to convert to a locale, or {@code null}.
- * @return The converted locale, or {@code null} if the given value was null or empty, or
+ * @param context context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
+ * @param value the string to convert to a locale, or {@code null}.
+ * @return the converted locale, or {@code null} if the given value was null or empty, or
* if an exception was thrown and {@code exceptionOccured(\u2026)} returned {@code true}.
- * @throws IllformedLocaleException If the given string can not be converted to a locale.
+ * @throws IllformedLocaleException if the given string can not be converted to a locale.
*
* @see Locales#parse(String)
*/
@@ -275,11 +276,11 @@ public class ValueConverter {
* <a href="http://www.iana.org/assignments/character-sets">IANA</a> identifier,
* or one of the ISO 19115:2003 {@code MD_CharacterSetCode} identifier.
*
- * @param context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
- * @param value The string to convert to a character set, or {@code null}.
- * @return The converted character set, or {@code null} if the given value was null or empty, or
+ * @param context context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
+ * @param value the string to convert to a character set, or {@code null}.
+ * @return the converted character set, or {@code null} if the given value was null or empty, or
* if an exception was thrown and {@code exceptionOccured(\u2026)} returned {@code true}.
- * @throws IllegalCharsetNameException If the given string can not be converted to a character set.
+ * @throws IllegalCharsetNameException if the given string can not be converted to a character set.
*
* @see Charset#forName(String)
*
@@ -309,11 +310,11 @@ public class ValueConverter {
* return Units.valueOf(value);
* }
*
- * @param context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
- * @param value The string to convert to a unit, or {@code null}.
- * @return The converted unit, or {@code null} if the given value was null or empty, or
+ * @param context context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
+ * @param value the string to convert to a unit, or {@code null}.
+ * @return the converted unit, or {@code null} if the given value was null or empty, or
* if an exception was thrown and {@code exceptionOccured(\u2026)} returned {@code true}.
- * @throws IllegalArgumentException If the given string can not be converted to a unit.
+ * @throws IllegalArgumentException if the given string can not be converted to a unit.
*
* @see Units#valueOf(String)
*/
@@ -321,7 +322,7 @@ public class ValueConverter {
value = trimWhitespaces(value);
if (value != null && !value.isEmpty()) try {
return Units.valueOf(value);
- } catch (IllegalArgumentException e) {
+ } catch (ParserException e) {
if (!exceptionOccured(context, value, String.class, Unit.class, e)) {
throw e;
}
@@ -338,11 +339,11 @@ public class ValueConverter {
* return UUID.fromString(value);
* }
*
- * @param context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
- * @param value The string to convert to a UUID, or {@code null}.
- * @return The converted UUID, or {@code null} if the given value was null or empty, or
+ * @param context context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
+ * @param value the string to convert to a UUID, or {@code null}.
+ * @return the converted UUID, or {@code null} if the given value was null or empty, or
* if an exception was thrown and {@code exceptionOccured(\u2026)} returned {@code true}.
- * @throws IllegalArgumentException If the given string can not be converted to a UUID.
+ * @throws IllegalArgumentException if the given string can not be converted to a UUID.
*
* @see UUID#fromString(String)
*/
@@ -367,11 +368,11 @@ public class ValueConverter {
* return new URI(value);
* }
*
- * @param context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
- * @param value The string to convert to a URI, or {@code null}.
- * @return The converted URI, or {@code null} if the given value was null or empty, or if
+ * @param context context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
+ * @param value the string to convert to a URI, or {@code null}.
+ * @return the converted URI, or {@code null} if the given value was null or empty, or if
* an exception was thrown and {@code exceptionOccured(\u2026)} returned {@code true}.
- * @throws URISyntaxException If the given string can not be converted to a URI.
+ * @throws URISyntaxException if the given string can not be converted to a URI.
*
* @see URI#URI(String)
*/
@@ -396,11 +397,11 @@ public class ValueConverter {
* return value.toURI();
* }
*
- * @param context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
- * @param value The URL to convert to a URI, or {@code null}.
- * @return The converted URI, or {@code null} if the given value was null or if an
+ * @param context context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
+ * @param value the URL to convert to a URI, or {@code null}.
+ * @return the converted URI, or {@code null} if the given value was null or if an
* exception was thrown and {@code exceptionOccured(\u2026)} returned {@code true}.
- * @throws URISyntaxException If the given URL can not be converted to a URI.
+ * @throws URISyntaxException if the given URL can not be converted to a URI.
*
* @see URL#toURI()
*/
@@ -424,11 +425,11 @@ public class ValueConverter {
* return value.toURL();
* }
*
- * @param context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
- * @param value The URI to convert to a URL, or {@code null}.
- * @return The converted URL, or {@code null} if the given value was null or if an
+ * @param context context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
+ * @param value the URI to convert to a URL, or {@code null}.
+ * @return the converted URL, or {@code null} if the given value was null or if an
* exception was thrown and {@code exceptionOccured(\u2026)} returned {@code true}.
- * @throws MalformedURLException If the given URI can not be converted to a URL.
+ * @throws MalformedURLException if the given URI can not be converted to a URL.
*
* @see URI#toURL()
*/
@@ -452,11 +453,11 @@ public class ValueConverter {
* return NilReason.valueOf(value);
* }
*
- * @param context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
- * @param value The string to convert to a nil reason, or {@code null}.
- * @return The converted nil reason, or {@code null} if the given value was null or empty, or
+ * @param context context (GML version, locale, <i>etc.</i>) of the (un)marshalling process.
+ * @param value the string to convert to a nil reason, or {@code null}.
+ * @return the converted nil reason, or {@code null} if the given value was null or empty, or
* if an exception was thrown and {@code exceptionOccured(\u2026)} returned {@code true}.
- * @throws URISyntaxException If the given string can not be converted to a nil reason.
+ * @throws URISyntaxException if the given string can not be converted to a nil reason.
*
* @see NilReason#valueOf(String)
*/
Modified: sis/trunk/core/sis-utility/src/main/resources/META-INF/services/org.apache.sis.util.ObjectConverter
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/resources/META-INF/services/org.apache.sis.util.ObjectConverter?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/resources/META-INF/services/org.apache.sis.util.ObjectConverter [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/resources/META-INF/services/org.apache.sis.util.ObjectConverter [UTF-8] Tue Nov 1 21:03:06 2016
@@ -38,3 +38,5 @@ org.apache.sis.internal.converter.DateCo
org.apache.sis.internal.converter.DateConverter$Timestamp
org.apache.sis.internal.converter.CollectionConverter$List
org.apache.sis.internal.converter.CollectionConverter$Set
+org.apache.sis.internal.converter.FractionConverter
+org.apache.sis.internal.converter.FractionConverter$FromInteger
Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -26,11 +26,11 @@ import java.net.URISyntaxException;
import java.net.MalformedURLException;
import java.nio.charset.Charset;
import java.lang.annotation.ElementType;
-import javax.measure.unit.SI;
-import javax.measure.unit.Unit;
+import javax.measure.Unit;
import org.opengis.util.InternationalString;
import org.opengis.metadata.citation.OnLineFunction;
import org.apache.sis.measure.Angle;
+import org.apache.sis.measure.Units;
import org.apache.sis.math.FunctionProperty;
import org.apache.sis.util.ObjectConverter;
import org.apache.sis.util.UnconvertibleObjectException;
@@ -52,7 +52,7 @@ import java.nio.charset.StandardCharsets
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.5
+ * @version 0.8
* @module
*/
@DependsOn(org.apache.sis.measure.AngleTest.class)
@@ -300,7 +300,7 @@ public final strictfp class StringConver
@Test
public void testUnit() {
final ObjectConverter<String,Unit<?>> c = new StringConverter.Unit();
- runInvertibleConversion(c, "km", SI.KILOMETRE);
+ runInvertibleConversion(c, "km", Units.KILOMETRE);
assertSerializedEquals(c);
}
Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/MeasureTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/MeasureTest.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/MeasureTest.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/MeasureTest.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -17,9 +17,7 @@
package org.apache.sis.internal.jaxb.gml;
import java.net.URISyntaxException;
-import javax.measure.unit.Unit;
-import javax.measure.unit.SI;
-import javax.measure.unit.NonSI;
+import org.apache.sis.measure.Units;
import org.apache.sis.internal.jaxb.Schemas;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.TestCase;
@@ -42,25 +40,25 @@ public final strictfp class MeasureTest
*/
@Test
public void testGetUOM() {
- final Measure measure = new Measure(10, SI.METRE);
+ final Measure measure = new Measure(10, Units.METRE);
assertEquals("urn:ogc:def:uom:EPSG::9001", measure.getUOM());
- measure.unit = NonSI.DEGREE_ANGLE;
+ measure.unit = Units.DEGREE;
assertEquals("urn:ogc:def:uom:EPSG::9102", measure.getUOM());
- measure.unit = Unit.ONE;
+ measure.unit = Units.UNITY;
assertEquals("urn:ogc:def:uom:EPSG::9201", measure.getUOM());
}
/**
* Tests the {@link Measure#setUOM(String)}.
*
- * @throws URISyntaxException Should not happen.
+ * @throws URISyntaxException if the URI used by the test is invalid.
*/
@Test
@DependsOnMethod("testGetUOM")
public void testSetUOM() throws URISyntaxException {
final Measure measure = new Measure();
measure.setUOM("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#m");
- assertEquals(SI.METRE, measure.unit);
+ assertEquals(Units.METRE, measure.unit);
assertEquals("urn:ogc:def:uom:EPSG::9001", measure.getUOM());
measure.asXPointer = true;
assertEquals(Schemas.METADATA_ROOT + Schemas.UOM_PATH + "#xpointer(//*[@gml:id='m'])", measure.getUOM());
@@ -68,15 +66,15 @@ public final strictfp class MeasureTest
measure.unit = null;
measure.asXPointer = false;
measure.setUOM("../uom/ML_gmxUom.xml#xpointer(//*[@gml:id='deg'])");
- assertEquals(NonSI.DEGREE_ANGLE, measure.unit);
+ assertEquals(Units.DEGREE, measure.unit);
assertEquals("urn:ogc:def:uom:EPSG::9102", measure.getUOM());
measure.asXPointer = true;
assertEquals(Schemas.METADATA_ROOT + Schemas.UOM_PATH + "#xpointer(//*[@gml:id='deg'])", measure.getUOM());
measure.unit = null;
measure.asXPointer = true;
- measure.setUOM("gmxUom.xml#kg"); // Not really an existing unit in 'gmxUom'.
- assertEquals(SI.KILOGRAM, measure.unit);
+ measure.setUOM("gmxUom.xml#kg"); // Not really an existing unit in 'gmxUom'.
+ assertEquals(Units.KILOGRAM, measure.unit);
assertEquals(Schemas.METADATA_ROOT + Schemas.UOM_PATH + "#xpointer(//*[@gml:id='kg'])", measure.getUOM());
}
}
Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/MeasurementRangeTest.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -16,9 +16,7 @@
*/
package org.apache.sis.measure;
-import javax.measure.unit.SI;
-import javax.measure.unit.NonSI;
-import javax.measure.converter.ConversionException;
+import javax.measure.IncommensurableException;
import org.junit.Test;
import org.apache.sis.test.TestCase;
import org.apache.sis.test.DependsOn;
@@ -31,7 +29,7 @@ import static org.apache.sis.test.Assert
*
* @author Martin Desruisseaux (IRD)
* @since 0.3
- * @version 0.4
+ * @version 0.8
* @module
*/
@DependsOn(NumberRangeTest.class)
@@ -39,13 +37,13 @@ public final strictfp class MeasurementR
/**
* Tests unit conversions by the {@link MeasurementRange#convertTo(Unit)} method.
*
- * @throws ConversionException Should not happen.
+ * @throws IncommensurableException if a conversion between incompatible units were attempted.
*/
@Test
- public void testConvertTo() throws ConversionException {
- final MeasurementRange<Float> range = MeasurementRange.create(1000f, true, 2000f, true, SI.METRE);
- assertSame(range, range.convertTo(SI.METRE));
- assertEquals(MeasurementRange.create(1f, true, 2f, true, SI.KILOMETRE), range.convertTo(SI.KILOMETRE));
+ public void testConvertTo() throws IncommensurableException {
+ final MeasurementRange<Float> range = MeasurementRange.create(1000f, true, 2000f, true, Units.METRE);
+ assertSame(range, range.convertTo(Units.METRE));
+ assertEquals(MeasurementRange.create(1f, true, 2f, true, Units.KILOMETRE), range.convertTo(Units.KILOMETRE));
}
/**
@@ -53,14 +51,14 @@ public final strictfp class MeasurementR
*/
@Test
public void testAutoConversions() {
- final MeasurementRange<Float> r1 = MeasurementRange.create(1000f, true, 2000f, true, SI.METRE);
- final MeasurementRange<Float> r2 = MeasurementRange.create(1.5f, true, 3f, true, SI.KILOMETRE);
+ final MeasurementRange<Float> r1 = MeasurementRange.create(1000f, true, 2000f, true, Units.METRE);
+ final MeasurementRange<Float> r2 = MeasurementRange.create(1.5f, true, 3f, true, Units.KILOMETRE);
assertEquals(Float.class, r1.getElementType());
assertEquals(Float.class, r2.getElementType());
- assertEquals(MeasurementRange.create(1000f, true, 3000f, true, SI.METRE ), r1.union (r2));
- assertEquals(MeasurementRange.create( 1f, true, 3f, true, SI.KILOMETRE), r2.union (r1));
- assertEquals(MeasurementRange.create(1500f, true, 2000f, true, SI.METRE ), r1.intersect(r2));
- assertEquals(MeasurementRange.create( 1.5f, true, 2f, true, SI.KILOMETRE), r2.intersect(r1));
+ assertEquals(MeasurementRange.create(1000f, true, 3000f, true, Units.METRE ), r1.union (r2));
+ assertEquals(MeasurementRange.create( 1f, true, 3f, true, Units.KILOMETRE), r2.union (r1));
+ assertEquals(MeasurementRange.create(1500f, true, 2000f, true, Units.METRE ), r1.intersect(r2));
+ assertEquals(MeasurementRange.create( 1.5f, true, 2f, true, Units.KILOMETRE), r2.intersect(r1));
}
/**
@@ -68,12 +66,12 @@ public final strictfp class MeasurementR
*/
@Test
public void testAutoConversionsOfAny() {
- final MeasurementRange<?> r1 = MeasurementRange.create(1000f, true, 2000f, true, SI.METRE);
- final MeasurementRange<?> r2 = MeasurementRange.create(1.5f, true, 3f, true, SI.KILOMETRE);
- assertEquals(MeasurementRange.create(1000f, true, 3000f, true, SI.METRE ), r1.unionAny (r2));
- assertEquals(MeasurementRange.create( 1f, true, 3f, true, SI.KILOMETRE), r2.unionAny (r1));
- assertEquals(MeasurementRange.create(1500f, true, 2000f, true, SI.METRE ), r1.intersectAny(r2));
- assertEquals(MeasurementRange.create( 1.5f, true, 2f, true, SI.KILOMETRE), r2.intersectAny(r1));
+ final MeasurementRange<?> r1 = MeasurementRange.create(1000f, true, 2000f, true, Units.METRE);
+ final MeasurementRange<?> r2 = MeasurementRange.create(1.5f, true, 3f, true, Units.KILOMETRE);
+ assertEquals(MeasurementRange.create(1000f, true, 3000f, true, Units.METRE ), r1.unionAny (r2));
+ assertEquals(MeasurementRange.create( 1f, true, 3f, true, Units.KILOMETRE), r2.unionAny (r1));
+ assertEquals(MeasurementRange.create(1500f, true, 2000f, true, Units.METRE ), r1.intersectAny(r2));
+ assertEquals(MeasurementRange.create( 1.5f, true, 2f, true, Units.KILOMETRE), r2.intersectAny(r1));
}
/**
@@ -81,9 +79,9 @@ public final strictfp class MeasurementR
*/
@Test
public void testToString() {
- MeasurementRange<Float> range = MeasurementRange.create(10f, true, 20f, true, SI.KILOMETRE);
+ MeasurementRange<Float> range = MeasurementRange.create(10f, true, 20f, true, Units.KILOMETRE);
assertEquals("[10.0 \u2026 20.0] km", range.toString());
- range = MeasurementRange.create(10f, true, 20f, true, NonSI.DEGREE_ANGLE);
+ range = MeasurementRange.create(10f, true, 20f, true, Units.DEGREE);
assertEquals("[10.0 \u2026 20.0]�", range.toString());
}
@@ -92,8 +90,8 @@ public final strictfp class MeasurementR
*/
@Test
public void testSerialization() {
- NumberRange<Float> r1 = MeasurementRange.create(1000f, true, 2000f, true, SI.METRE);
- NumberRange<Float> r2 = MeasurementRange.create(1.5f, true, 3f, true, SI.KILOMETRE);
+ NumberRange<Float> r1 = MeasurementRange.create(1000f, true, 2000f, true, Units.METRE);
+ NumberRange<Float> r2 = MeasurementRange.create(1.5f, true, 3f, true, Units.KILOMETRE);
assertNotSame(r1, assertSerializedEquals(r1));
assertNotSame(r2, assertSerializedEquals(r2));
}
Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/RangeFormatTest.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -24,8 +24,6 @@ import java.text.FieldPosition;
import java.text.ParsePosition;
import java.text.ParseException;
import java.text.AttributedCharacterIterator;
-import javax.measure.unit.NonSI;
-import javax.measure.unit.SI;
import org.junit.Test;
import org.apache.sis.test.TestCase;
import org.apache.sis.test.DependsOn;
@@ -42,7 +40,7 @@ import static org.apache.sis.internal.ut
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.4
+ * @version 0.8
* @module
*/
@DependsOn(MeasurementRangeTest.class)
@@ -167,34 +165,34 @@ public final strictfp class RangeFormatT
assertEquals("maxPos.endIndex", 7, maxPos.getEndIndex());
// Positive infinity with integers
- assertEquals("[50 \u2026 \u221e)", format(new NumberRange<Integer>(Integer.class, 50, true, null, true)));
+ assertEquals("[50 \u2026 \u221e)", format(new NumberRange<>(Integer.class, 50, true, null, true)));
assertEquals("minPos.beginIndex", 1, minPos.getBeginIndex());
assertEquals("minPos.endIndex", 3, minPos.getEndIndex());
assertEquals("maxPos.beginIndex", 6, maxPos.getBeginIndex());
assertEquals("maxPos.endIndex", 7, maxPos.getEndIndex());
// Negative infinity with integers
- assertEquals("(-\u221e \u2026 40]", format(new NumberRange<Integer>(Integer.class, null, true, 40, true)));
+ assertEquals("(-\u221e \u2026 40]", format(new NumberRange<>(Integer.class, null, true, 40, true)));
assertEquals("minPos.beginIndex", 1, minPos.getBeginIndex());
assertEquals("minPos.endIndex", 3, minPos.getEndIndex());
assertEquals("maxPos.beginIndex", 6, maxPos.getBeginIndex());
assertEquals("maxPos.endIndex", 8, maxPos.getEndIndex());
// Measurement
- assertEquals("[-10 \u2026 20] m", format(MeasurementRange.create(-10, true, 20, true, SI.METRE)));
+ assertEquals("[-10 \u2026 20] m", format(MeasurementRange.create(-10, true, 20, true, Units.METRE)));
assertEquals("minPos.beginIndex", 1, minPos.getBeginIndex());
assertEquals("minPos.endIndex", 4, minPos.getEndIndex());
assertEquals("maxPos.beginIndex", 7, maxPos.getBeginIndex());
assertEquals("maxPos.endIndex", 9, maxPos.getEndIndex());
- assertEquals("[-10 \u2026 20]�", format(MeasurementRange.create(-10, true, 20, true, NonSI.DEGREE_ANGLE)));
+ assertEquals("[-10 \u2026 20]�", format(MeasurementRange.create(-10, true, 20, true, Units.DEGREE)));
assertEquals("minPos.beginIndex", 1, minPos.getBeginIndex());
assertEquals("minPos.endIndex", 4, minPos.getEndIndex());
assertEquals("maxPos.beginIndex", 7, maxPos.getBeginIndex());
assertEquals("maxPos.endIndex", 9, maxPos.getEndIndex());
maxPos = new FieldPosition(RangeFormat.Field.UNIT);
- assertEquals("[-1 \u2026 2] km", format(MeasurementRange.create(-1, true, 2, true, SI.KILOMETRE)));
+ assertEquals("[-1 \u2026 2] km", format(MeasurementRange.create(-1, true, 2, true, Units.KILOMETRE)));
assertEquals("unitPos.beginIndex", 9, maxPos.getBeginIndex());
assertEquals("unitPos.endIndex", 11, maxPos.getEndIndex());
}
Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/SexagesimalConverterTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/SexagesimalConverterTest.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/SexagesimalConverterTest.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/SexagesimalConverterTest.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -16,14 +16,12 @@
*/
package org.apache.sis.measure;
-import javax.measure.unit.Unit;
-import javax.measure.quantity.Quantity;
-import javax.measure.converter.UnitConverter;
-import org.apache.sis.internal.util.PatchedUnitFormat;
+import javax.measure.Unit;
+import javax.measure.Quantity;
+import javax.measure.UnitConverter;
import org.apache.sis.test.TestCase;
import org.junit.Test;
-import static javax.measure.unit.NonSI.DEGREE_ANGLE;
import static org.apache.sis.measure.SexagesimalConverter.*;
import static org.apache.sis.test.Assert.*;
@@ -33,7 +31,7 @@ import static org.apache.sis.test.Assert
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.6
+ * @version 0.8
* @module
*/
public final strictfp class SexagesimalConverterTest extends TestCase {
@@ -46,7 +44,7 @@ public final strictfp class SexagesimalC
* Converts the given value to an other unit, compares with the expected value, and verify
* the inverse conversion. Then tries again with the negative of the given values.
*/
- private static <Q extends Quantity> void checkConversion(
+ private static <Q extends Quantity<Q>> void checkConversion(
final double expected, final Unit<Q> unitExpected,
final double actual, final Unit<Q> unitActual)
{
@@ -63,11 +61,11 @@ public final strictfp class SexagesimalC
*/
@Test
public void testDM() {
- checkConversion(10.00, DEGREE_ANGLE, 10.0000, DM);
- checkConversion(10.006, DEGREE_ANGLE, 10.0036, DM);
- checkConversion(10.50, DEGREE_ANGLE, 10.3000, DM);
- checkConversion(10.987333333333333, DEGREE_ANGLE, 10.5924, DM);
- checkConversion(44.503354166666666, DEGREE_ANGLE, 44.3020125, DM);
+ checkConversion(10.00, Units.DEGREE, 10.0000, DM);
+ checkConversion(10.006, Units.DEGREE, 10.0036, DM);
+ checkConversion(10.50, Units.DEGREE, 10.3000, DM);
+ checkConversion(10.987333333333333, Units.DEGREE, 10.5924, DM);
+ checkConversion(44.503354166666666, Units.DEGREE, 44.3020125, DM);
}
/**
@@ -75,11 +73,11 @@ public final strictfp class SexagesimalC
*/
@Test
public void testDMS() {
- checkConversion(10.00, DEGREE_ANGLE, 10.0000, DMS);
- checkConversion(10.01, DEGREE_ANGLE, 10.0036, DMS);
- checkConversion(10.50, DEGREE_ANGLE, 10.3000, DMS);
- checkConversion(10.99, DEGREE_ANGLE, 10.5924, DMS);
- checkConversion(44.505590277777777, DEGREE_ANGLE, 44.3020125, DMS);
+ checkConversion(10.00, Units.DEGREE, 10.0000, DMS);
+ checkConversion(10.01, Units.DEGREE, 10.0036, DMS);
+ checkConversion(10.50, Units.DEGREE, 10.3000, DMS);
+ checkConversion(10.99, Units.DEGREE, 10.5924, DMS);
+ checkConversion(44.505590277777777, Units.DEGREE, 44.3020125, DMS);
}
/**
@@ -87,21 +85,20 @@ public final strictfp class SexagesimalC
*/
@Test
public void testDMS_Scaled() {
- checkConversion(10.00, DEGREE_ANGLE, 100000, DMS_SCALED);
- checkConversion(10.01, DEGREE_ANGLE, 100036, DMS_SCALED);
- checkConversion(10.50, DEGREE_ANGLE, 103000, DMS_SCALED);
- checkConversion(10.99, DEGREE_ANGLE, 105924, DMS_SCALED);
- checkConversion(44.505590277777777, DEGREE_ANGLE, 443020.125, DMS_SCALED);
+ checkConversion(10.00, Units.DEGREE, 100000, DMS_SCALED);
+ checkConversion(10.01, Units.DEGREE, 100036, DMS_SCALED);
+ checkConversion(10.50, Units.DEGREE, 103000, DMS_SCALED);
+ checkConversion(10.99, Units.DEGREE, 105924, DMS_SCALED);
+ checkConversion(44.505590277777777, Units.DEGREE, 443020.125, DMS_SCALED);
}
/**
- * Tests {@link PatchedUnitFormat#toString(Unit)}.
- * Tested here because it can be tested only after {@link SexagesimalConverter} initialization.
+ * Verifies the unit symbols.
*/
@Test
- public void testPatchedUnitFormat() {
- assertEquals("D.M", PatchedUnitFormat.toString(DM));
- assertEquals("D.MS", PatchedUnitFormat.toString(DMS));
- assertEquals("DMS", PatchedUnitFormat.toString(DMS_SCALED));
+ public void testToString() {
+ assertEquals("D.M", DM.toString());
+ assertEquals("D.MS", DMS.toString());
+ assertEquals("DMS", DMS_SCALED.toString());
}
}