Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -215,8 +215,8 @@ public final class DefinitionURI {
* If this method does not recognize the given URI, then it returns {@code null}.
* If the given URI is incomplete, then the {@link #code} value will be {@code null}.
*
- * @param uri The URI to parse.
- * @return The parse result, or {@code null} if the given URI is not recognized.
+ * @param uri the URI to parse.
+ * @return the parse result, or {@code null} if the given URI is not recognized.
*/
public static DefinitionURI parse(final String uri) {
ensureNonNull("uri", uri);
@@ -315,10 +315,10 @@ public final class DefinitionURI {
* Returns {@code true} if a sub-region of {@code urn} matches the given {@code component},
* ignoring case, leading and trailing whitespaces.
*
- * @param component The expected component ({@code "urn"}, {@code "ogc"}, {@code "def"}, <i>etc.</i>)
- * @param urn The URN for which to test a subregion.
- * @param lower Index of the first character in {@code urn} to compare, after skipping whitespaces.
- * @param upper Index after the last character in {@code urn} to compare, ignoring whitespaces.
+ * @param component the expected component ({@code "urn"}, {@code "ogc"}, {@code "def"}, <i>etc.</i>)
+ * @param urn the URN for which to test a subregion.
+ * @param lower index of the first character in {@code urn} to compare, after skipping whitespaces.
+ * @param upper index after the last character in {@code urn} to compare, ignoring whitespaces.
* @return {@code true} if the given sub-region of {@code urn} match the given component.
*/
static boolean regionMatches(final String component, final String urn, int lower, int upper) {
@@ -338,15 +338,15 @@ public final class DefinitionURI {
* returns {@code null}. The presence of more {@code ':'} characters means that the code has parameters,
* (e.g. {@code "urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45"}) which are not handled by this method.</p>
*
- * @param urn The URN from which to get the code.
- * @param fromIndex Index of the first character in {@code urn} to check.
- * @return The code part of the URN, or {@code null} if empty or invalid.
+ * @param urn the URN from which to get the code.
+ * @param fromIndex index of the first character in {@code urn} to check.
+ * @return the code part of the URN, or {@code null} if empty or invalid.
*/
private static String codeIgnoreVersion(final String urn, int fromIndex) {
final int length = urn.length();
fromIndex = skipLeadingWhitespaces(urn, fromIndex, length);
if (fromIndex >= length) {
- return null; // Empty code.
+ return null; // Empty code.
}
final int s = urn.indexOf(SEPARATOR, fromIndex);
if (s >= 0) {
@@ -379,10 +379,10 @@ public final class DefinitionURI {
* <li>The HTTP form (e.g. {@code "http://www.opengis.net/gml/srs/epsg.xml#4326"}).</li>
* </ul>
*
- * @param type The expected object type (e.g. {@code "crs"}) in lower cases. See class javadoc for a list of types.
- * @param authority The expected authority, typically {@code "epsg"}. See class javadoc for a list of authorities.
- * @param uri The URI to parse.
- * @return The code part of the given URI, or {@code null} if the codespace does not match the given type
+ * @param type the expected object type (e.g. {@code "crs"}) in lower cases. See class javadoc for a list of types.
+ * @param authority the expected authority, typically {@code "epsg"}. See class javadoc for a list of authorities.
+ * @param uri the URI to parse.
+ * @return the code part of the given URI, or {@code null} if the codespace does not match the given type
* and authority, the code is empty, or the code is followed by parameters.
*/
public static String codeOf(final String type, final String authority, final String uri) {
@@ -427,13 +427,12 @@ public final class DefinitionURI {
lower = upper + 1;
upper = uri.indexOf(SEPARATOR, lower);
if (upper < 0) {
- return null; // No more components.
+ return null; // No more components.
}
switch (p) {
- case 0: if (regionMatches("ogc", uri, lower, upper)) {
- continue; // "ogc" is tested before "x-ogc" because more common.
- }
- component = "x-ogc"; break; // Fallback if the component is not "ogc".
+ // "ogc" is tested before "x-ogc" because more common.
+ case 0: if (regionMatches("ogc", uri, lower, upper)) continue;
+ component = "x-ogc"; break; // Fallback if the component is not "ogc".
case 1: component = "def"; break;
case 2: component = type; break;
case 3: component = authority; break;
@@ -455,15 +454,13 @@ public final class DefinitionURI {
* (example: {@code "http://www.opengis.net/gml/srs/epsg.xml#4326"})</li>
* </ul>
*
- * @param type The expected type in lower cases, or {@code null} for any.
- * @param authority The expected authority, or {@code null} for any.
- * @param url The URL to parse.
- * @param result If non-null, store the type, authority and code in that object.
+ * @param type the expected type in lower cases, or {@code null} for any.
+ * @param authority the expected authority, or {@code null} for any.
+ * @param url the URL to parse.
+ * @param result if non-null, store the type, authority and code in that object.
*/
@SuppressWarnings("fallthrough")
- private static String codeForGML(final String type, String authority, final String url, int lower,
- final DefinitionURI result)
- {
+ private static String codeForGML(final String type, String authority, final String url, int lower, final DefinitionURI result) {
Map<String, String> paths = PATHS;
if (type != null) {
final String path = paths.get(type);
@@ -527,24 +524,24 @@ public final class DefinitionURI {
* version and code are appended omitting any characters that are not valid for a Unicode identifier.
* If some information are missing in the given identifier, then this method returns {@code null}.
*
- * @param type The object type as one of the types documented in class javadoc, or {@code null}.
- * @param authority The authority as one of the values documented in class javadoc, or {@code null}.
- * @param version The code version, or {@code null}. This is the only optional information.
- * @param code The code, or {@code null}.
- * @return An identifier using the URN syntax, or {@code null} if a mandatory information is missing.
+ * @param type the object type as one of the types documented in class javadoc, or {@code null}.
+ * @param authority the authority as one of the values documented in class javadoc, or {@code null}.
+ * @param version the code version, or {@code null}. This is the only optional information.
+ * @param code the code, or {@code null}.
+ * @return an identifier using the URN syntax, or {@code null} if a mandatory information is missing.
*
* @see org.apache.sis.internal.metadata.NameMeaning#toURN(Class, String, String, String)
*/
public static String format(final String type, final String authority, final String version, final String code) {
final StringBuilder buffer = new StringBuilder(PREFIX);
- for (int p=0; p<4; p++) {
+loop: for (int p=0; ; p++) {
final String component;
switch (p) {
case 0: component = type; break;
case 1: component = authority; break;
case 2: component = version; break;
case 3: component = code; break;
- default: throw new AssertionError(p);
+ default: break loop;
}
if (!appendUnicodeIdentifier(buffer.append(SEPARATOR), '\u0000', component, ".-", false)) {
/*
@@ -565,7 +562,7 @@ public final class DefinitionURI {
* then this method formats the URI in the {@code "http://www.opengis.net/"} namespace.
* Otherwise this method formats the URI as a URN.
*
- * @return The string representation of this URI.
+ * @return the string representation of this URI.
*/
@Override
public String toString() {
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -17,9 +17,12 @@
package org.apache.sis.internal.util;
import java.util.Arrays;
+import java.math.BigInteger;
+import java.math.BigDecimal;
+import java.math.MathContext;
+import org.apache.sis.math.Fraction;
import org.apache.sis.math.MathFunctions;
import org.apache.sis.math.DecimalFunctions;
-// No BigDecimal dependency - see class javadoc
// Branch-dependent imports
import org.apache.sis.internal.jdk8.JDK8;
@@ -46,8 +49,6 @@ import org.apache.sis.internal.jdk8.JDK8
* BigDecimal decimal = new BigDecimal(dd.value).add(new BigDecimal(dd.error));
* }
*
- * We do not provide convenience method for the above in order to avoid dependency to {@code BigDecimal}.
- *
* <div class="section">Impact of availability of FMA instructions</div>
* If <cite>fused multiply-add</cite> (FMA) instruction are available in a future Java version
* (see <a href="https://issues.apache.org/jira/browse/SIS-136">SIS-136</a> on Apache SIS JIRA),
@@ -59,7 +60,7 @@ import org.apache.sis.internal.jdk8.JDK8
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.4
- * @version 0.6
+ * @version 0.8
* @module
*
* @see <a href="http://en.wikipedia.org/wiki/Double-double_%28arithmetic%29#Double-double_arithmetic">Wikipedia: Double-double arithmetic</a>
@@ -194,7 +195,7 @@ public final class DoubleDouble extends
/**
* Creates a new value initialized to the given value.
*
- * @param other The other value to copy.
+ * @param other the other value to copy.
*/
public DoubleDouble(final DoubleDouble other) {
value = other.value;
@@ -202,14 +203,44 @@ public final class DoubleDouble extends
}
/**
- * Creates a new value initialized to the given number. If the given number is an
- * instance of {@code DoubleDouble}, then its error term will be taken in account.
+ * Creates a new value initialized to the given number. If the given number is an instance of
+ * {@code DoubleDouble}, {@link BigDecimal}, {@link BigInteger} or {@link Fraction}, then the
+ * error term will be taken in account.
+ *
+ * @param otherValue the initial value.
+ */
+ public DoubleDouble(Number otherValue) {
+ if (otherValue instanceof Fraction) {
+ value = ((Fraction) otherValue).denominator;
+ inverseDivide(((Fraction) otherValue).numerator, 0);
+ } else {
+ if (otherValue instanceof BigInteger) {
+ otherValue = new BigDecimal((BigInteger) otherValue, MathContext.DECIMAL128);
+ }
+ value = otherValue.doubleValue();
+ if (otherValue instanceof DoubleDouble) {
+ error = ((DoubleDouble) otherValue).error;
+ } else if (otherValue instanceof BigDecimal) {
+ // Really need new BigDecimal(value) below, not BigDecimal.valueOf(value).
+ error = ((BigDecimal) otherValue).subtract(new BigDecimal(value), MathContext.DECIMAL64).doubleValue();
+ } else {
+ error = errorForWellKnownValue(value);
+ }
+ }
+ }
+
+ /**
+ * Returns {@code true} if the given value is one of the special cases recognized by the
+ * {@link DoubleDouble(Number)} constructor. Those special cases should rarely occur, so
+ * we do not complicate the code with optimized code paths.
*
- * @param otherValue The initial value.
+ * @param value the value to test.
+ * @return {@code true} if it is worth to convert the given value to a {@code DoubleDouble}.
+ *
+ * @since 0.8
*/
- public DoubleDouble(final Number otherValue) {
- value = otherValue.doubleValue();
- error = (otherValue instanceof DoubleDouble) ? ((DoubleDouble) otherValue).error : errorForWellKnownValue(value);
+ public static boolean shouldConvert(final Number value) {
+ return (value instanceof Fraction) || (value instanceof BigInteger) || (value instanceof BigDecimal);
}
/**
@@ -219,7 +250,7 @@ public final class DoubleDouble extends
* <b>Tip:</b> if the other value is known to be an integer or a power of 2, then invoking
* <code>{@linkplain #DoubleDouble(double, double) DoubleDouble}(otherValue, 0)</code> is more efficient.
*
- * @param value The initial value.
+ * @param value the initial value.
*/
public DoubleDouble(final double value) {
this.value = value;
@@ -230,8 +261,8 @@ public final class DoubleDouble extends
* Creates a new value initialized to the given value and error.
* It is caller's responsibility to ensure that the (value, error) pair is normalized.
*
- * @param value The initial value.
- * @param error The initial error.
+ * @param value the initial value.
+ * @param error the initial error.
*/
public DoubleDouble(final double value, final double error) {
this.value = value;
@@ -240,14 +271,28 @@ public final class DoubleDouble extends
}
/**
+ * Returns the given value as a {@code DoubleDouble}. This method returns the given instance
+ * directly if it can be safely casted to {@code DoubleDouble}.
+ *
+ * @param value the value to cast or to copy, or {@code null}.
+ * @return the value as a {@code DoubleDouble} (may be the same instance than the given argument),
+ * or {@code null} if the given value was null.
+ *
+ * @since 0.8
+ */
+ public static DoubleDouble castOrCopy(final Number value) {
+ return (value == null || value instanceof DoubleDouble) ? (DoubleDouble) value : new DoubleDouble(value);
+ }
+
+ /**
* Uses the given value verbatim, without inferring an error term for double-double arithmetic.
* We use this method when the value has been computed using transcendental functions (cosine,
* logarithm, <i>etc.</i>) in which case there is no way we can infer a meaningful error term.
*
* <p>We use this method both for readability and for making easier to search where such thing occur.</p>
*
- * @param value The value to wrap in a {@code DoubleDouble} instance.
- * @return A {@code DoubleDouble} containing exactly the given value, without error term.
+ * @param value the value to wrap in a {@code DoubleDouble} instance.
+ * @return a {@code DoubleDouble} containing exactly the given value, without error term.
*/
public static DoubleDouble verbatim(final double value) {
return new DoubleDouble(value, 0);
@@ -257,7 +302,7 @@ public final class DoubleDouble extends
* Returns a new {@code DoubleDouble} instance initialized to the conversion factor
* from radians to angular degrees.
*
- * @return An instance initialized to the 57.2957795130823208767981548141052 value.
+ * @return an instance initialized to the 57.2957795130823208767981548141052 value.
*/
public static DoubleDouble createRadiansToDegrees() {
return new DoubleDouble(57.2957795130823208767981548141052, -1.9878495670576283E-15);
@@ -267,7 +312,7 @@ public final class DoubleDouble extends
* Returns a new {@code DoubleDouble} instance initialized to the conversion factor
* from angular degrees to radians.
*
- * @return An instance initialized to the 0.01745329251994329576923690768488613 value.
+ * @return an instance initialized to the 0.01745329251994329576923690768488613 value.
*/
public static DoubleDouble createDegreesToRadians() {
return new DoubleDouble(0.01745329251994329576923690768488613, 2.9486522708701687E-19);
@@ -277,7 +322,7 @@ public final class DoubleDouble extends
* Returns a new {@code DoubleDouble} instance initialized to the conversion factor
* from arc-seconds to radians.
*
- * @return An instance initialized to the 0.000004848136811095359935899141023579480 value.
+ * @return an instance initialized to the 0.000004848136811095359935899141023579480 value.
*/
public static DoubleDouble createSecondsToRadians() {
return new DoubleDouble(0.000004848136811095359935899141023579480, 9.320078015422868E-23);
@@ -303,8 +348,8 @@ public final class DoubleDouble extends
* the intend was to provide the "feet to metres" conversion factor and complete the double-double instance
* accordingly.
*
- * @param value The value for which to get this error.
- * @return The error for the given value, or 0 if unknown. In the later case,
+ * @param value the value for which to get this error.
+ * @return the error for the given value, or 0 if unknown. In the later case,
* the base 2 representation of the given value is assumed to be accurate enough.
*/
public static double errorForWellKnownValue(final double value) {
@@ -337,7 +382,7 @@ public final class DoubleDouble extends
/**
* Sets this {@code DoubleDouble} to the same value than the given instance.
*
- * @param other The instance to copy.
+ * @param other the instance to copy.
*/
public void setFrom(final DoubleDouble other) {
value = other.value;
@@ -353,9 +398,9 @@ public final class DoubleDouble extends
* error = array[index + errorOffset];
* }
*
- * @param array The array from which to get the value and error.
- * @param index Index of the value in the given array.
- * @param errorOffset Offset to add to {@code index} in order to get the index of the error in the given array.
+ * @param array the array from which to get the value and error.
+ * @param index index of the value in the given array.
+ * @param errorOffset offset to add to {@code index} in order to get the index of the error in the given array.
*/
public void setFrom(final double[] array, final int index, final int errorOffset) {
value = array[index];
@@ -377,8 +422,8 @@ public final class DoubleDouble extends
*
* <p>Source: [Hida & al.] page 4 algorithm 3, itself reproduced from [Shewchuk] page 312.</p>
*
- * @param a The first number to add.
- * @param b The second number to add, which must be smaller than {@code a}.
+ * @param a the first number to add.
+ * @param b the second number to add, which must be smaller than {@code a}.
*/
public void setToQuickSum(final double a, final double b) {
value = a + b;
@@ -391,8 +436,8 @@ public final class DoubleDouble extends
*
* <p>Source: [Hida & al.] page 4 algorithm 4, itself reproduced from [Shewchuk] page 314.</p>
*
- * @param a The first number to add.
- * @param b The second number to add.
+ * @param a the first number to add.
+ * @param b the second number to add.
*/
public void setToSum(final double a, final double b) {
value = a + b;
@@ -407,8 +452,8 @@ public final class DoubleDouble extends
*
* <p>Source: [Hida & al.] page 4 algorithm 6, itself reproduced from [Shewchuk] page 326.</p>
*
- * @param a The first number to multiply.
- * @param b The second number to multiply.
+ * @param a the first number to multiply.
+ * @param b the second number to multiply.
*/
public void setToProduct(final double a, final double b) {
value = a * b;
@@ -431,9 +476,9 @@ public final class DoubleDouble extends
* array[index + errorOffset] = error;
* }
*
- * @param array The array where to store the value and error.
- * @param index Index of the value in the given array.
- * @param errorOffset Offset to add to {@code index} in order to get the index of the error in the given array.
+ * @param array the array where to store the value and error.
+ * @param index index of the value in the given array.
+ * @param errorOffset offset to add to {@code index} in order to get the index of the error in the given array.
*/
public void storeTo(final double[] array, final int index, final int errorOffset) {
array[index] = value;
@@ -443,10 +488,10 @@ public final class DoubleDouble extends
/**
* Swaps two double-double values in the given array.
*
- * @param array The array where to swap the values and errors.
- * @param i0 Index of the first value to swap.
- * @param i1 Index of the second value to swap.
- * @param errorOffset Offset to add to the indices in order to get the error indices in the given array.
+ * @param array the array where to swap the values and errors.
+ * @param i0 index of the first value to swap.
+ * @param i1 index of the second value to swap.
+ * @param errorOffset offset to add to the indices in order to get the error indices in the given array.
*
* @see org.apache.sis.util.ArraysExt#swap(double[], int, int)
*/
@@ -475,7 +520,7 @@ public final class DoubleDouble extends
* add(other.value, other.error);
* }
*
- * @param other The other value to add to this {@code DoubleDouble}.
+ * @param other the other value to add to this {@code DoubleDouble}.
*/
public void add(final DoubleDouble other) {
add(other.value, other.error);
@@ -483,13 +528,15 @@ public final class DoubleDouble extends
/**
* Adds a {@code Number} value to this {@code DoubleDouble}. If the given number is an instance
- * of {@code DoubleDouble}, then its error term will be taken in account.
+ * of {@code DoubleDouble} or {@link Fraction}, then the error term will be taken in account.
*
- * @param other The other value to add to this {@code DoubleDouble}.
+ * @param other the other value to add to this {@code DoubleDouble}.
*/
public void add(final Number other) {
if (other instanceof DoubleDouble) {
add((DoubleDouble) other);
+ } else if (shouldConvert(other)) {
+ add(new DoubleDouble(other));
} else {
add(other.doubleValue());
}
@@ -506,7 +553,7 @@ public final class DoubleDouble extends
* <b>Tip:</b> if the other value is known to be an integer or a power of 2, then invoking
* <code>{@linkplain #add(double, double) add}(otherValue, 0)</code> is more efficient.
*
- * @param otherValue The other value to add to this {@code DoubleDouble}.
+ * @param otherValue the other value to add to this {@code DoubleDouble}.
*/
public void add(final double otherValue) {
add(otherValue, errorForWellKnownValue(otherValue));
@@ -537,8 +584,8 @@ public final class DoubleDouble extends
* setToQuickSum(value, error);
* }
*
- * @param otherValue The other value to add to this {@code DoubleDouble}.
- * @param otherError The error of the other value to add to this {@code DoubleDouble}.
+ * @param otherValue the other value to add to this {@code DoubleDouble}.
+ * @param otherError the error of the other value to add to this {@code DoubleDouble}.
*/
public void add(final double otherValue, final double otherError) {
// Inline expansion of the code in above javadoc.
@@ -571,9 +618,9 @@ public final class DoubleDouble extends
* add(array[index], array[index + errorOffset]);
* }
*
- * @param array The array from which to get the value and error.
- * @param index Index of the value in the given array.
- * @param errorOffset Offset to add to {@code index} in order to get the index of the error in the given array.
+ * @param array the array from which to get the value and error.
+ * @param index index of the value in the given array.
+ * @param errorOffset offset to add to {@code index} in order to get the index of the error in the given array.
*/
public void add(final double[] array, final int index, final int errorOffset) {
add(array[index], array[index + errorOffset]);
@@ -587,7 +634,7 @@ public final class DoubleDouble extends
* subtract(other.value, other.error);
* }
*
- * @param other The other value to subtract from this value.
+ * @param other the other value to subtract from this value.
*/
public void subtract(final DoubleDouble other) {
subtract(other.value, other.error);
@@ -595,13 +642,15 @@ public final class DoubleDouble extends
/**
* Subtracts a {@code Number} from this {@code DoubleDouble}. If the given number is an instance
- * of {@code DoubleDouble}, then its error term will be taken in account.
+ * of {@code DoubleDouble} or {@link Fraction}, then the error term will be taken in account.
*
- * @param other The other value to subtract from this {@code DoubleDouble}.
+ * @param other the other value to subtract from this {@code DoubleDouble}.
*/
public void subtract(final Number other) {
if (other instanceof DoubleDouble) {
subtract((DoubleDouble) other);
+ } else if (shouldConvert(other)) {
+ subtract(new DoubleDouble(other));
} else {
subtract(other.doubleValue());
}
@@ -618,7 +667,7 @@ public final class DoubleDouble extends
* <b>Tip:</b> if the other value is known to be an integer or a power of 2, then invoking
* <code>{@linkplain #subtract(double, double) subtract}(otherValue, 0)</code> is more efficient.
*
- * @param otherValue The other value to subtract from this {@code DoubleDouble}.
+ * @param otherValue the other value to subtract from this {@code DoubleDouble}.
*/
public void subtract(final double otherValue) {
subtract(otherValue, errorForWellKnownValue(otherValue));
@@ -628,8 +677,8 @@ public final class DoubleDouble extends
* Subtracts an other double-double value from this {@code DoubleDouble}.
* The result is stored in this instance.
*
- * @param otherValue The other value to subtract from this {@code DoubleDouble}.
- * @param otherError The error of the other value to subtract from this {@code DoubleDouble}.
+ * @param otherValue the other value to subtract from this {@code DoubleDouble}.
+ * @param otherError the error of the other value to subtract from this {@code DoubleDouble}.
*/
public void subtract(final double otherValue, final double otherError) {
add(-otherValue, -otherError);
@@ -643,9 +692,9 @@ public final class DoubleDouble extends
* subtract(array[index], array[index + errorOffset]);
* }
*
- * @param array The array from which to get the value and error.
- * @param index Index of the value in the given array.
- * @param errorOffset Offset to add to {@code index} in order to get the index of the error in the given array.
+ * @param array the array from which to get the value and error.
+ * @param index index of the value in the given array.
+ * @param errorOffset offset to add to {@code index} in order to get the index of the error in the given array.
*/
public void subtract(final double[] array, final int index, final int errorOffset) {
subtract(array[index], array[index + errorOffset]);
@@ -659,7 +708,7 @@ public final class DoubleDouble extends
* multiply(other.value, other.error);
* }
*
- * @param other The other value to multiply by this value.
+ * @param other the other value to multiply by this value.
*/
public void multiply(final DoubleDouble other) {
multiply(other.value, other.error);
@@ -667,13 +716,15 @@ public final class DoubleDouble extends
/**
* Multiplies this {@code DoubleDouble} by a {@code Number}. If the given number is an instance
- * of {@code DoubleDouble}, then its error term will be taken in account.
+ * of {@code DoubleDouble} or {@link Fraction}, then the error term will be taken in account.
*
- * @param other The other value to multiply by this {@code DoubleDouble}.
+ * @param other the other value to multiply by this {@code DoubleDouble}.
*/
public void multiply(final Number other) {
if (other instanceof DoubleDouble) {
multiply((DoubleDouble) other);
+ } else if (shouldConvert(other)) {
+ multiply(new DoubleDouble(other));
} else {
multiply(other.doubleValue());
}
@@ -690,7 +741,7 @@ public final class DoubleDouble extends
* <b>Tip:</b> if the other value is known to be an integer or a power of 2, then invoking
* <code>{@linkplain #multiply(double, double) multiply}(otherValue, 0)</code> is more efficient.
*
- * @param otherValue The other value to multiply by this {@code DoubleDouble}.
+ * @param otherValue the other value to multiply by this {@code DoubleDouble}.
*/
public void multiply(final double otherValue) {
multiply(otherValue, errorForWellKnownValue(otherValue));
@@ -724,8 +775,8 @@ public final class DoubleDouble extends
* setToQuickSum(value, error);
* }
*
- * @param otherValue The other value by which to multiply this {@code DoubleDouble}.
- * @param otherError The error of the other value by which to multiply this {@code DoubleDouble}.
+ * @param otherValue the other value by which to multiply this {@code DoubleDouble}.
+ * @param otherError the error of the other value by which to multiply this {@code DoubleDouble}.
*/
public void multiply(final double otherValue, final double otherError) {
final double thisValue = this.value;
@@ -744,9 +795,9 @@ public final class DoubleDouble extends
* multiply(array[index], array[index + errorOffset]);
* }
*
- * @param array The array from which to get the value and error.
- * @param index Index of the value in the given array.
- * @param errorOffset Offset to add to {@code index} in order to get the index of the error in the given array.
+ * @param array the array from which to get the value and error.
+ * @param index index of the value in the given array.
+ * @param errorOffset offset to add to {@code index} in order to get the index of the error in the given array.
*/
public void multiply(final double[] array, final int index, final int errorOffset) {
multiply(array[index], array[index + errorOffset]);
@@ -760,7 +811,7 @@ public final class DoubleDouble extends
* divide(other.value, other.error);
* }
*
- * @param other The other value to by which to divide this value.
+ * @param other the other value to by which to divide this value.
*/
public void divide(final DoubleDouble other) {
divide(other.value, other.error);
@@ -768,13 +819,15 @@ public final class DoubleDouble extends
/**
* Divides this {@code DoubleDouble} by a {@code Number}. If the given number is an instance
- * of {@code DoubleDouble}, then its error term will be taken in account.
+ * of {@code DoubleDouble} or {@link Fraction}, then the error term will be taken in account.
*
- * @param other The other value by which to divide this {@code DoubleDouble}.
+ * @param other the other value by which to divide this {@code DoubleDouble}.
*/
public void divide(final Number other) {
if (other instanceof DoubleDouble) {
divide((DoubleDouble) other);
+ } else if (shouldConvert(other)) {
+ divide(new DoubleDouble(other));
} else {
divide(other.doubleValue());
}
@@ -791,7 +844,7 @@ public final class DoubleDouble extends
* <b>Tip:</b> if the other value is known to be an integer or a power of 2, then invoking
* <code>{@linkplain #divide(double, double) divide}(otherValue, 0)</code> is more efficient.
*
- * @param otherValue The other value by which to divide this {@code DoubleDouble}.
+ * @param otherValue the other value by which to divide this {@code DoubleDouble}.
*/
public void divide(final double otherValue) {
divide(otherValue, errorForWellKnownValue(otherValue));
@@ -801,8 +854,8 @@ public final class DoubleDouble extends
* Divides this {@code DoubleDouble} by an other double-double value.
* The result is stored in this instance.
*
- * @param denominatorValue The other value by which to divide this {@code DoubleDouble}.
- * @param denominatorError The error of the other value by which to divide this {@code DoubleDouble}.
+ * @param denominatorValue the other value by which to divide this {@code DoubleDouble}.
+ * @param denominatorError the error of the other value by which to divide this {@code DoubleDouble}.
*/
public void divide(final double denominatorValue, final double denominatorError) {
if (DISABLED) {
@@ -825,9 +878,9 @@ public final class DoubleDouble extends
* divide(array[index], array[index + errorOffset]);
* }
*
- * @param array The array from which to get the value and error.
- * @param index Index of the value in the given array.
- * @param errorOffset Offset to add to {@code index} in order to get the index of the error in the given array.
+ * @param array the array from which to get the value and error.
+ * @param index index of the value in the given array.
+ * @param errorOffset offset to add to {@code index} in order to get the index of the error in the given array.
*/
public void divide(final double[] array, final int index, final int errorOffset) {
divide(array[index], array[index + errorOffset]);
@@ -841,21 +894,23 @@ public final class DoubleDouble extends
* inverseDivide(other.value, other.error);
* }
*
- * @param other The other value to divide by this value.
+ * @param other the other value to divide by this value.
*/
public void inverseDivide(final DoubleDouble other) {
inverseDivide(other.value, other.error);
}
/**
- * Divides the given {@code Number} value by this {@code DoubleDouble}. If the given number
- * is an instance of {@code DoubleDouble}, then its error term will be taken in account.
+ * Divides the given {@code Number} value by this {@code DoubleDouble}. If the given number is an instance
+ * of {@code DoubleDouble} or {@link Fraction}, then the error term will be taken in account.
*
- * @param other The other value to divide by this {@code DoubleDouble}.
+ * @param other the other value to divide by this {@code DoubleDouble}.
*/
public void inverseDivide(final Number other) {
if (other instanceof DoubleDouble) {
inverseDivide((DoubleDouble) other);
+ } else if (shouldConvert(other)) {
+ inverseDivide(new DoubleDouble(other));
} else {
inverseDivide(other.doubleValue());
}
@@ -872,7 +927,7 @@ public final class DoubleDouble extends
* <b>Tip:</b> if the other value is known to be an integer or a power of 2, then invoking
* <code>{@linkplain #inverseDivide(double, double) inverseDivide}(otherValue, 0)</code> is more efficient.
*
- * @param numeratorValue The other value to divide by this {@code DoubleDouble}.
+ * @param numeratorValue the other value to divide by this {@code DoubleDouble}.
*/
public void inverseDivide(final double numeratorValue) {
inverseDivide(numeratorValue, errorForWellKnownValue(numeratorValue));
@@ -891,8 +946,8 @@ public final class DoubleDouble extends
*
* <blockquote>remainder = a - b * (a.value / b.value)</blockquote>
*
- * @param numeratorValue The other value to divide by this {@code DoubleDouble}.
- * @param numeratorError The error of the other value to divide by this {@code DoubleDouble}.
+ * @param numeratorValue the other value to divide by this {@code DoubleDouble}.
+ * @param numeratorError the error of the other value to divide by this {@code DoubleDouble}.
*/
public void inverseDivide(final double numeratorValue, final double numeratorError) {
if (DISABLED) {
@@ -929,9 +984,9 @@ public final class DoubleDouble extends
* inverseDivide(array[index], array[index + errorOffset]);
* }
*
- * @param array The array from which to get the value and error.
- * @param index Index of the value in the given array.
- * @param errorOffset Offset to add to {@code index} in order to get the index of the error in the given array.
+ * @param array the array from which to get the value and error.
+ * @param index index of the value in the given array.
+ * @param errorOffset offset to add to {@code index} in order to get the index of the error in the given array.
*/
public void inverseDivide(final double[] array, final int index, final int errorOffset) {
inverseDivide(array[index], array[index + errorOffset]);
@@ -1018,7 +1073,7 @@ public final class DoubleDouble extends
/**
* Returns a hash code value for this number.
*
- * @return A hash code value.
+ * @return a hash code value.
*/
@Override
public int hashCode() {
@@ -1028,7 +1083,7 @@ public final class DoubleDouble extends
/**
* Compares this number with the given object for equality.
*
- * @param obj The other object to compare with this number.
+ * @param obj the other object to compare with this number.
* @return {@code true} if both object are equal.
*/
@Override
@@ -1047,7 +1102,7 @@ public final class DoubleDouble extends
* Returns a string representation of this number for debugging purpose.
* The returned string does not need to contains all digits that this {@code DoubleDouble} can handle.
*
- * @return A string representation of this number.
+ * @return a string representation of this number.
*/
@Override
public String toString() {
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/XPaths.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/XPaths.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/XPaths.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/XPaths.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -46,9 +46,9 @@ public final class XPaths extends Static
* {@code "http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])"})</li>
* </ul>
*
- * @param type The object type.
- * @param url The URL to parse.
- * @return The reference, or {@code null} if none.
+ * @param type the object type.
+ * @param url the URL to parse.
+ * @return the reference, or {@code null} if none.
*/
public static String xpointer(final String type, final String url) {
if (type.equals("uom")) {
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -29,14 +29,14 @@ import java.text.ParsePosition;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import javax.measure.unit.Unit;
-import javax.measure.unit.UnitFormat;
+import javax.measure.Unit;
import org.opengis.referencing.IdentifiedObject;
import org.apache.sis.measure.Angle;
import org.apache.sis.measure.AngleFormat;
import org.apache.sis.measure.Range;
import org.apache.sis.measure.RangeFormat;
+import org.apache.sis.measure.UnitFormat;
import org.apache.sis.util.Localized;
import org.apache.sis.util.ArraysExt;
import org.apache.sis.util.ArgumentChecks;
@@ -77,7 +77,7 @@ import static org.apache.sis.internal.ut
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.3
+ * @version 0.8
* @module
*/
public abstract class CompoundFormat<T> extends Format implements Localized {
@@ -444,7 +444,7 @@ public abstract class CompoundFormat<T>
} else if (valueType == Angle.class) {
return AngleFormat.getInstance(locale);
} else if (valueType == Unit.class) {
- return UnitFormat.getInstance(locale);
+ return new UnitFormat(locale);
} else if (valueType == Range.class) {
return new RangeFormat(locale);
} else if (valueType == Class.class) {
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -105,7 +105,7 @@ public final class DecimalFunctions exte
* public {@link MathFunctions#pow10(int)} method, defined here in order to allow the
* JVM to initialize the {@link #POW10} table only when first needed.
*
- * @param x The exponent.
+ * @param x the exponent.
* @return 10 raised to the given exponent.
*/
static double pow10(int x) {
@@ -146,7 +146,7 @@ public final class DecimalFunctions exte
*/
final int e = Math.getExponent(value) - Numerics.SIGNIFICAND_SIZE_OF_FLOAT;
if (e >= 0) {
- return value; // Integer, infinity or NaN.
+ return value; // Integer, infinity or NaN.
}
final int m = Numerics.getSignificand(value);
assert Math.scalb((float) m, e) == Math.abs(value) : value;
@@ -162,9 +162,9 @@ public final class DecimalFunctions exte
*
* Note: the conversation factor c is also equals to 1 ULP converted to the units of (m × c).
*/
- final int e10 = -Numerics.toExp10(e); // Range: [0 … 45] inclusive.
- final double c = Math.scalb(pow10(e10), e); // Range: (1 … 10) exclusive.
- final double mc = m * c; // Only integer part is meaningful.
+ final int e10 = -Numerics.toExp10(e); // Range: [0 … 45] inclusive.
+ final double c = Math.scalb(pow10(e10), e); // Range: (1 … 10) exclusive.
+ final double mc = m * c; // Only integer part is meaningful.
/*
* First, presume that our representation in base 10 has one extranous digit, so we will round
* to the tens instead of unities. If the difference appears to not be smaller than half a ULP,
@@ -212,8 +212,8 @@ public final class DecimalFunctions exte
* threshold, this method returns {@code NaN} because of insufficient algorithm accuracy.
* This limitation may change in any future SIS version if we find a better algorithm.
*
- * @param value The value for which to get the delta compared to its base 10 representation.
- * @return The delta that would need to be added to the given {@code double} value for getting a result
+ * @param value the value for which to get the delta compared to its base 10 representation.
+ * @return the delta that would need to be added to the given {@code double} value for getting a result
* closer to its base 10 representation, or {@link Double#NaN NaN} if it can not be computed.
*/
public static double deltaForDoubleToDecimal(final double value) {
@@ -225,18 +225,18 @@ public final class DecimalFunctions exte
*/
final int e = Math.getExponent(value) - SIGNIFICAND_SIZE;
if (e >= 0) {
- return 0; // Integer, infinity or NaN.
+ return 0; // Integer, infinity or NaN.
}
- if (e < -24 - SIGNIFICAND_SIZE) { // 2.9802322E-8 threshold found empirically.
- return (e == -1075) ? 0 : Double.NaN; // Returns 0 for the 0 value, NaN for all others.
+ if (e < -24 - SIGNIFICAND_SIZE) { // 2.9802322E-8 threshold found empirically.
+ return (e == -1075) ? 0 : Double.NaN; // Returns 0 for the 0 value, NaN for all others.
}
final long m = Numerics.getSignificand(value);
assert Math.scalb((double) m, e) == Math.abs(value) : value;
- final int e10 = -Numerics.toExp10(e); // Range: [0 … 324] inclusive.
+ final int e10 = -Numerics.toExp10(e); // Range: [0 … 324] inclusive.
/*
* If we were continuing with the same strategy than in floatToDouble(float), we would compute:
*
- * c = Math.scalb(pow10(e10), e); // Range: (1 … 10) exclusive.
+ * c = Math.scalb(pow10(e10), e); // Range: (1 … 10) exclusive.
*
* Unfortunately this would require a floating point type with twice the accuracy of 'double',
* which we don't have. Instead, we will apply a trick with integer arithmetic. But before to
@@ -249,8 +249,8 @@ public final class DecimalFunctions exte
* will be equals or greater than 2^52. At that threshold, 'double' values can not have
* fraction digits.
*/
- final int PRECISION = SIGNIFICAND_SIZE + 4; // Number of bits to use for scaling to integers.
- double cs = Math.scalb(pow10(e10 - 1), e + PRECISION); // Range: (0.1 × 2^56 … 2^56) exclusive.
+ final int PRECISION = SIGNIFICAND_SIZE + 4; // Number of bits to use for scaling to integers.
+ double cs = Math.scalb(pow10(e10 - 1), e + PRECISION); // Range: (0.1 × 2^56 … 2^56) exclusive.
/*
* This is where magic happen: the following multiplication overflow (we would need a 128 bits integer
* for representing it), but we don't care because we are interrested only in the fraction digits (the
@@ -269,8 +269,8 @@ public final class DecimalFunctions exte
* The above digit is guaranteed to be in the [0 … 9] range. We will wraparound in the [-5 … 4] range
* because the delta must be no more than ±0.5 ULP of the 'value' argument.
*/
- if (mc >= (5L << PRECISION) / 10) { // The 0.5 × 2^56 threshold.
- mc -= (1L << PRECISION); // Shift [5 … 9] digits to [-5 … -1].
+ if (mc >= (5L << PRECISION) / 10) { // The 0.5 × 2^56 threshold.
+ mc -= (1L << PRECISION); // Shift [5 … 9] digits to [-5 … -1].
}
/*
* At this point, 'mc' is less than 0.5 ULP if the last decimal digits were zero.
@@ -283,8 +283,8 @@ public final class DecimalFunctions exte
* we care only about the remainder after we removed the effet of that last digit.
*/
if (Math.abs(mc) >= ci/2) {
- mc %= (1L << PRECISION) / 10; // Remove the effect of last decimal digit.
- if (mc >= 0) { // Check if changing the sign would make it smaller.
+ mc %= (1L << PRECISION) / 10; // Remove the effect of last decimal digit.
+ if (mc >= 0) { // Check if changing the sign would make it smaller.
if (mc >= (1L << PRECISION) / 20) {
mc -= (1L << PRECISION) / 10;
}
@@ -351,11 +351,11 @@ public final class DecimalFunctions exte
* -{@linkplain Math#floor(double) floor}({@linkplain Math#log10(double) log10}(accuracy))</code>
* except for the 0, {@code NaN}, infinities and {@code 0.…95} special cases.
*
- * @param accuracy The desired accuracy of numbers to format in base 10.
+ * @param accuracy the desired accuracy of numbers to format in base 10.
* @param strict {@code true} for checking the {@code 0.…95} special case.
* If {@code false}, then the difference between adjacent formatted numbers is not
* guaranteed to be smaller than {@code accuracy} in every cases.
- * @return Number of fraction digits needed for formatting numbers with the given accuracy.
+ * @return number of fraction digits needed for formatting numbers with the given accuracy.
* May be negative.
*
* @see java.text.NumberFormat#setMaximumFractionDigits(int)
@@ -364,7 +364,7 @@ public final class DecimalFunctions exte
accuracy = Math.abs(accuracy);
int i = MathFunctions.getExponent(accuracy);
if (i == Double.MAX_EXPONENT + 1) {
- return 0; // NaN or infinities.
+ return 0; // NaN or infinities.
}
i = Numerics.toExp10(i);
if (accuracy >= pow10(i+1)) {
@@ -374,7 +374,7 @@ public final class DecimalFunctions exte
if (strict) {
double scale = pow10(i);
while ((accuracy *= scale) >= 9.5) {
- i++; // The 0.…95 special case.
+ i++; // The 0.…95 special case.
accuracy -= Math.floor(accuracy);
scale = 10;
}
@@ -409,8 +409,8 @@ public final class DecimalFunctions exte
* This method is useful with {@link java.text.NumberFormat} for formatting all significant digits of a
* {@code double} value, padding with trailing zeros if necessary, but no more than necessary.</div>
*
- * @param value The value for which to get the number of significant fraction digits.
- * @return The number of significant fraction digits (may be negative), or 0 if {@code value} is NaN or infinity.
+ * @param value the value for which to get the number of significant fraction digits.
+ * @return the number of significant fraction digits (may be negative), or 0 if {@code value} is NaN or infinity.
*
* @see java.text.NumberFormat#setMinimumFractionDigits(int)
*/
@@ -423,7 +423,7 @@ public final class DecimalFunctions exte
* normal numbers (in order to reproduce the Math.ulp behavior).
*/
final int exponent = Math.getExponent(value);
- if (exponent <= Double.MAX_EXPONENT) { // Exclude NaN and ±∞ cases.
+ if (exponent <= Double.MAX_EXPONENT) { // Exclude NaN and ±∞ cases.
return -Numerics.toExp10(exponent - SIGNIFICAND_SIZE);
}
return 0;
@@ -459,9 +459,9 @@ public final class DecimalFunctions exte
* </ul>
* </div>
*
- * @param value The value for which to get the number of significant fraction fraction digits minus rounding error.
- * @param uncertainDigits Number of trailing fraction digits which may be rounding error artefacts.
- * @return Suggested number of significant digits (may be negative), or 0 if {@code value} is NaN or infinity.
+ * @param value the value for which to get the number of significant fraction fraction digits minus rounding error.
+ * @param uncertainDigits number of trailing fraction digits which may be rounding error artefacts.
+ * @return suggested number of significant digits (may be negative), or 0 if {@code value} is NaN or infinity.
*/
public static int fractionDigitsForValue(double value, final int uncertainDigits) {
ArgumentChecks.ensurePositive("uncertainDigits", uncertainDigits);
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -179,7 +179,7 @@ public class AngleFormat extends Format
* a string, this value may be specified to the {@link FieldPosition} constructor in order to
* get the bounding index where fraction digits have been written.
*/
- private static final int FRACTION_FIELD = 3; // Not yet implemented.
+ private static final int FRACTION_FIELD = 3; // Not yet implemented.
/**
* Constant for hemisphere field. When formatting a string, this value may be specified to the
@@ -347,13 +347,11 @@ public class AngleFormat extends Format
/**
* A temporary variable which may be set to the character iterator for which the
- * attributes need to be set. IF non-null, then this is actually an instance of
- * {@link FormattedCharacterIterator}. But we use the interface here for avoiding
- * too early class loading.
+ * attributes need to be set.
*
* @see #formatToCharacterIterator(Object)
*/
- private transient AttributedCharacterIterator characterIterator;
+ private transient FormattedCharacterIterator characterIterator;
/**
* Returns the number format, created when first needed.
@@ -378,7 +376,7 @@ public class AngleFormat extends Format
/**
* Constructs a new {@code AngleFormat} for the default pattern and the current default locale.
*
- * @return An angle format for the current default locale.
+ * @return an angle format for the current default locale.
*/
public static AngleFormat getInstance() {
return new AngleFormat();
@@ -387,8 +385,8 @@ public class AngleFormat extends Format
/**
* Constructs a new {@code AngleFormat} for the default pattern and the specified locale.
*
- * @param locale The locale to use.
- * @return An angle format for the given locale.
+ * @param locale the locale to use.
+ * @return an angle format for the given locale.
*/
public static AngleFormat getInstance(final Locale locale) {
return new AngleFormat(locale);
@@ -404,7 +402,7 @@ public class AngleFormat extends Format
/**
* Constructs a new {@code AngleFormat} for the default pattern and the specified locale.
*
- * @param locale The locale to use.
+ * @param locale the locale to use.
*/
@SuppressWarnings("PointlessBitwiseExpression") // We rely on the compiler for simplifying the expression.
public AngleFormat(final Locale locale) {
@@ -424,9 +422,9 @@ public class AngleFormat extends Format
/**
* Constructs a new {@code AngleFormat} for the specified pattern and the current default locale.
*
- * @param pattern Pattern to use for parsing and formatting angles.
+ * @param pattern the pattern to use for parsing and formatting angles.
* See class description for an explanation of pattern syntax.
- * @throws IllegalArgumentException If the specified pattern is illegal.
+ * @throws IllegalArgumentException if the specified pattern is illegal.
*/
public AngleFormat(final String pattern) throws IllegalArgumentException {
this(pattern, Locale.getDefault(Locale.Category.FORMAT));
@@ -435,10 +433,10 @@ public class AngleFormat extends Format
/**
* Constructs a new {@code AngleFormat} using the specified pattern and locale.
*
- * @param pattern Pattern to use for parsing and formatting angles.
+ * @param pattern the pattern to use for parsing and formatting angles.
* See class description for an explanation of pattern syntax.
* @param locale Locale to use.
- * @throws IllegalArgumentException If the specified pattern is illegal.
+ * @throws IllegalArgumentException if the specified pattern is illegal.
*/
public AngleFormat(final String pattern, final Locale locale) throws IllegalArgumentException {
ArgumentChecks.ensureNonEmpty("pattern", pattern);
@@ -451,8 +449,8 @@ public class AngleFormat extends Format
* Sets the pattern to use for parsing and formatting angles.
* See class description for a description of pattern syntax.
*
- * @param pattern Pattern to use for parsing and formatting angle.
- * @throws IllegalArgumentException If the specified pattern is not legal.
+ * @param pattern the pattern to use for parsing and formatting angle.
+ * @throws IllegalArgumentException if the specified pattern is not legal.
*
* @see #setMinimumFractionDigits(int)
* @see #setMaximumFractionDigits(int)
@@ -478,9 +476,9 @@ public class AngleFormat extends Format
* Actual implementation of {@link #applyPattern(String)}, as a private method for use by the constructor.
* All fields related to the pattern shall be set to 0 or null before this method call.
*
- * @param symbols An array of code points containing the reserved symbols as upper-case letters.
- * This is always the {@link #SYMBOLS} array, unless we apply localized patterns.
- * @param decimalSeparator The code point which represent decimal separator in the pattern.
+ * @param symbols an array of code points containing the reserved symbols as upper-case letters.
+ * This is always the {@link #SYMBOLS} array, unless we apply localized patterns.
+ * @param decimalSeparator the code point which represent decimal separator in the pattern.
*/
@SuppressWarnings("fallthrough")
private void applyPattern(final String pattern, final int[] symbols, final int decimalSeparator) {
@@ -612,9 +610,9 @@ public class AngleFormat extends Format
/**
* Returns the field index for the given upper case character, or -1 if none.
*
- * @param symbols An array of code points containing the reserved symbols as upper-case letters.
- * @param c The symbol to search, as an upper-case character (code point actually).
- * @return The index of the given character, or -1 if not found.
+ * @param symbols an array of code points containing the reserved symbols as upper-case letters.
+ * @param c the symbol to search, as an upper-case character (code point actually).
+ * @return the index of the given character, or -1 if not found.
*/
private static int fieldForSymbol(final int[] symbols, final int c) {
for (int field=DEGREES_FIELD; field<=FRACTION_FIELD; field++) {
@@ -637,7 +635,7 @@ public class AngleFormat extends Format
* Returns the pattern used for parsing and formatting angles.
* See class description for an explanation of how patterns work.
*
- * @return The formatting pattern.
+ * @return the formatting pattern.
*
* @see #getMinimumFractionDigits()
* @see #getMaximumFractionDigits()
@@ -650,9 +648,9 @@ public class AngleFormat extends Format
* Actual implementation of {@link #toPattern()} and {@code toLocalizedPattern()}
* (the later method may be provided in a future SIS version).
*
- * @param symbols An array of code points containing the reserved symbols as upper-case letters.
- * This is always the {@link #SYMBOLS} array, unless we apply localized patterns.
- * @param decimalSeparator The code point which represent decimal separator in the pattern.
+ * @param symbols an array of code points containing the reserved symbols as upper-case letters.
+ * this is always the {@link #SYMBOLS} array, unless we apply localized patterns.
+ * @param decimalSeparator the code point which represent decimal separator in the pattern.
*/
private String toPattern(final int[] symbols, final int decimalSeparator) {
int symbol = 0;
@@ -730,7 +728,7 @@ public class AngleFormat extends Format
* This value can be set by the repetition of {@code 'd'}, {@code 'm'} or {@code 's'} symbol
* in the pattern.
*
- * @return The minimum number of digits allowed in the fraction portion.
+ * @return the minimum number of digits allowed in the fraction portion.
*
* @see DecimalFormat#getMinimumFractionDigits()
*/
@@ -743,7 +741,7 @@ public class AngleFormat extends Format
* If the given value is greater than the {@linkplain #getMaximumFractionDigits() maximum
* number of fraction digits}, then that maximum number will be set to the given value too.
*
- * @param count The minimum number of digits allowed in the fraction portion.
+ * @param count the minimum number of digits allowed in the fraction portion.
*
* @see DecimalFormat#setMinimumFractionDigits(int)
*/
@@ -763,7 +761,7 @@ public class AngleFormat extends Format
* Returns the maximum number of digits allowed in the fraction portion of the last field.
* This value can be set by the repetition of {@code '#'} symbol in the pattern.
*
- * @return The maximum number of digits allowed in the fraction portion.
+ * @return the maximum number of digits allowed in the fraction portion.
*
* @see DecimalFormat#getMaximumFractionDigits()
*/
@@ -776,7 +774,7 @@ public class AngleFormat extends Format
* If the given value is smaller than the {@linkplain #getMinimumFractionDigits() minimum
* number of fraction digits}, then that minimum number will be set to the given value too.
*
- * @param count The maximum number of digits allowed in the fraction portion.
+ * @param count the maximum number of digits allowed in the fraction portion.
*
* @see DecimalFormat#setMaximumFractionDigits(int)
*/
@@ -812,7 +810,7 @@ public class AngleFormat extends Format
* <p>This method does not take into account the space needed for the hemisphere symbol when
* formatting {@link Latitude} or {@link Longitude} objects.</p>
*
- * @param width The maximum total width of formatted angle.
+ * @param width the maximum total width of formatted angle.
*/
@SuppressWarnings("fallthrough")
public void setMaximumWidth(int width) {
@@ -842,8 +840,8 @@ public class AngleFormat extends Format
*/
if (width < 0) {
switch (field) {
- default: width += (degreesFieldWidth-1); degreesFieldWidth = 1; // Fall through
- case MINUTES_FIELD: minutesSuffix = null; minutesFieldWidth = 0; // Fall through
+ default: width += (degreesFieldWidth-1); degreesFieldWidth = 1; // Fall through
+ case MINUTES_FIELD: minutesSuffix = null; minutesFieldWidth = 0; // Fall through
case SECONDS_FIELD: secondsSuffix = null; secondsFieldWidth = 0;
}
if (field >= MINUTES_FIELD) {
@@ -882,8 +880,8 @@ public class AngleFormat extends Format
* Formats an angle. The angle will be formatted according the pattern given to the last call
* of {@link #applyPattern(String)}.
*
- * @param angle Angle to format, in decimal degrees.
- * @return The formatted string.
+ * @param angle angle to format, in decimal degrees.
+ * @return the formatted string.
*/
public final String format(final double angle) {
return format(angle, new StringBuffer(), null).toString();
@@ -893,16 +891,12 @@ public class AngleFormat extends Format
* Formats an angle in the given buffer. The angle will be formatted according
* the pattern given to the last call of {@link #applyPattern(String)}.
*
- * @param angle
- * Angle to format, in decimal degrees.
- * @param toAppendTo
- * The buffer where to append the formatted angle.
- * @param pos
- * An optional object where to store the position of the field in the formatted
- * text, or {@code null} if this information is not wanted. This field position
- * shall be created with one of the {@link Field} constants.
- *
- * @return The {@code toAppendTo} buffer, returned for method calls chaining.
+ * @param angle angle to format, in decimal degrees.
+ * @param toAppendTo the buffer where to append the formatted angle.
+ * @param pos an optional object where to store the position of the field in the formatted text,
+ * or {@code null} if this information is not wanted. This field position shall be
+ * created with one of the {@link Field} constants.
+ * @return the {@code toAppendTo} buffer, returned for method calls chaining.
*/
@SuppressWarnings("PointlessBitwiseExpression") // We rely on the compiler for simplifying the expression.
public StringBuffer format(final double angle, StringBuffer toAppendTo, final FieldPosition pos) {
@@ -937,15 +931,15 @@ public class AngleFormat extends Format
final double p = pow10(maximumFractionDigits);
if (secondsFieldWidth != 0) {
seconds = (minutes - (minutes = truncate(minutes))) * 60;
- seconds = rint(seconds * p) / p; // Correction for rounding errors.
- if (seconds >= 60) { // We do not expect > 60 (only == 60), but let be safe.
+ seconds = rint(seconds * p) / p; // Correction for rounding errors.
+ if (seconds >= 60) { // We do not expect > 60 (only == 60), but let be safe.
seconds = 0;
minutes++;
}
} else {
- minutes = rint(minutes * p) / p; // Correction for rounding errors.
+ minutes = rint(minutes * p) / p; // Correction for rounding errors.
}
- if (minutes >= 60) { // We do not expect > 60 (only == 60), but let be safe.
+ if (minutes >= 60) { // We do not expect > 60 (only == 60), but let be safe.
minutes = 0;
degrees += Math.signum(angle);
}
@@ -1038,7 +1032,7 @@ public class AngleFormat extends Format
*/
final int startPosition = toAppendTo.length();
if (characterIterator != null) {
- final FormattedCharacterIterator it = (FormattedCharacterIterator) characterIterator;
+ final FormattedCharacterIterator it = characterIterator;
it.append(numberFormat.formatToCharacterIterator(value), toAppendTo);
if (suffix != null) {
toAppendTo.append(suffix);
@@ -1083,16 +1077,12 @@ public class AngleFormat extends Format
* method.</li>
* </ul>
*
- * @param value
- * {@link Angle} object to format.
- * @param toAppendTo
- * The buffer where to append the formatted angle.
- * @param pos
- * An optional object where to store the position of the field in the formatted
- * text, or {@code null} if this information is not wanted. This field position
- * shall be created with one of the {@link Field} constants.
- *
- * @return The {@code toAppendTo} buffer, returned for method calls chaining.
+ * @param value {@link Angle} object to format.
+ * @param toAppendTo the buffer where to append the formatted angle.
+ * @param pos an optional object where to store the position of the field in the formatted text,
+ * or {@code null} if this information is not wanted. This field position shall be
+ * created with one of the {@link Field} constants.
+ * @return the {@code toAppendTo} buffer, returned for method calls chaining.
* @throws IllegalArgumentException if {@code value} if not an instance of {@link Angle}.
*/
@Override
@@ -1136,8 +1126,7 @@ public class AngleFormat extends Format
pos.setEndIndex(toAppendTo.length());
}
if (characterIterator != null) {
- ((FormattedCharacterIterator) characterIterator).addFieldLimit(
- Field.HEMISPHERE, suffix, startPosition);
+ characterIterator.addFieldLimit(Field.HEMISPHERE, suffix, startPosition);
}
return toAppendTo;
}
@@ -1181,8 +1170,8 @@ public class AngleFormat extends Format
* In Apache SIS implementation, the returned character iterator also implements the
* {@link CharSequence} interface for convenience.
*
- * @param value {@link Angle} object to format.
- * @return A character iterator together with the attributes describing the formatted value.
+ * @param value the {@link Angle} object to format.
+ * @return a character iterator together with the attributes describing the formatted value.
* @throws IllegalArgumentException if {@code value} if not an instance of {@link Angle}.
*/
@Override
@@ -1209,16 +1198,13 @@ public class AngleFormat extends Format
* been recognized, then this method will compares against the standard ', ° and "
* ASCII symbols.</p>
*
- * @param source
- * The string being parsed.
- * @param pos
- * On input, index of the first {@code source} character to read.
- * On output, index after the last suffix character.
- * @param expectedField
- * First field to verify. For example a value of {@link #MINUTES_FIELD} means that
- * the suffix for minute and seconds shall be verified before degrees.
- * @return The {@code *_FIELD} constant for the suffix which has been found, or a value
- * outside those constants if no suffix matched.
+ * @param source the string being parsed.
+ * @param pos on input, index of the first {@code source} character to read.
+ * On output, index after the last suffix character.
+ * @param expectedField first field to verify. For example a value of {@link #MINUTES_FIELD} means that
+ * the suffix for minute and seconds shall be verified before degrees.
+ * @return the {@code *_FIELD} constant for the suffix which has been found,
+ * or a value outside those constants if no suffix matched.
*/
private int skipSuffix(final String source, final ParsePosition pos, final int expectedField) {
int field = expectedField;
@@ -1246,7 +1232,7 @@ public class AngleFormat extends Format
c = source.codePointAt(index);
index += Character.charCount(c);
}
- while (Character.isSpaceChar(c)); // Method shall be consistent with skipSpaces(…)
+ while (Character.isSpaceChar(c)); // Method shall be consistent with skipSpaces(…)
}
if (++field > SECONDS_FIELD) {
field = PREFIX_FIELD;
@@ -1265,7 +1251,7 @@ public class AngleFormat extends Format
c = source.codePointAt(start);
start += Character.charCount(c);
}
- while (Character.isSpaceChar(c)); // Method shall be consistent with skipSpaces(…)
+ while (Character.isSpaceChar(c)); // Method shall be consistent with skipSpaces(…)
switch (c) {
case '°' : pos.setIndex(start); return DEGREES_FIELD;
case '′' : case '\'': pos.setIndex(start); return MINUTES_FIELD;
@@ -1285,10 +1271,10 @@ public class AngleFormat extends Format
* not want to skip tabulations or line feeds, since they are unlikely to be part of
* the angle to parse.
*
- * @param source The string being parsed.
- * @param index Index of the first {@code source} character to read.
- * @param length The length of {@code source}.
- * @return Index of the first non-space character, or the end of string if none.
+ * @param source the string being parsed.
+ * @param index index of the first {@code source} character to read.
+ * @param length the length of {@code source}.
+ * @return index of the first non-space character, or the end of string if none.
*/
private static int skipSpaces(final String source, int index, final int length) {
while (index < length) {
@@ -1315,10 +1301,10 @@ public class AngleFormat extends Format
* used as a separator for other kinds of values. If the string is known to contain only
* an angle value, use {@code parse(String)} instead.</p>
*
- * @param source The string to parse.
- * @param pos On input, index of the first {@code source} character to read.
- * On output, index after the last parsed character.
- * @return The parsed string as an {@link Angle}, {@link Latitude} or {@link Longitude} object.
+ * @param source the string to parse.
+ * @param pos on input, index of the first {@code source} character to read.
+ * On output, index after the last parsed character.
+ * @return the parsed string as an {@link Angle}, {@link Latitude} or {@link Longitude} object.
*
* @see #isFallbackAllowed()
*/
@@ -1652,7 +1638,7 @@ BigBoss: switch (skipSuffix(source, p
case EAST : pos.setIndex(index); return new Longitude( degrees);
case WEST : pos.setIndex(index); return new Longitude(-degrees);
}
- if (!Character.isSpaceChar(c)) { // Method shall be consistent with skipSpaces(…)
+ if (!Character.isSpaceChar(c)) { // Method shall be consistent with skipSpaces(…)
break;
}
}
@@ -1665,9 +1651,9 @@ BigBoss: switch (skipSuffix(source, p
* {@link #parse(String, ParsePosition)} regarding white spaces between degrees, minutes
* and seconds fields.
*
- * @param source The string to parse.
- * @return The parsed string as an {@link Angle}, {@link Latitude} or {@link Longitude} object.
- * @throws ParseException If the string can not be fully parsed.
+ * @param source the string to parse.
+ * @return the parsed string as an {@link Angle}, {@link Latitude} or {@link Longitude} object.
+ * @throws ParseException if the string can not be fully parsed.
*
* @see #isFallbackAllowed()
*/
@@ -1686,9 +1672,9 @@ BigBoss: switch (skipSuffix(source, p
* Parses a substring as an object.
* The default implementation delegates to {@link #parse(String, ParsePosition)}.
*
- * @param source The string to parse.
- * @param pos The position where to start parsing.
- * @return The parsed string as an {@link Angle}, {@link Latitude} or {@link Longitude} object.
+ * @param source the string to parse.
+ * @param pos the position where to start parsing.
+ * @return the parsed string as an {@link Angle}, {@link Latitude} or {@link Longitude} object.
*/
@Override
public Object parseObject(final String source, final ParsePosition pos) {
@@ -1699,9 +1685,9 @@ BigBoss: switch (skipSuffix(source, p
* Parses the given string as an object.
* The default implementation delegates to {@link #parse(String)}.
*
- * @param source The string to parse.
- * @return The parsed string as an {@link Angle}, {@link Latitude} or {@link Longitude} object.
- * @throws ParseException If the string can not been fully parsed.
+ * @param source the string to parse.
+ * @return the parsed string as an {@link Angle}, {@link Latitude} or {@link Longitude} object.
+ * @throws ParseException if the string can not been fully parsed.
*/
@Override
public Object parseObject(final String source) throws ParseException {
@@ -1745,7 +1731,7 @@ BigBoss: switch (skipSuffix(source, p
* Returns this formatter locale. This is the locale specified at construction time if any,
* or the {@linkplain Locale#getDefault() default locale} at construction time otherwise.
*
- * @return This formatter locale (never {@code null}).
+ * @return this formatter locale (never {@code null}).
*/
@Override
public Locale getLocale() {
@@ -1755,7 +1741,7 @@ BigBoss: switch (skipSuffix(source, p
/**
* Returns a clone of this {@code AngleFormat}.
*
- * @return A clone of this format.
+ * @return a clone of this format.
*/
@Override
public AngleFormat clone() {
@@ -1778,7 +1764,7 @@ BigBoss: switch (skipSuffix(source, p
/**
* Compares this format with the specified object for equality.
*
- * @param object The object to compare with this angle format for equality.
+ * @param object the object to compare with this angle format for equality.
*/
@Override
public boolean equals(final Object object) {
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -16,9 +16,9 @@
*/
package org.apache.sis.measure;
-import javax.measure.unit.Unit;
-import javax.measure.converter.UnitConverter;
-import javax.measure.converter.ConversionException;
+import javax.measure.Unit;
+import javax.measure.UnitConverter;
+import javax.measure.IncommensurableException;
import org.apache.sis.util.Numbers;
import org.apache.sis.util.resources.Errors;
@@ -243,9 +243,9 @@ public class MeasurementRange<E extends
*
* @param targetUnit the target unit, or {@code null} for keeping the unit unchanged.
* @return the converted range, or {@code this} if no conversion is needed.
- * @throws ConversionException if the target unit are not compatible with this {@linkplain #unit() range unit}.
+ * @throws IncommensurableException if the target unit are not compatible with this {@linkplain #unit() range unit}.
*/
- public MeasurementRange<E> convertTo(final Unit<?> targetUnit) throws ConversionException {
+ public MeasurementRange<E> convertTo(final Unit<?> targetUnit) throws IncommensurableException {
return convertAndCast(elementType, targetUnit);
}
@@ -275,7 +275,7 @@ public class MeasurementRange<E extends
private <N extends E> Range<N> convert(final Range<N> range) throws IllegalArgumentException {
if (range instanceof MeasurementRange<?>) try {
return ((MeasurementRange<N>) range).convertAndCast(range.elementType, unit);
- } catch (ConversionException e) {
+ } catch (IncommensurableException e) {
throw new IllegalArgumentException(Errors.format(Errors.Keys.IncompatibleUnits_2,
((MeasurementRange<?>) range).unit, unit), e);
}
@@ -298,7 +298,7 @@ public class MeasurementRange<E extends
{
if (range instanceof MeasurementRange<?>) try {
return ((MeasurementRange<?>) range).convertAndCast(type, unit);
- } catch (ConversionException e) {
+ } catch (IncommensurableException e) {
throw new IllegalArgumentException(Errors.format(Errors.Keys.IncompatibleUnits_2,
((MeasurementRange<?>) range).unit, unit), e);
}
@@ -314,11 +314,11 @@ public class MeasurementRange<E extends
* {@link Integer}, {@link Long}, {@link Float} or {@link Double}.
* @param targetUnit the target unit, or {@code null} for no change.
* @return the casted range, or {@code this}.
- * @throws ConversionException if the given target unit is not compatible with the unit of this range.
+ * @throws IncommensurableException if the given target unit is not compatible with the unit of this range.
*/
@SuppressWarnings("unchecked")
private <N extends Number & Comparable<? super N>> MeasurementRange<N>
- convertAndCast(final Class<N> type, Unit<?> targetUnit) throws ConversionException
+ convertAndCast(final Class<N> type, Unit<?> targetUnit) throws IncommensurableException
{
if (targetUnit == null || targetUnit.equals(unit)) {
if (elementType == type) {
@@ -327,7 +327,7 @@ public class MeasurementRange<E extends
targetUnit = unit;
} else if (unit != null) {
final UnitConverter converter = unit.getConverterToAny(targetUnit);
- if (!converter.equals(UnitConverter.IDENTITY)) {
+ if (!converter.isIdentity()) {
boolean minInc = isMinIncluded;
boolean maxInc = isMaxIncluded;
double minimum = converter.convert(getMinDouble());
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java?rev=1767577&r1=1767576&r2=1767577&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java [UTF-8] Tue Nov 1 21:03:06 2016
@@ -20,9 +20,8 @@ import java.util.Formatter;
import java.util.Formattable;
import java.util.FormattableFlags;
import java.io.Serializable;
-import javax.measure.unit.Unit;
+import javax.measure.Unit;
import org.apache.sis.internal.util.Utilities;
-import org.apache.sis.internal.util.PatchedUnitFormat;
import org.apache.sis.util.collection.CheckedContainer;
import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.util.Emptiable;
@@ -86,7 +85,7 @@ import java.util.Objects;
* @author Martin Desruisseaux (Geomatys)
* @author Jody Garnett (for parameterized type inspiration)
* @since 0.3
- * @version 0.3
+ * @version 0.8
* @module
*
* @see RangeFormat
@@ -681,8 +680,8 @@ public class Range<E extends Comparable<
}
final Unit<?> unit = unit();
if (unit != null) {
- final String symbol = PatchedUnitFormat.toString(unit);
- if (!symbol.isEmpty()) {
+ final String symbol = unit.toString();
+ if (symbol != null && !symbol.isEmpty()) {
if (Character.isLetterOrDigit(symbol.codePointAt(0))) {
buffer.append(' ');
}
|