You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2016/12/31 07:44:11 UTC
svn commit: r1776698 [3/5] - in /sis/trunk: ./
application/sis-console/src/main/java/org/apache/sis/console/
core/sis-build-helper/src/main/java/org/apache/sis/util/resources/
core/sis-feature/src/main/java/org/apache/sis/feature/
core/sis-feature/src/...
Modified: sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/HTMLGenerator.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/HTMLGenerator.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/HTMLGenerator.java [UTF-8] (original)
+++ sis/trunk/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/HTMLGenerator.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -125,8 +125,8 @@ abstract strictfp class HTMLGenerator im
/**
* Escapes the {@code &}, {@code <} and {@code >} characters.
*
- * @param text The text to escape, or {@code null}.
- * @return The escaped text, or {@code null} if the given text was null.
+ * @param text the text to escape, or {@code null}.
+ * @return the escaped text, or {@code null} if the given text was null.
*/
static CharSequence escape(CharSequence text) {
text = CharSequences.replace(text, "&", "&");
@@ -150,8 +150,8 @@ abstract strictfp class HTMLGenerator im
/**
* Opens a new HTML tag and increase the indentation.
*
- * @param tag The HTML tag without brackets (e.g. {@code "h2"}).
- * @return The value to give to {@link #closeTags(int)} for closing the tags.
+ * @param tag the HTML tag without brackets (e.g. {@code "h2"}).
+ * @return the value to give to {@link #closeTags(int)} for closing the tags.
* @throws IOException if an error occurred while writing to the file.
*/
final int openTag(final String tag) throws IOException {
@@ -169,7 +169,7 @@ abstract strictfp class HTMLGenerator im
/**
* Closes the last HTML tag if it is equals to the given element, and opens a new tag on the same line.
*
- * @param tag The HTML tag without brackets (e.g. {@code "h2"}).
+ * @param tag the HTML tag without brackets (e.g. {@code "h2"}).
* @throws IOException if an error occurred while writing to the file.
*/
final void reopenTag(final String tag) throws IOException {
@@ -190,7 +190,7 @@ abstract strictfp class HTMLGenerator im
/**
* Closes the HTML tag identified by the given number, together will all child tags.
*
- * @param openedTag The value returned by the {@link #openTag(String)} matching the tag to close.
+ * @param openedTag the value returned by the {@link #openTag(String)} matching the tag to close.
* @throws IOException if an error occurred while writing to the file.
*/
final void closeTags(final int openedTag) throws IOException {
@@ -209,8 +209,8 @@ abstract strictfp class HTMLGenerator im
* The {@code &}, {@code <} and {@code >} characters are <strong>not</strong> escaped.
* For escaping those characters, invoke <code>println(tag, {@linkplain #escape(CharSequence) escape}(value))</code>.
*
- * @param tag The HTML tag without brackets (e.g. {@code "h1"}).
- * @param value The text to write, or {@code null}�for none.
+ * @param tag the HTML tag without brackets (e.g. {@code "h1"}).
+ * @param value the text to write, or {@code null}�for none.
* @throws IOException if an error occurred while writing to the file.
*/
final void println(final String tag, final CharSequence value) throws IOException {
@@ -233,7 +233,7 @@ abstract strictfp class HTMLGenerator im
* The {@code &}, {@code <} and {@code >} characters are <strong>not</strong> escaped.
* For escaping those characters, invoke <code>println({@linkplain #escape(CharSequence) escape}(value))</code>.
*
- * @param value The text to write, or {@code null}�if none.
+ * @param value the text to write, or {@code null}�if none.
* @throws IOException if an error occurred while writing to the file.
*/
final void println(final CharSequence value) throws IOException {
@@ -258,8 +258,8 @@ abstract strictfp class HTMLGenerator im
/**
* Returns the localized version of the given string, or {@code null} if none.
*
- * @param text The text to localize, or {@code null}.
- * @return The localized test, or {@code null}.
+ * @param text the text to localize, or {@code null}.
+ * @return the localized test, or {@code null}.
*
* @see #LOCALE
*/
@@ -270,7 +270,7 @@ abstract strictfp class HTMLGenerator im
/**
* Returns {@code true} if the given object is deprecated.
*
- * @param object The object to test.
+ * @param object the object to test.
* @return {@code true} if the given object is deprecated.
*/
static boolean isDeprecated(final Object object) {
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -50,7 +50,7 @@ public final class TM_Primitive extends
/**
* Wraps a Temporal Primitive value at marshalling-time.
*
- * @param metadata The metadata value to marshal.
+ * @param metadata the metadata value to marshal.
*/
private TM_Primitive(final TemporalPrimitive metadata) {
super(metadata);
@@ -59,8 +59,8 @@ public final class TM_Primitive extends
/**
* Returns the Vertical CRS value wrapped by a temporal primitive element.
*
- * @param value The value to marshal.
- * @return The adapter which wraps the metadata value.
+ * @param value the value to marshal.
+ * @return the adapter which wraps the metadata value.
*/
@Override
protected TM_Primitive wrap(final TemporalPrimitive value) {
@@ -81,7 +81,7 @@ public final class TM_Primitive extends
* Returns the {@code TimePeriod} generated from the metadata value.
* This method is systematically called at marshalling-time by JAXB.
*
- * @return The time period, or {@code null}.
+ * @return the time period, or {@code null}.
*/
@XmlElement(name = "TimePeriod")
public TimePeriod getTimePeriod() {
@@ -93,7 +93,7 @@ public final class TM_Primitive extends
* Returns the {@link TimeInstant} generated from the metadata value.
* This method is systematically called at marshalling-time by JAXB.
*
- * @return The time instant, or {@code null}.
+ * @return the time instant, or {@code null}.
*/
@XmlElement(name = "TimeInstant")
public TimeInstant getTimeInstant() {
@@ -105,10 +105,10 @@ public final class TM_Primitive extends
* Sets the value from the {@link TimePeriod}.
* This method is called at unmarshalling-time by JAXB.
*
- * @param period The wrapper to set.
+ * @param period the wrapper to set.
*/
public void setTimePeriod(final TimePeriod period) {
- metadata = null; // Cleaned first in case of failure.
+ metadata = null; // Cleaned first in case of failure.
if (period != null) {
final Context context = Context.current();
final Date begin = toDate(context, period.begin);
@@ -137,10 +137,10 @@ public final class TM_Primitive extends
* Sets the value from the {@link TimeInstant}.
* This method is called at unmarshalling-time by JAXB.
*
- * @param instant The wrapper to set.
+ * @param instant the wrapper to set.
*/
public void setTimeInstant(final TimeInstant instant) {
- metadata = null; // Cleaned first in case of failure.
+ metadata = null; // Cleaned first in case of failure.
if (instant != null) {
final Date position = XmlUtilities.toDate(Context.current(), instant.timePosition);
if (position != null) try {
@@ -162,7 +162,7 @@ public final class TM_Primitive extends
/**
* Reports a warning for the given exception.
*
- * @param method The name of the method to declare in the log record.
+ * @param method the name of the method to declare in the log record.
* @param e the exception.
*/
private static void warningOccured(final String method, final Exception e) {
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleMetadata.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleMetadata.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleMetadata.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleMetadata.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -99,7 +99,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<Locale> getLanguages() {
- return Collections.emptySet();
+ return Collections.emptySet(); // We use 'Set' because we handle 'Locale' like a CodeList.
}
/**
@@ -117,7 +117,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<Locale> getLocales() {
- return Collections.emptySet();
+ return Collections.emptySet(); // We use 'Set' because we handle 'Locale' like a CodeList.
}
/**
@@ -126,7 +126,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<CharacterSet> getCharacterSets() {
- return Collections.emptySet();
+ return Collections.emptySet(); // We use 'Set' because we handle 'Charset' like a CodeList.
}
/**
@@ -169,7 +169,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<ResponsibleParty> getContacts() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -210,7 +210,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<SpatialRepresentation> getSpatialRepresentationInfo() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -218,7 +218,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<ReferenceSystem> getReferenceSystemInfo() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -226,7 +226,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<MetadataExtensionInformation> getMetadataExtensionInfo() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -255,7 +255,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<ContentInformation> getContentInfo() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -271,7 +271,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<DataQuality> getDataQualityInfo() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -279,7 +279,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<PortrayalCatalogueReference> getPortrayalCatalogueInfo() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -287,7 +287,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<Constraints> getMetadataConstraints() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -295,7 +295,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<ApplicationSchemaInformation> getApplicationSchemaInfo() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -303,7 +303,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<AcquisitionInformation> getAcquisitionInformation() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -353,7 +353,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<String> getCredits() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -362,7 +362,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<Progress> getStatus() {
- return Collections.emptySet();
+ return Collections.emptySet(); // We use 'Set' because 'Progress' is a CodeList.
}
/**
@@ -371,7 +371,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<ResponsibleParty> getPointOfContacts() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -391,7 +391,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<Resolution> getSpatialResolutions() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -411,7 +411,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<Extent> getExtents() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -420,7 +420,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<MaintenanceInformation> getResourceMaintenances() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -429,7 +429,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<BrowseGraphic> getGraphicOverviews() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -438,7 +438,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<Format> getResourceFormats() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -447,7 +447,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<Keywords> getDescriptiveKeywords() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -457,7 +457,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<Usage> getResourceSpecificUsages() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -466,7 +466,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<Constraints> getResourceConstraints() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -475,7 +475,7 @@ public class SimpleMetadata implements M
@Override
@Deprecated
public Collection<AggregateInformation> getAggregationInfo() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -517,7 +517,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<InternationalString> getAlternateTitles() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -526,7 +526,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<CitationDate> getDates() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -553,7 +553,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<Identifier> getIdentifiers() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
@@ -563,7 +563,7 @@ public class SimpleMetadata implements M
*/
@Override
public Collection<ResponsibleParty> getCitedResponsibleParties() {
- return Collections.emptySet();
+ return Collections.emptyList();
}
/**
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/LocalizedParseException.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/LocalizedParseException.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/LocalizedParseException.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/internal/util/LocalizedParseException.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -19,15 +19,16 @@ package org.apache.sis.internal.util;
import java.util.Locale;
import java.text.ParsePosition;
import java.text.ParseException;
+import org.opengis.util.InternationalString;
import org.apache.sis.util.Workaround;
-import org.apache.sis.util.Localized;
import org.apache.sis.util.CharSequences;
import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.LocalizedException;
/**
- * A {@link ParseException} in which {@link #getLocalizedMessage()} returns the message in the
- * parser locale. This exception contains the error message in two languages:
+ * A {@link ParseException} in which {@link #getLocalizedMessage()} returns the message in the parser locale.
+ * This exception contains the error message in two languages:
*
* <ul>
* <li>{@link ParseException#getMessage()} returns the message in the default locale.</li>
@@ -40,64 +41,48 @@ import org.apache.sis.util.resources.Err
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.7
+ * @version 0.8
* @module
*/
-public final class LocalizedParseException extends ParseException implements LocalizedException, Localized {
+public final class LocalizedParseException extends ParseException implements LocalizedException {
/**
* For cross-version compatibility.
*/
private static final long serialVersionUID = -1467571540435486742L;
/**
- * The locale to use for formatting the localized error message, or {@code null} for the default.
- */
- private final Locale locale;
-
- /**
- * The resources key as one of the {@code Errors.Keys} constant.
- */
- private final short key;
-
- /**
- * The arguments for the localization message.
+ * The resources key as one of the {@link Errors.Keys} constant, or 0 if none.
+ *
+ * <p>This field is not serialized because key values sometime change between different SIS versions.
+ * The deserialized value will be 0, which will cause this {@code LocalizedParseException} to fallback
+ * on {@code super.getMessage()}.</p>
*/
- private final Object[] arguments;
+ private transient final short key;
/**
- * Constructs a {@code ParseException} with a message formatted from the given resource key
- * and message arguments. This is the most generic constructor.
- *
- * @param locale the locale for {@link #getLocalizedMessage()}, or {@code null} for the default.
- * @param key the resource key as one of the {@code Errors.Keys} constant.
- * @param arguments the values to be given to {@link Errors#getString(short, Object)}.
- * @param errorOffset the position where the error is found while parsing.
+ * The parameters for the localization message.
*/
- public LocalizedParseException(final Locale locale, final short key, final Object[] arguments, final int errorOffset) {
- super(Errors.format(key, arguments), errorOffset);
- this.locale = locale;
- this.arguments = arguments;
- this.key = key;
- }
+ private transient final Object[] parameters;
/**
- * Constructs a {@code ParseException} with a message formatted from the given resource key
- * and unparsable string. This convenience constructor fetches the word starting at the error
- * index, and uses that word as the single argument associated to the resource key.
+ * Constructs a {@code ParseException} with a message formatted from the given resource key and message parameters.
+ * This is the most generic constructor.
*
* @param locale the locale for {@link #getLocalizedMessage()}, or {@code null} for the default.
* @param key the resource key as one of the {@code Errors.Keys} constant.
- * @param text the full text that {@code Format} failed to parse.
+ * @param parameters the values to be given to {@link Errors#getString(short, Object)}.
* @param errorOffset the position where the error is found while parsing.
*/
- public LocalizedParseException(final Locale locale, final short key, final CharSequence text, final int errorOffset) {
- this(locale, key, new Object[] {CharSequences.token(text, errorOffset)}, errorOffset);
+ public LocalizedParseException(final Locale locale, final short key, final Object[] parameters, final int errorOffset) {
+ super(Errors.getResources(locale).getString(key, parameters), errorOffset);
+ this.parameters = parameters;
+ this.key = key;
}
/**
- * Creates a {@link ParseException} with a localized message built from the given parsing
- * information. This convenience constructor creates a message of the kind <cite>"Can not
- * parse string "text" as an object of type 'type'"</cite>.
+ * Creates a {@link ParseException} with a localized message built from the given parsing information.
+ * This convenience constructor creates a message of the kind <cite>"Can not parse string "text" as an
+ * object of type 'type'"</cite>.
*
* @param locale the locale for {@link #getLocalizedMessage()}, or {@code null} for the default.
* @param type the type of objects parsed by the {@link java.text.Format}.
@@ -114,20 +99,20 @@ public final class LocalizedParseExcepti
* Workaround for RFE #4093999
* ("Relax constraint on placement of this()/super() call in constructors").
*/
- @Workaround(library="JDK", version="1.7")
+ @Workaround(library="JDK", version="1.8")
private LocalizedParseException(final Locale locale, final Class<?> type,
final CharSequence text, final int offset, final int errorOffset)
{
- this(locale, arguments(type, text, offset, Math.max(offset, errorOffset)), errorOffset);
+ this(locale, parameters(type, text, offset, Math.max(offset, errorOffset)), errorOffset);
}
/**
* Workaround for RFE #4093999
* ("Relax constraint on placement of this()/super() call in constructors").
*/
- @Workaround(library="JDK", version="1.7")
- private LocalizedParseException(final Locale locale, final Object[] arguments, final int errorOffset) {
- this(locale, key(arguments), arguments, errorOffset);
+ @Workaround(library="JDK", version="1.8")
+ private LocalizedParseException(final Locale locale, final Object[] parameters, final int errorOffset) {
+ this(locale, key(parameters), parameters, errorOffset);
}
/**
@@ -138,15 +123,15 @@ public final class LocalizedParseExcepti
* @param text the text that {@code Format} failed to parse.
* @param offset index of the first character to parse in {@code text}.
* @param errorOffset the position where the error is found while parsing.
- * @return the {@code arguments} value to give to the constructor.
+ * @return the {@code parameters} value to give to the constructor.
*/
- @Workaround(library="JDK", version="1.7")
- private static Object[] arguments(final Class<?> type, CharSequence text, final int offset, final int errorOffset) {
+ @Workaround(library="JDK", version="1.8")
+ private static Object[] parameters(final Class<?> type, CharSequence text, final int offset, final int errorOffset) {
if (errorOffset >= text.length()) {
return new Object[] {text};
}
- text = text.subSequence(offset, text.length());
final CharSequence erroneous = CharSequences.token(text, errorOffset);
+ text = text.subSequence(offset, text.length());
if (erroneous.length() == 0) {
return new Object[] {type, text};
}
@@ -157,10 +142,10 @@ public final class LocalizedParseExcepti
* Workaround for RFE #4093999
* ("Relax constraint on placement of this()/super() call in constructors").
*/
- @Workaround(library="JDK", version="1.7")
- private static short key(final Object[] arguments) {
+ @Workaround(library="JDK", version="1.8")
+ private static short key(final Object[] parameters) {
final short key;
- switch (arguments.length) {
+ switch (parameters.length) {
case 1: key = Errors.Keys.UnexpectedEndOfString_1; break;
case 2: key = Errors.Keys.UnparsableStringForClass_2; break;
case 3: key = Errors.Keys.UnparsableStringForClass_3; break;
@@ -170,26 +155,44 @@ public final class LocalizedParseExcepti
}
/**
- * {@inheritDoc}
+ * Returns the exception message in the default locale, typically for system administrator.
+ *
+ * @return the message of this exception.
*/
@Override
- public Locale getLocale() {
- return (locale != null) ? locale : Locale.getDefault();
+ public String getMessage() {
+ return (key != 0) ? Errors.format(key, parameters) : super.getMessage();
}
/**
- * {@inheritDoc}
+ * Returns a localized version of the exception message, typically for final user.
+ *
+ * @return the localized message of this exception.
*/
@Override
public String getLocalizedMessage() {
- return Errors.getResources(locale).getString(key, arguments);
+ return super.getMessage();
}
/**
- * {@inheritDoc}
+ * If this exception is capable to return the message in various locales, returns that message.
+ * Otherwise returns {@code null}.
+ *
+ * @return the exception message, or {@code null} if this exception can not produce international message.
+ */
+ @Override
+ public InternationalString getInternationalMessage() {
+ return (key != 0) ? Errors.formatInternational(key, parameters) : null;
+ }
+
+ /**
+ * Initializes the <i>cause</i> of this throwable to the specified value.
+ *
+ * @param cause the cause saved for later retrieval by the {@link #getCause()} method.
+ * @return a reference to this {@code LocalizedParseException} instance.
*/
@Override
- public String getLocalizedMessage(final Locale locale) {
- return Errors.getResources(locale).getString(key, arguments);
+ public LocalizedParseException initCause(final Throwable cause) {
+ return (LocalizedParseException) super.initCause(cause);
}
}
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -115,9 +115,7 @@ final class DefaultFormat extends Format
try {
return valueOf(source);
} catch (NumberFormatException cause) {
- ParseException e = new LocalizedParseException(null, type, source, null);
- e.initCause(cause);
- throw e;
+ throw new LocalizedParseException(null, type, source, null).initCause(cause);
}
}
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/Angle.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/Angle.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/Angle.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/Angle.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -88,7 +88,7 @@ public class Angle implements Comparable
/**
* Constructs a new angle with the specified value in decimal degrees.
*
- * @param \u03b8 Angle in decimal degrees.
+ * @param \u03b8 angle in decimal degrees.
*/
public Angle(final double \u03b8) {
this.\u03b8 = \u03b8;
@@ -103,16 +103,16 @@ public class Angle implements Comparable
* locale. Developers should consider using {@link AngleFormat} for end-user applications
* instead than this constructor.</p>
*
- * @param string A string to be converted to an {@code Angle}.
+ * @param text a string to be converted to an {@code Angle}.
* @throws NumberFormatException if the string does not contain a parsable angle.
*
* @see AngleFormat#parse(String)
*/
- public Angle(final String string) throws NumberFormatException {
+ public Angle(final String text) throws NumberFormatException {
final Object angle;
try {
synchronized (Angle.class) {
- angle = getAngleFormat().parseObject(string);
+ angle = getAngleFormat().parseObject(text);
}
} catch (ParseException exception) {
/*
@@ -121,22 +121,20 @@ public class Angle implements Comparable
* 'getAngleFormat()' implementation. The getMessage() method uses the system locale,
* which is what we actually want.
*/
- NumberFormatException e = new NumberFormatException(exception.getMessage());
- e.initCause(exception);
- throw e;
+ throw (NumberFormatException) new NumberFormatException(exception.getMessage()).initCause(exception);
}
final Class<?> type = angle.getClass();
if (type == Angle.class || getClass().isAssignableFrom(type)) {
this.\u03b8 = ((Angle) angle).\u03b8;
} else {
- throw new NumberFormatException(string);
+ throw new NumberFormatException(text);
}
}
/**
* Returns the angle value in decimal degrees.
*
- * @return The angle value in decimal degrees.
+ * @return the angle value in decimal degrees.
*/
public double degrees() {
return \u03b8;
@@ -145,7 +143,7 @@ public class Angle implements Comparable
/**
* Returns the angle value in radians.
*
- * @return The angle value in radians.
+ * @return the angle value in radians.
*/
public double radians() {
return Math.toRadians(\u03b8);
@@ -163,7 +161,7 @@ public class Angle implements Comparable
/**
* Compares the specified object with this angle for equality.
*
- * @param object The object to compare with this angle for equality.
+ * @param object the object to compare with this angle for equality.
* @return {@code true} if the given object is equal to this angle.
*/
@Override
@@ -181,7 +179,7 @@ public class Angle implements Comparable
* Compares two {@code Angle} objects numerically. The comparison
* is done as if by the {@link Double#compare(double, double)} method.
*
- * @param that The angle to compare with this object for order.
+ * @param that the angle to compare with this object for order.
* @return -1 if this angle is smaller than the given one, +1 if greater or 0 if equals.
*/
@Override
@@ -217,11 +215,11 @@ public class Angle implements Comparable
public String toString() {
StringBuffer buffer = new StringBuffer();
double m = Math.abs(\u03b8);
- final boolean isSmall = m <= (1 / 3600E+3); // 1E-3 arc-second.
+ final boolean isSmall = m <= (1 / 3600E+3); // 1E-3 arc-second.
if (isSmall || m > maximum()) {
final char h = hemisphere(isNegative(\u03b8));
if (h == 0) {
- m = \u03b8; // Restore the sign.
+ m = \u03b8; // Restore the sign.
}
char symbol = '�';
if (isSmall) {
@@ -273,10 +271,10 @@ public class Angle implements Comparable
* <li>Otherwise the precision, if positive, is given to {@link AngleFormat#setMaximumWidth(int)}.</li>
* </ul>
*
- * @param formatter The formatter in which to format this angle.
- * @param flags {@link FormattableFlags#LEFT_JUSTIFY} for left alignment, or 0 for right alignment.
- * @param width Minimal number of characters to write, padding with {@code ' '} if necessary.
- * @param precision Maximal number of characters to write, or -1 if no limit.
+ * @param formatter the formatter in which to format this angle.
+ * @param flags {@link FormattableFlags#LEFT_JUSTIFY} for left alignment, or 0 for right alignment.
+ * @param width minimal number of characters to write, padding with {@code ' '} if necessary.
+ * @param precision maximal number of characters to write, or -1 if no limit.
*/
@Override
public void formatTo(final Formatter formatter, final int flags, final int width, final int precision) {
@@ -285,7 +283,7 @@ public class Angle implements Comparable
value = "";
} else {
final char h;
- int w = precision; // To be decremented only if we may truncate and an hemisphere symbol exist.
+ int w = precision; // To be decremented only if we may truncate and an hemisphere symbol exist.
if (w > 0 && (h = hemisphere(isNegative(\u03b8))) != 0 && --w == 0) {
value = Character.toString(h);
} else {
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/FormatField.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/FormatField.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/FormatField.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/FormatField.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -70,9 +70,7 @@ class FormatField extends Format.Field {
try {
return type.cast(type.getField(getName()).get(null));
} catch (Exception cause) { // Many exceptions, including unchecked ones.
- InvalidObjectException e = new InvalidObjectException(cause.toString());
- e.initCause(cause);
- throw e;
+ throw (InvalidObjectException) new InvalidObjectException(cause.toString()).initCause(cause);
}
}
}
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -33,9 +33,9 @@ import java.text.ParseException;
import java.text.ParsePosition;
import javax.measure.Unit;
import org.apache.sis.util.Numbers;
-import org.apache.sis.util.CharSequences;
-import org.apache.sis.util.UnconvertibleObjectException;
import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.UnconvertibleObjectException;
+import org.apache.sis.internal.util.LocalizedParseException;
/**
@@ -297,11 +297,17 @@ public class RangeFormat extends Format
private transient Map<Unit<?>,Boolean> insertSpaceBeforeUnit;
/**
+ * The locale for error message, or {@code null} for the default.
+ */
+ private Locale locale;
+
+ /**
* Creates a new format for parsing and formatting {@linkplain NumberRange number ranges}
* using the {@linkplain Locale#getDefault() default locale}.
*/
public RangeFormat() {
this(Locale.getDefault(Locale.Category.FORMAT));
+ locale = Locale.getDefault(Locale.Category.DISPLAY);
}
/**
@@ -336,6 +342,7 @@ public class RangeFormat extends Format
* @throws IllegalArgumentException if the given type is not recognized by this constructor.
*/
public RangeFormat(final Locale locale, final Class<?> elementType) throws IllegalArgumentException {
+ this.locale = locale;
this.elementType = elementType;
if (Angle.class.isAssignableFrom(elementType)) {
elementFormat = AngleFormat.getInstance(locale);
@@ -723,11 +730,7 @@ public class RangeFormat extends Format
} catch (UnconvertibleObjectException e) {
failure = e;
}
- final int errorIndex = pos.getErrorIndex();
- final ParseException e = new ParseException(Errors.format(Errors.Keys.UnparsableStringForClass_3,
- elementType, source, CharSequences.token(source, errorIndex)), errorIndex);
- e.initCause(failure);
- throw e;
+ throw new LocalizedParseException(locale, elementType, source, pos).initCause(failure);
}
/**
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/setup/About.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/setup/About.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/setup/About.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/setup/About.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -164,7 +164,7 @@ public enum About {
* return configuration(EnumSet.allOf(About.class), null, null);
* }
*
- * @return Configuration information, as a tree for grouping some configuration by sections.
+ * @return configuration information, as a tree for grouping some configuration by sections.
*/
public static TreeTable configuration() {
return configuration(EnumSet.allOf(About.class), null, null);
@@ -173,10 +173,10 @@ public enum About {
/**
* Returns a subset of the information about the current Apache SIS running environment.
*
- * @param sections The section for which information are desired.
- * @param locale The locale to use for formatting the texts in the tree, or {@code null} for the default.
- * @param timezone The timezone to use for formatting the dates, or {@code null} for the default.
- * @return Configuration information, as a tree for grouping some configuration by sections.
+ * @param sections the section for which information are desired.
+ * @param locale the locale to use for formatting the texts in the tree, or {@code null} for the default.
+ * @param timezone the timezone to use for formatting the dates, or {@code null} for the default.
+ * @return configuration information, as a tree for grouping some configuration by sections.
*/
public static TreeTable configuration(final Set<About> sections, Locale locale, final TimeZone timezone) {
ArgumentChecks.ensureNonNull("sections", sections);
@@ -503,9 +503,9 @@ pathTree: for (int j=0; ; j++) {
* Returns a map of all JAR files or class directories found in the given paths,
* associated to a description obtained from their {@code META-INF/MANIFEST.MF}.
*
- * @param paths The paths using the {@link File#pathSeparatorChar} separator.
- * @param asDirectories {@code true} if the paths are directories, or {@code false} for JAR files.
- * @return The paths, or {@code null} if none.
+ * @param paths the paths using the {@link File#pathSeparatorChar} separator.
+ * @param asDirectories {@code true} if the paths are directories, or {@code false} for JAR files.
+ * @return the paths, or {@code null} if none.
*/
private static Map<File,CharSequence> classpath(final String paths, final boolean asDirectories) {
final Map<File,CharSequence> files = new LinkedHashMap<>();
@@ -524,10 +524,10 @@ pathTree: for (int j=0; ; j++) {
* a {@code MANIFEST.MF} attribute using space as the path separator.</li>
* </ul>
*
- * @param paths The paths using the separator described above.
- * @param directory The directory of {@code MANIFEST.MF} classpath, or {@code null}.
- * @param asDirectories {@code true} if the paths are directories, or {@code false} for JAR files.
- * @param files Where to add the paths.
+ * @param paths the paths using the separator described above.
+ * @param directory the directory of {@code MANIFEST.MF} classpath, or {@code null}.
+ * @param asDirectories {@code true} if the paths are directories, or {@code false} for JAR files.
+ * @param files where to add the paths.
* @return {@code true} if the given map has been changed as a result of this method call.
*/
private static boolean classpath(final String paths, final File directory,
@@ -654,9 +654,9 @@ pathTree: for (int j=0; ; j++) {
* In particular, note that this implementation assumes that children collections are {@link List} (this is
* guaranteed for {@link DefaultTreeTable.Node} implementations).</p>
*
- * @param node The root of the node to simplify.
- * @param skip {@code true} for disabling concatenation of root node.
- * @return The root of the simplified tree. May be the given {@code node} or a child.
+ * @param node the root of the node to simplify.
+ * @param skip {@code true} for disabling concatenation of root node.
+ * @return the root of the simplified tree. May be the given {@code node} or a child.
*/
private static TreeTable.Node concatenateSingletons(final TreeTable.Node node, final boolean skip) {
// DefaultTreeTable.Node instances are known to handle their children in a List.
@@ -683,10 +683,10 @@ pathTree: for (int j=0; ; j++) {
* Concatenates the given strings in the format "main (complement)".
* Any of the given strings can be null.
*
- * @param main The main string to show first, or {@code null}.
- * @param complement The string to show after the main one, or {@code null}.
- * @param parenthesis {@code true} for writing the complement between parenthesis, or {@code null}.
- * @return The concatenated string, or {@code null} if all components are null.
+ * @param main the main string to show first, or {@code null}.
+ * @param complement the string to show after the main one, or {@code null}.
+ * @param parenthesis {@code true} for writing the complement between parenthesis, or {@code null}.
+ * @return the concatenated string, or {@code null} if all components are null.
*/
private static CharSequence concatenate(final CharSequence main, final CharSequence complement, final boolean parenthesis) {
if (main != null && main.length() != 0) {
@@ -729,10 +729,10 @@ pathTree: for (int j=0; ; j++) {
* Formats the given value preceded by a plus or minus sign.
* This method is used for formatting timezone offset.
*
- * @param df The {@link DateFormat} to use for formatting the offset.
- * @param offset The offset to format, as a positive or negative value.
- * @param buffer The buffer where to format the offset.
- * @return The given buffer, returned for convenience.
+ * @param df the {@link DateFormat} to use for formatting the offset.
+ * @param offset the offset to format, as a positive or negative value.
+ * @param buffer the buffer where to format the offset.
+ * @return the given buffer, returned for convenience.
*/
private static StringBuffer format(final Format df, final int offset, final StringBuffer buffer) {
return df.format(Math.abs(offset), buffer.append(offset < 0 ? '-' : '+').append(' '), new FieldPosition(0));
@@ -751,9 +751,9 @@ pathTree: for (int j=0; ; j++) {
* Returns the given file relative to the given root, or {@code null} if the root is not
* a parent of that file.
*
- * @param root The root directory (typically Java home or user home directory).
- * @param file The file to make relative to the root.
- * @return The file relative to the given root, or {@code null} if none.
+ * @param root the root directory (typically Java home or user home directory).
+ * @param file the file to make relative to the root.
+ * @return the file relative to the given root, or {@code null} if none.
*/
private static File relativize(final File root, final File file) {
File parent = file.getParentFile();
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/setup/OptionKey.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/setup/OptionKey.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/setup/OptionKey.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/setup/OptionKey.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -60,7 +60,7 @@ import org.apache.sis.internal.system.Mo
* }
* }
*
- * @param <T> The type of option values.
+ * @param <T> the type of option values.
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/Exceptions.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/Exceptions.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/Exceptions.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/Exceptions.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -20,10 +20,8 @@ import java.util.List;
import java.util.ArrayList;
import java.util.Locale;
import java.sql.SQLException;
-import org.apache.sis.internal.util.LocalizedException;
-
+import org.opengis.util.InternationalString;
import org.apache.sis.util.resources.Vocabulary;
-import static org.apache.sis.util.CharSequences.trimWhitespaces;
/**
@@ -31,7 +29,7 @@ import static org.apache.sis.util.CharSe
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @since 0.3
- * @version 0.7
+ * @version 0.8
* @module
*/
public final class Exceptions extends Static {
@@ -44,21 +42,43 @@ public final class Exceptions extends St
/**
* Returns the message of the given exception, localized in the given locale if possible.
* Some exceptions created by SIS can format a message in different locales. This method
- * will return such localized message if possible, or fallback on the standard
- * {@link Throwable#getLocalizedMessage()} method otherwise. Note that by default,
- * {@code getLocalizedMessage()} itself fallback on {@link Throwable#getMessage()}.
- *
- * @param exception The exception from which to get the localize message, or {@code null}.
- * @param locale The locale for the message, or {@code null} for the default locale.
- * @return The message in the given locale if possible, or {@code null} if the {@code exception}
- * argument was {@code null} or the exception does not contain a message.
+ * returns such localized message if possible, or fallback on the standard JDK methods otherwise.
+ * More specifically:
+ *
+ * <ul>
+ * <li>If the given {@code exception} is null, then this method returns {@code null}.</li>
+ * <li>Otherwise if the given {@code locale} is null, then this method returns {@link Exception#getMessage()}.
+ * This is consistent with the {@link Localized} policy saying that null locale stands for "unlocalized"
+ * message (usually in English) or message in the JVM {@linkplain Locale#getDefault() default locale}.</li>
+ * <li>Otherwise if the given {@code exception} is an instance of {@link LocalizedException} providing
+ * a non-null {@linkplain LocalizedException#getInternationalMessage() international message},
+ * then this method returns the result of {@link InternationalString#toString(Locale)}.</li>
+ * <li>Otherwise this method returns {@link Exception#getLocalizedMessage()}.</li>
+ * </ul>
+ *
+ * @param exception the exception from which to get the localize message, or {@code null}.
+ * @param locale the preferred locale for the message, or {@code null} for the JVM default locale.
+ * This locale is honored on a <cite>best-effort</cite> basis only.
+ * @return the message in the given locale if possible, or {@code null} if the {@code exception}
+ * argument was {@code null} or if the exception does not contain a message.
+ *
+ * @see LocalizedException#getLocalizedMessage()
*/
public static String getLocalizedMessage(final Throwable exception, final Locale locale) {
if (exception == null) {
return null;
}
- if (locale != null && exception instanceof LocalizedException) {
- return ((LocalizedException) exception).getLocalizedMessage(locale);
+ if (locale == null) {
+ return exception.getMessage(); // See the policy documented in LocalizedException.getMessage()
+ }
+ if (exception instanceof LocalizedException) {
+ final InternationalString i18n = ((LocalizedException) exception).getInternationalMessage();
+ if (i18n != null) {
+ final String message = i18n.toString(locale);
+ if (message != null) {
+ return message;
+ }
+ }
}
return exception.getLocalizedMessage();
}
@@ -75,20 +95,20 @@ public final class Exceptions extends St
* exception class does not provide such constructor, then the given exception is returned
* unchanged.</p>
*
- * @param <T> The type of the exception.
- * @param exception The exception to copy with a different message.
- * @param message The message to set in the exception to be returned.
- * @param append If {@code true}, the existing message in the original exception (if any)
- * will be happened after the provided message.
- * @return A new exception with the given message, or the given exception if the exception
+ * @param <T> the type of the exception.
+ * @param exception the exception to copy with a different message.
+ * @param message the message to set in the exception to be returned.
+ * @param append if {@code true}, the existing message in the original exception (if any)
+ * will be happened after the provided message.
+ * @return a new exception with the given message, or the given exception if the exception
* class does not provide public {@code Exception(String)} constructor.
*/
@SuppressWarnings("unchecked")
public static <T extends Throwable> T setMessage(final T exception, String message, final boolean append) {
if (append) {
- final String em = trimWhitespaces(exception.getLocalizedMessage());
+ final String em = CharSequences.trimWhitespaces(exception.getLocalizedMessage());
if (em != null && !em.isEmpty()) {
- final StringBuilder buffer = new StringBuilder(trimWhitespaces(message));
+ final StringBuilder buffer = new StringBuilder(CharSequences.trimWhitespaces(message));
final int length = buffer.length();
if (length != 0 && Character.isLetterOrDigit(buffer.charAt(length-1))) {
buffer.append(". ");
@@ -108,7 +128,7 @@ public final class Exceptions extends St
/**
* Returns a string which contain the given message on the first line, followed by the
- * {@linkplain Throwable#getLocalizedMessage() localized message} of the given exception
+ * {@linkplain #getLocalizedMessage(Throwable, Locale) localized message} of the given exception
* on the next line. If the exception has a {@linkplain Throwable#getCause() causes}, then
* the class name and the localized message of the cause are formatted on the next line
* and the process is repeated for the whole cause chain, omitting duplicated messages.
@@ -118,36 +138,38 @@ public final class Exceptions extends St
*
* <p>This method does not format the stack trace.</p>
*
- * @param locale The preferred locale for the exception message, or {@code null}.
- * @param header The message to insert on the first line, or {@code null} if none.
- * @param cause The exception, or {@code null} if none.
- * @return The formatted message, or {@code null} if both the header was {@code null}
+ * @param locale the preferred locale for the exception message, or {@code null}.
+ * @param header the message to insert on the first line, or {@code null} if none.
+ * @param cause the exception, or {@code null} if none.
+ * @return the formatted message, or {@code null} if both the header was {@code null}
* and no exception provide a message.
*/
- public static String formatChainedMessages(final Locale locale, String header, Throwable cause) {
+ public static String formatChainedMessages(final Locale locale, final String header, Throwable cause) {
final List<String> previousLines = new ArrayList<>();
- final String lineSeparator = System.lineSeparator();
StringBuilder buffer = null;
Vocabulary resources = null;
while (cause != null) {
- final String message = trimWhitespaces(getLocalizedMessage(cause, locale));
+ final String message = CharSequences.trimWhitespaces(getLocalizedMessage(cause, locale));
if (message != null && !message.isEmpty()) {
if (buffer == null) {
buffer = new StringBuilder(128);
- header = trimWhitespaces(header);
- if (header != null && !header.isEmpty()) {
- buffer.append(header);
+ if (header != null) {
+ final int length = CharSequences.skipTrailingWhitespaces(header, 0, header.length());
+ if (length > 0) {
+ buffer.append(header, 0, length);
+ }
previousLines.add(header);
}
}
if (!contains(previousLines, message)) {
previousLines.add(message);
if (buffer.length() != 0) {
- buffer.append(lineSeparator);
if (resources == null) {
resources = Vocabulary.getResources(locale);
}
- buffer.append(resources.getString(Vocabulary.Keys.CausedBy_1, cause.getClass())).append(": ");
+ buffer.append(System.lineSeparator())
+ .append(resources.getString(Vocabulary.Keys.CausedBy_1, cause.getClass()))
+ .append(": ");
}
buffer.append(message);
}
@@ -161,17 +183,14 @@ public final class Exceptions extends St
}
cause = cause.getCause();
}
- if (buffer != null) {
- header = buffer.toString();
- }
- return header;
+ return (buffer != null) ? buffer.toString() : header;
}
/**
* Returns {@code true} if a previous line contains the given exception message.
*/
private static boolean contains(final List<String> previousLines, final String message) {
- for (int i=previousLines.size(); --i>=0;) {
+ for (int i = previousLines.size(); --i >= 0;) {
if (previousLines.get(i).contains(message)) {
return true;
}
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/TableColumn.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/TableColumn.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/TableColumn.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/TableColumn.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -239,9 +239,7 @@ public class TableColumn<V> implements C
try {
return TableColumn.class.getField(field).get(null);
} catch (ReflectiveOperationException cause) {
- InvalidObjectException e = new InvalidObjectException(cause.toString());
- e.initCause(cause);
- throw e;
+ throw (InvalidObjectException) new InvalidObjectException(cause.toString()).initCause(cause);
}
}
}
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -167,9 +167,9 @@ public class TreeTableFormat extends Tab
/**
* Creates a new tree table format.
*
- * @param locale The locale to use for numbers, dates and angles formatting,
- * or {@code null} for the {@linkplain Locale#ROOT root locale}.
- * @param timezone The timezone, or {@code null} for UTC.
+ * @param locale the locale to use for numbers, dates and angles formatting,
+ * or {@code null} for the {@linkplain Locale#ROOT root locale}.
+ * @param timezone the timezone, or {@code null} for UTC.
*/
public TreeTableFormat(final Locale locale, final TimeZone timezone) {
super(locale, timezone);
@@ -212,7 +212,7 @@ public class TreeTableFormat extends Tab
* <li>On formatting, {@linkplain TreeTable#getColumns() all <code>TreeTable</code> columns}.</li>
* </ul>
*
- * @return The table columns to parse and format, or {@code null} for the default.
+ * @return the table columns to parse and format, or {@code null} for the default.
*/
public TableColumn<?>[] getColumns() {
return (columnIndices != null) ? DefaultTreeTable.getColumns(columnIndices) : null;
@@ -222,8 +222,8 @@ public class TreeTableFormat extends Tab
* Sets the table columns to parse and format. A {@code null} value means to use the default
* list of columns, as defined in the {@link #getColumns()} method.
*
- * @param columns The table columns to parse and format, or {@code null} for the default.
- * @throws IllegalArgumentException If the given array is empty, contains a null element
+ * @param columns the table columns to parse and format, or {@code null} for the default.
+ * @throws IllegalArgumentException if the given array is empty, contains a null element
* or a duplicated value.
*/
public void setColumns(final TableColumn<?>... columns) throws IllegalArgumentException {
@@ -241,7 +241,7 @@ public class TreeTableFormat extends Tab
* Returns the number of spaces to add on the left margin for each indentation level.
* The default value is 4.
*
- * @return The current indentation.
+ * @return the current indentation.
*/
public int getIndentation() {
return indentation;
@@ -252,8 +252,8 @@ public class TreeTableFormat extends Tab
* If the new indentation is smaller than the {@linkplain #getVerticalLinePosition()
* vertical line position}, then the later is also set to the given indentation value.
*
- * @param indentation The new indentation.
- * @throws IllegalArgumentException If the given value is negative.
+ * @param indentation the new indentation.
+ * @throws IllegalArgumentException if the given value is negative.
*/
public void setIndentation(final int indentation) throws IllegalArgumentException {
ArgumentChecks.ensurePositive("indentation", indentation);
@@ -269,7 +269,7 @@ public class TreeTableFormat extends Tab
* The default value is 2, which means that the vertical line is drawn below the third
* letter of the root label.
*
- * @return The current vertical line position.
+ * @return the current vertical line position.
*/
public int getVerticalLinePosition() {
return verticalLinePosition;
@@ -279,8 +279,8 @@ public class TreeTableFormat extends Tab
* Sets the position of the vertical line, relative to the position of the root label.
* The given value can not be greater than the {@linkplain #getIndentation() indentation}.
*
- * @param verticalLinePosition The new vertical line position.
- * @throws IllegalArgumentException If the given value is negative or greater than the indentation.
+ * @param verticalLinePosition the new vertical line position.
+ * @throws IllegalArgumentException if the given value is negative or greater than the indentation.
*/
public void setVerticalLinePosition(final int verticalLinePosition) throws IllegalArgumentException {
ArgumentChecks.ensureBetween("verticalLinePosition", 0, indentation, verticalLinePosition);
@@ -300,9 +300,9 @@ public class TreeTableFormat extends Tab
* The returned array may contain {@code null} elements, which means that the values
* in that column can be stored as {@code String}s.
*
- * @param mandatoy {@code true} if an exception shall be thrown for unrecognized types,
- * or {@code false} for storing a {@code null} value in the array instead.
- * @throws IllegalStateException If {@code mandatory} is {@code true} and a column
+ * @param mandatoy {@code true} if an exception shall be thrown for unrecognized types, or
+ * {@code false} for storing a {@code null} value in the array instead.
+ * @throws IllegalStateException if {@code mandatory} is {@code true} and a column
* contains values of an unsupported type.
*/
final Format[] getFormats(final TableColumn<?>[] columns, final boolean mandatory) throws IllegalStateException {
@@ -341,10 +341,10 @@ public class TreeTableFormat extends Tab
* <li>Parsing stops at first empty line (ignoring whitespaces), or at the end of the given text.</li>
* </ul>
*
- * @param text The character sequence for the tree to parse.
- * @param pos The position where to start the parsing.
- * @return The parsed tree, or {@code null} if the given character sequence can not be parsed.
- * @throws ParseException If an error occurred while parsing a node value.
+ * @param text the character sequence for the tree to parse.
+ * @param pos the position where to start the parsing.
+ * @return the parsed tree, or {@code null} if the given character sequence can not be parsed.
+ * @throws ParseException if an error occurred while parsing a node value.
*/
@Override
@SuppressWarnings("null")
@@ -365,7 +365,7 @@ public class TreeTableFormat extends Tab
while (endOfLine > indexOfLineStart) {
final int c = text.charAt(endOfLine-1);
if (c != '\r' && c != '\n') break;
- endOfLine--; // Skip trailing '\r' and '\n'.
+ endOfLine--; // Skip trailing '\r' and '\n'.
}
/*
* Skip leading spaces using Character.isSpaceChar(\u2026) instead than isWhitespace(\u2026)
@@ -373,7 +373,7 @@ public class TreeTableFormat extends Tab
* need to consider line feeds since they were handled by the lines just above.
*/
boolean hasChar = false;
- int i; // The indentation of current line.
+ int i; // The indentation of current line.
for (i=indexOfLineStart; i<endOfLine;) {
final int c = Character.codePointAt(text, i);
if (!Character.isSpaceChar(c)) {
@@ -385,7 +385,7 @@ public class TreeTableFormat extends Tab
i += Character.charCount(c);
}
if (!hasChar) {
- break; // The line contains only whitespaces.
+ break; // The line contains only whitespaces.
}
/*
* Go back to the fist non-space character (should be '\u2500'). We do that in case the
@@ -480,12 +480,12 @@ public class TreeTableFormat extends Tab
* Parses the given string using a format appropriate for the type of values in
* the given column, and stores the value in the given node.
*
- * @param V The type of values in the given column.
- * @param node The node in which to set the value.
- * @param column The column in which to set the value.
- * @param format The format to use for parsing the value, or {@code null}.
- * @param text The textual representation of the value.
- * @throws ParseException If an error occurred while parsing.
+ * @param V the type of values in the given column.
+ * @param node the node in which to set the value.
+ * @param column the column in which to set the value.
+ * @param format the format to use for parsing the value, or {@code null}.
+ * @param text the textual representation of the value.
+ * @throws ParseException if an error occurred while parsing.
*/
private <V> void parseValue(final TreeTable.Node node, final TableColumn<V> column,
final Format format, final String text) throws ParseException
@@ -607,9 +607,9 @@ public class TreeTableFormat extends Tab
/**
* Creates a new instance which will write to the given appendable.
*
- * @param out Where to format the tree.
- * @param column The columns of the tree table to format.
- * @param parentObjects An initially empty {@link IdentityHashMap}.
+ * @param out where to format the tree.
+ * @param column the columns of the tree table to format.
+ * @param parentObjects an initially empty {@link IdentityHashMap}.
*/
Writer(final Appendable out, final TableColumn<?>[] columns, final Map<Object,Object> parentObjects) {
super(columns.length >= 2 ? new TableAppender(out, "") : out);
@@ -646,13 +646,13 @@ public class TreeTableFormat extends Tab
/**
* Appends a textual representation of the given value.
*
- * @param value The value to format (may be {@code null}).
- * @param recursive {@code true} if this method is invoking itself for writing collection values.
+ * @param value the value to format (may be {@code null}).
+ * @param recursive {@code true} if this method is invoking itself for writing collection values.
*/
private void formatValue(final Object value, final boolean recursive) throws IOException {
final CharSequence text;
if (value == null) {
- text = " "; // String for missing value.
+ text = " "; // String for missing value.
} else if (columnFormat != null) {
if (columnFormat instanceof CompoundFormat<?>) {
formatValue((CompoundFormat<?>) columnFormat, value);
@@ -741,8 +741,8 @@ public class TreeTableFormat extends Tab
* Appends the string representation of the given node and all its children.
* This method invokes itself recursively.
*
- * @param node The node to format.
- * @param level Indentation level. The first level is 0.
+ * @param node the node to format.
+ * @param level indentation level. The first level is 0.
*/
final void format(final TreeTable.Node node, final int level) throws IOException {
for (int i=0; i<level; i++) {
@@ -812,9 +812,9 @@ public class TreeTableFormat extends Tab
* representation of the {@linkplain TreeTable.Node#getValue(TableColumn) value in that column}
* using the formatter obtained by a call to {@link #getFormat(Class)}.
*
- * @param tree The tree to format.
- * @param toAppendTo Where to format the tree.
- * @throws IOException If an error occurred while writing to the given appendable.
+ * @param tree the tree to format.
+ * @param toAppendTo where to format the tree.
+ * @throws IOException if an error occurred while writing to the given appendable.
*
* @see TreeTables#toString(TreeTable)
*/
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractInternationalString.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractInternationalString.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractInternationalString.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractInternationalString.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -78,7 +78,7 @@ public abstract class AbstractInternatio
* Returns the length of the string in the {@linkplain Locale#getDefault() default locale}.
* This is the length of the string returned by {@link #toString()}.
*
- * @return Length of the string in the default locale.
+ * @return length of the string in the default locale.
*/
@Override
public int length() {
@@ -89,8 +89,8 @@ public abstract class AbstractInternatio
* Returns the character of the string in the {@linkplain Locale#getDefault() default locale}
* at the specified index. This is a character of the string returned by {@link #toString()}.
*
- * @param index The index of the character.
- * @return The character at the specified index.
+ * @param index the index of the character.
+ * @return the character at the specified index.
* @throws IndexOutOfBoundsException if the specified index is out of bounds.
*/
@Override
@@ -103,9 +103,9 @@ public abstract class AbstractInternatio
* The subsequence is a {@link String} object starting with the character value at the specified
* index and ending with the character value at index {@code end - 1}.
*
- * @param start The start index, inclusive.
- * @param end The end index, exclusive.
- * @return The specified subsequence.
+ * @param start the start index, inclusive.
+ * @param end the end index, exclusive.
+ * @return the specified subsequence.
* @throws IndexOutOfBoundsException if {@code start} or {@code end} is out of range.
*/
@Override
@@ -133,8 +133,8 @@ public abstract class AbstractInternatio
* other subclasses will take {@code null} as a synonymous of the root locale. In order to
* ensure determinist behavior, client code are encouraged to specify only non-null values.
*
- * @param locale The desired locale for the string to be returned.
- * @return The string in the given locale if available, or in an
+ * @param locale the desired locale for the string to be returned.
+ * @return the string in the given locale if available, or in an
* implementation-dependent fallback locale otherwise.
*
* @see Locale#getDefault()
@@ -150,7 +150,7 @@ public abstract class AbstractInternatio
* <p>All methods from {@link CharSequence} operate on this string.
* This string is also used as the criterion for {@linkplain Comparable natural ordering}.</p>
*
- * @return The string in the default locale.
+ * @return the string in the default locale.
*/
@Override
public synchronized String toString() {
@@ -173,11 +173,11 @@ public abstract class AbstractInternatio
* {@linkplain #toString(Locale) toString}(formatter.{@linkplain Formatter#locale()})
* </code></blockquote>
*
- * @param formatter The formatter to use for formatting this string.
- * @param flags A bitmask of {@link FormattableFlags} values.
- * @param width The minimum number of characters, or -1 if none.
- * @param precision The maximum number of characters (before expanding to the {@code width}),
- * or -1 for no restriction.
+ * @param formatter the formatter to use for formatting this string.
+ * @param flags a bitmask of {@link FormattableFlags} values.
+ * @param width the minimum number of characters, or -1 if none.
+ * @param precision the maximum number of characters (before expanding to the {@code width}),
+ * or -1 for no restriction.
*/
@Override
public void formatTo(final Formatter formatter, final int flags, final int width, final int precision) {
@@ -189,9 +189,9 @@ public abstract class AbstractInternatio
* the string in the {@linkplain Locale#getDefault() default locale}, as returned
* by {@link #toString()}.
*
- * @param object The string to compare with this string.
- * @return A negative number if this string is before the given string, a positive
- * number if after, or 0 if equals.
+ * @param object the string to compare with this string.
+ * @return a negative number if this string is before the given string,
+ * a positive number if after, or 0 if equals.
*/
@Override
public int compareTo(final InternationalString object) {
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -96,7 +96,7 @@ import org.apache.sis.internal.jdk8.JDK8
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @since 0.3
- * @version 0.7
+ * @version 0.8
* @module
*/
public final class Types extends Static {
@@ -798,4 +798,18 @@ public final class Types extends Static
}
return copy;
}
+
+ /**
+ * Returns the given international string in the given locale, or {@code null} if the given string is null.
+ * If the given locale is {@code null}, then the {@code i18n}�default locale is used.
+ *
+ * @param i18n the international string to get as a localized string, or {@code null} if none.
+ * @param locale the desired locale, or {@code null}�for the {@code i18n}�default locale.
+ * @return the localized string, or {@code null}�if {@code i18n} is {@code null}.
+ *
+ * @since 0.8
+ */
+ public static String toString(final InternationalString i18n, final Locale locale) {
+ return (i18n == null) ? null : (locale == null) ? i18n.toString() : i18n.toString(locale);
+ }
}
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java?rev=1776698&r1=1776697&r2=1776698&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java [UTF-8] Sat Dec 31 07:44:10 2016
@@ -363,10 +363,10 @@ public final class Logging extends Stati
*
* The message is fetched using Exception.getMessage() instead than getLocalizedMessage()
* because in a client-server architecture, we want the locale on the server-side instead
- * than the locale on the client side.
+ * than the locale on the client side. See LocalizedException policy.
*/
final StringBuilder buffer = new StringBuilder(256).append(Classes.getShortClassName(error));
- String message = error.getMessage(); // Targeted to system administrators.
+ String message = error.getMessage(); // Targeted to system administrators (see above).
if (message != null) {
buffer.append(": ").append(message);
}