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 2014/11/18 15:44:12 UTC
svn commit: r1640352 [2/2] - in /sis/trunk: ./
core/sis-feature/src/main/java/org/apache/sis/feature/
core/sis-feature/src/test/java/org/apache/sis/feature/
core/sis-feature/src/test/java/org/apache/sis/test/suite/
core/sis-metadata/src/main/java/org/a...
Modified: sis/trunk/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueMap.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueMap.java?rev=1640352&r1=1640351&r2=1640352&view=diff
==============================================================================
--- sis/trunk/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueMap.java [UTF-8] (original)
+++ sis/trunk/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueMap.java [UTF-8] Tue Nov 18 14:44:11 2014
@@ -20,15 +20,11 @@ import java.util.Map;
import java.util.Set;
import java.util.Iterator;
import java.util.NoSuchElementException;
-import org.apache.sis.util.CharSequences;
-import org.apache.sis.util.Debug;
+import org.apache.sis.internal.util.AbstractMapEntry;
import static org.apache.sis.metadata.PropertyAccessor.RETURN_NULL;
import static org.apache.sis.metadata.PropertyAccessor.RETURN_PREVIOUS;
-// Branch-dependent imports
-import org.apache.sis.internal.jdk7.Objects;
-
/**
* A view of a metadata object as a map. Keys are property names and values
@@ -181,7 +177,7 @@ final class ValueMap extends PropertyMap
* @version 0.3
* @module
*/
- final class Property implements Map.Entry<String,Object> {
+ final class Property extends AbstractMapEntry<String,Object> {
/**
* The property index.
*/
@@ -229,41 +225,6 @@ final class ValueMap extends PropertyMap
public Object setValue(final Object value) {
return accessor.set(index, metadata, value, RETURN_PREVIOUS);
}
-
- /**
- * Compares the specified object with this entry for equality.
- * Criterion are specified by the {@link Map.Entry} contract.
- */
- @Override
- public boolean equals(final Object object) {
- if (object instanceof Map.Entry<?,?>) {
- final Map.Entry<?,?> entry = (Map.Entry<?,?>) object;
- return Objects.equals(getKey(), entry.getKey()) &&
- Objects.equals(getValue(), entry.getValue());
- }
- return false;
- }
-
- /**
- * Returns the hash code value for this map entry. The
- * formula is specified by the {@link Map.Entry} contract.
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(getKey()) ^ Objects.hashCode(getValue());
- }
-
- /**
- * Returns a string representation of this entry.
- * This method is mostly for debugging purpose.
- */
- @Debug
- @Override
- public String toString() {
- String value = String.valueOf(getValue());
- value = value.substring(0, CharSequences.indexOfLineStart(value, 1, 0));
- return getKey() + '=' + value;
- }
}
Modified: sis/trunk/core/sis-referencing/src/main/java/org/apache/sis/referencing/Properties.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-referencing/src/main/java/org/apache/sis/referencing/Properties.java?rev=1640352&r1=1640351&r2=1640352&view=diff
==============================================================================
--- sis/trunk/core/sis-referencing/src/main/java/org/apache/sis/referencing/Properties.java [UTF-8] (original)
+++ sis/trunk/core/sis-referencing/src/main/java/org/apache/sis/referencing/Properties.java [UTF-8] Tue Nov 18 14:44:11 2014
@@ -17,13 +17,8 @@
package org.apache.sis.referencing;
import java.util.Map;
-import java.util.Set;
import java.util.HashMap;
-import java.util.AbstractMap;
-import java.util.AbstractSet;
import java.util.Collection;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
import java.io.Serializable;
import org.opengis.util.GenericName;
import org.opengis.referencing.datum.Datum;
@@ -32,6 +27,7 @@ import org.opengis.referencing.Identifie
import org.opengis.referencing.ReferenceIdentifier;
import org.opengis.referencing.operation.CoordinateOperation;
import org.opengis.metadata.quality.PositionalAccuracy;
+import org.apache.sis.internal.util.AbstractMap;
/**
@@ -220,14 +216,6 @@ final class Properties extends AbstractM
}
/**
- * Returns true if this map contains a mapping for the specified key.
- */
- @Override
- public boolean containsKey(final Object key) {
- return get(key) != null;
- }
-
- /**
* Returns the value to which this map maps the specified key.
* Returns {@code null} if the map contains no mapping for this key.
*/
@@ -238,93 +226,50 @@ final class Properties extends AbstractM
}
/**
- * Returns a set view of the mappings contained in this map.
+ * Iterates over the {@link #KEYS}, returning only the entry having a non-null value.
*/
@Override
- public Set<Entry<String,Object>> entrySet() {
- return new EntrySet();
- }
-
- /**
- * The view returned by {@link #entrySet()}.
- */
- private final class EntrySet extends AbstractSet<Entry<String,Object>> {
- /** Creates a new instance. */
- EntrySet() {
- }
-
- /** Delegates to the enclosing map. */
- @Override
- public boolean isEmpty() {
- return Properties.this.isEmpty();
- }
-
- /** Delegates to the enclosing map. */
- @Override
- public int size() {
- return Properties.this.size();
- }
-
- /** Iterates over the {@link #KEYS}, returning only the entry having a non-null value. */
- @Override
- public Iterator<Entry<String, Object>> iterator() {
- return new Iter();
- }
- }
-
- /**
- * The iterator returned by {@link EntrySet#iterator()}.
- */
- private final class Iter implements Iterator<Entry<String,Object>> {
- /**
- * Index of the next element to return.
- */
- private int nextIndex;
-
- /**
- * Index of the value to be returned by {@link #next()}, or {@code null} if not yet computed.
- */
- private Object value;
-
- /**
- * Creates a new iterator.
- */
- Iter() {
- }
-
- /**
- * Returns {@code true} if there is a value to return.
- */
- @Override
- public boolean hasNext() {
- while (value == null) {
- if (nextIndex == KEYS.length) {
- return false;
+ protected EntryIterator<String,Object> entryIterator() {
+ return new EntryIterator<String,Object>() {
+ /**
+ * Index of the next element to inspect.
+ */
+ private int nextIndex;
+
+ /**
+ * Index of the value to be returned by {@link #next()}, or {@code null} if not yet computed.
+ */
+ private Object value;
+
+ /**
+ * Returns {@code true} if there is a value to return.
+ */
+ @Override
+ protected boolean next() {
+ while (nextIndex < KEYS.length) {
+ value = getAt(nextIndex++);
+ if (value != null) {
+ return true;
+ }
}
- value = getAt(nextIndex++);
+ return false;
}
- return true;
- }
- /**
- * Returns the next element.
- */
- @Override
- public Entry<String, Object> next() {
- if (hasNext()) {
- final Entry<String, Object> entry = new SimpleImmutableEntry<String, Object>(KEYS[nextIndex-1], value);
- value = null; // For forcing the next call to 'hasNext()' to increment 'nextIndex'.
- return entry;
+ /**
+ * Returns the key at the current position.
+ */
+ @Override
+ protected String getKey() {
+ return KEYS[nextIndex - 1];
}
- throw new NoSuchElementException();
- }
- /**
- * Unsupported operation, since this map is read-only.
- */
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
+ /**
+ * Returns the value at the current position.
+ */
+ @Override
+ protected Object getValue() {
+ return value;
+ }
+ };
}
}
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java?rev=1640352&r1=1640351&r2=1640352&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java [UTF-8] Tue Nov 18 14:44:11 2014
@@ -550,7 +550,7 @@ public class IdentifierMapAdapter extend
buffer.append(", ");
}
SpecializedIdentifier.format(buffer, entry.getKey(), entry.getValue());
- }
+ }
return buffer.append('}').toString();
}
}
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java?rev=1640352&r1=1640351&r2=1640352&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java [UTF-8] Tue Nov 18 14:44:11 2014
@@ -187,7 +187,7 @@ public class Cache<K,V> extends Abstract
/**
* A view over the entries in the cache.
*/
- private transient Set<Entry<K,V>> entries;
+ private volatile transient Set<Entry<K,V>> entries;
/**
* Creates a new cache with a default initial capacity and cost limit of 100.
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=1640352&r1=1640351&r2=1640352&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 18 14:44:11 2014
@@ -95,9 +95,10 @@ abstract class WeakEntry<E> extends Weak
*/
static <E> int count(final WeakEntry<E>[] table) {
int n = 0;
- for (int i=0; i<table.length; i++) {
- for (WeakEntry<E> e=table[i]; e!=null; e=e.next) {
+ for (WeakEntry<E> e : table) {
+ while (e != null) {
n++;
+ e = e.next;
}
}
return n;
@@ -159,8 +160,8 @@ abstract class WeakEntry<E> extends Weak
final Class<?> entryType = oldTable.getClass().getComponentType();
@SuppressWarnings("unchecked")
final WeakEntry<E>[] table = (WeakEntry<E>[]) Array.newInstance(entryType, capacity);
- for (int i=0; i<oldTable.length; i++) {
- for (WeakEntry<E> next=oldTable[i]; next!=null;) {
+ for (WeakEntry<E> next : oldTable) {
+ while (next != null) {
final WeakEntry<E> e = next;
next = next.next; // We keep 'next' right now because its value will change.
final int index = e.hash % table.length;
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=1640352&r1=1640351&r2=1640352&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 18 14:44:11 2014
@@ -293,22 +293,17 @@ public class WeakValueHashMap<K,V> exten
/**
* Checks if this {@code WeakValueHashMap} is valid. This method counts the number of elements
- * and compares it to {@link #count}. If the check fails, the number of elements is corrected
- * (if we didn't, an {@link AssertionError} would be thrown for every operations after the first
- * error, which make debugging more difficult). The set is otherwise unchanged, which should
- * help to get similar behavior as if assertions hasn't been turned on.
+ * and compares it to {@link #count}. This method is invoked in assertions only.
*/
@Debug
final boolean isValid() {
- assert Thread.holdsLock(this);
- assert count <= upperCapacityThreshold(table.length);
- final int n = count(table);
- if (n != count) {
- count = n;
- return false;
- } else {
- return true;
+ if (!Thread.holdsLock(this)) {
+ throw new AssertionError();
}
+ if (count > upperCapacityThreshold(table.length)) {
+ throw new AssertionError(count);
+ }
+ return count(table) == count;
}
/**
@@ -520,12 +515,13 @@ public class WeakValueHashMap<K,V> exten
final Map.Entry<K,V>[] elements = new Map.Entry[size()];
int index = 0;
final Entry[] table = WeakValueHashMap.this.table;
- for (int i=0; i<table.length; i++) {
- for (Entry el=table[i]; el!=null; el=(Entry) el.next) {
+ for (Entry el : table) {
+ while (el != null) {
final Map.Entry<K,V> entry = new SimpleEntry<K,V>(el);
if (entry.getValue() != null) {
elements[index++] = entry;
}
+ el= (Entry) el.next;
}
}
return ArraysExt.resize(elements, index);
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java?rev=1640352&r1=1640351&r2=1640352&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java [UTF-8] Tue Nov 18 14:44:11 2014
@@ -31,6 +31,7 @@ import org.apache.sis.util.Debug;
import org.apache.sis.util.Utilities;
import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.util.resources.Errors;
+import org.apache.sis.internal.util.AbstractMapEntry;
// Branch-dependent imports
import org.apache.sis.internal.jdk7.Objects;
@@ -199,7 +200,7 @@ public class DefaultRecord implements Re
* Operations on this entry delegate to {@link DefaultRecord#locate(MemberName)}
* and {@link DefaultRecord#set(MemberName, Object)} methods.
*/
- private final class Entry implements Map.Entry<MemberName,Object> {
+ private final class Entry extends AbstractMapEntry<MemberName,Object> {
/** Index of the record member represented by this entry. */
private final int index;
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=1640352&r1=1640351&r2=1640352&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 18 14:44:11 2014
@@ -81,6 +81,11 @@ public final class Errors extends Indexe
public static final short CanNotAddToExclusiveSet_2 = 0;
/**
+ * Can not assign “{1}” to “{0}”.
+ */
+ public static final short CanNotAssign_2 = 167;
+
+ /**
* Can not compute the derivative.
*/
public static final short CanNotComputeDerivative = 1;
@@ -176,7 +181,7 @@ public final class Errors extends Indexe
public static final short DuplicatedElement_1 = 16;
/**
- * Identifier “{0}” is duplicated.
+ * Name or identifier “{0}” is used more than once.
*/
public static final short DuplicatedIdentifier_1 = 17;
@@ -679,7 +684,7 @@ public final class Errors extends Indexe
public static final short ParameterNotFound_2 = 147;
/**
- * Property “{1}” is already exists in “{0}”.
+ * Property “{1}” already exists in “{0}”.
*/
public static final short PropertyAlreadyExists_2 = 156;
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=1640352&r1=1640351&r2=1640352&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 18 14:44:11 2014
@@ -27,6 +27,7 @@
AbstractType_1 = Type \u2018{0}\u2019 is abstract.
AmbiguousName_3 = Name \u201c{2}\u201d is ambiguous because it can be understood as either \u201c{0}\u201d or \u201c{1}\u201d.
CanNotAddToExclusiveSet_2 = No element can be added to this set because properties \u2018{0}\u2019 and \u2018{1}\u2019 are mutually exclusive.
+CanNotAssign_2 = Can not assign \u201c{1}\u201d to \u201c{0}\u201d.
CanNotConcatenateTransforms_2 = Can not concatenate transforms \u201c{0}\u201d and \u201c{1}\u201d.
CanNotConnectTo_1 = Can not connect to \u201c{0}\u201d.
CanNotConvertFromType_2 = Can not convert from type \u2018{0}\u2019 to type \u2018{1}\u2019.
@@ -46,7 +47,7 @@ ColinearAxisDirections_2 = Axis
DeadThread_1 = Thread \u201c{0}\u201d is dead.
DirectoryNotExpected_1 = The \u201c{0}\u201d file points to a directory instead of a regular file.
DuplicatedElement_1 = Element \u201c{0}\u201d is duplicated.
-DuplicatedIdentifier_1 = Identifier \u201c{0}\u201d is duplicated.
+DuplicatedIdentifier_1 = Name or identifier \u201c{0}\u201d is used more than once.
DuplicatedOption_1 = Option \u201c{0}\u201d is duplicated.
DuplicatedParameterName_4 = Name or alias for parameter \u201c{0}\u201d at index {1} conflict with name \u201c{2}\u201d at index {3}.
ElementAlreadyPresent_1 = Element \u201c{0}\u201d is already present.
@@ -146,7 +147,7 @@ NullCollectionElement_1 = \u20
NullMapKey = Null key is not allowed in this dictionary.
NullMapValue = Null values are not allowed in this dictionary.
OddArrayLength_1 = Array length is {0}, while we expected an even length.
-PropertyAlreadyExists_2 = Property \u201c{1}\u201d is already exists in \u201c{0}\u201d.
+PropertyAlreadyExists_2 = Property \u201c{1}\u201d already exists in \u201c{0}\u201d.
ParameterNotFound_2 = No parameter named \u201c{1}\u201d has been found in \u201c{0}\u201d.
PropertyNotFound_2 = No property named \u201c{1}\u201d has been found in \u201c{0}\u201d.
RecordAlreadyDefined_2 = Record \u201c{1}\u201d is already defined in schema \u201c{0}\u201d.
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=1640352&r1=1640351&r2=1640352&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 18 14:44:11 2014
@@ -17,6 +17,7 @@
AbstractType_1 = Le type \u2018{0}\u2019 est abstrait.
AmbiguousName_3 = Le nom \u00ab\u202f{2}\u202f\u00bb est ambigu\u00eb car il peut \u00eatre interpr\u00e9t\u00e9 comme \u00ab\u202f{0}\u202f\u00bb ou \u00ab\u202f{1}\u202f\u00bb.
CanNotAddToExclusiveSet_2 = Aucun \u00e9l\u00e9ment ne peut \u00eatre ajout\u00e9 \u00e0 cet ensemble car les propri\u00e9t\u00e9s \u2018{0}\u2019 et \u2018{1}\u2019 sont mutuellement exclusives.
+CanNotAssign_2 = Ne peut pas assigner \u00ab\u202f{1}\u202f\u00bb \u00e0 \u00ab\u202f{0}\u202f\u00bb.
CanNotConcatenateTransforms_2 = Les transformations \u00ab\u202f{0}\u202f\u00bb et \u00ab\u202f{1}\u202f\u00bb ne peuvent pas \u00eatre combin\u00e9es.
CanNotConnectTo_1 = Ne peut pas se connecter \u00e0 \u00ab\u202f{0}\u202f\u00bb.
CanNotConvertFromType_2 = Ne peut pas convertir du type \u2018{0}\u2019 vers le type \u2018{1}\u2019.
@@ -36,7 +37,7 @@ ColinearAxisDirections_2 = Les
DeadThread_1 = La t\u00e2che \u00ab\u202f{0}\u202f\u00bb est morte.
DirectoryNotExpected_1 = Le fichier \u00ab\u202f{0}\u202f\u00bb d\u00e9signe un r\u00e9pertoire plut\u00f4t qu\u2019un fichier r\u00e9gulier.
DuplicatedElement_1 = L\u2019\u00e9lement \u00ab\u202f{0}\u202f\u00bb est dupliqu\u00e9.
-DuplicatedIdentifier_1 = L\u2019identifiant \u00ab\u202f{0}\u202f\u00bb est dupliqu\u00e9.
+DuplicatedIdentifier_1 = Le nom ou l\u2019identifiant \u00ab\u202f{0}\u202f\u00bb est utilis\u00e9 plus d\u2019une fois.
DuplicatedOption_1 = L\u2019option \u00ab\u202f{0}\u202f\u00bb est dupliqu\u00e9e.
DuplicatedParameterName_4 = Le nom ou un alias pour le param\u00e8tre \u00ab\u202f{0}\u202f\u00bb \u00e0 l\u2019index {1} duplique le nom \u00ab\u202f{2}\u202f\u00bb \u00e0 l\u2019index {3}.
ElementAlreadyPresent_1 = L\u2019\u00e9lement \u00ab\u202f{0}\u202f\u00bb est d\u00e9j\u00e0 pr\u00e9sent.
Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1640352&r1=1640351&r2=1640352&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java [UTF-8] Tue Nov 18 14:44:11 2014
@@ -75,6 +75,7 @@ import org.junit.BeforeClass;
org.apache.sis.util.collection.TreeTablesTest.class,
org.apache.sis.util.collection.CodeListSetTest.class,
org.apache.sis.internal.util.CollectionsExtTest.class,
+ org.apache.sis.internal.util.AbstractMapTest.class,
// GeoAPI most basic types.
org.apache.sis.internal.util.DefinitionURITest.class,