From d53ee57e6709b2e7b6857394878667851dd4b037 Mon Sep 17 00:00:00 2001 From: Werner Keil Date: Tue, 17 Nov 2020 00:50:32 +0100 Subject: [PATCH] 200: Add a variant option when obtaining a UnitFormat from FormatService. Task-Url: https://github.com/unitsofmeasurement/unit-api/issues/200 --- pom.xml | 2 +- .../javax/measure/format/ParserException.java | 81 ------------------- .../java/javax/measure/spi/FormatService.java | 7 +- .../javax/measure/format/ParserException.java | 81 ------------------- .../test/format/MeasurementParseTest.java | 13 ++- 5 files changed, 11 insertions(+), 173 deletions(-) delete mode 100644 src/main/java/javax/measure/format/ParserException.java delete mode 100644 src/main/jdk9/javax/measure/format/ParserException.java diff --git a/pom.xml b/pom.xml index d9349877..34e7b30f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 javax.measure unit-api - 2.1.1-SNAPSHOT + 2.1 Units of Measurement API bundle http://unitsofmeasurement.github.io/unit-api/ diff --git a/src/main/java/javax/measure/format/ParserException.java b/src/main/java/javax/measure/format/ParserException.java deleted file mode 100644 index 0135e20e..00000000 --- a/src/main/java/javax/measure/format/ParserException.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Units of Measurement API - * Copyright (c) 2014-2020, Jean-Marie Dautelle, Werner Keil, Otavio Santana. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions - * and the following disclaimer in the documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of JSR-385 nor the names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package javax.measure.format; - -/** - * Signals that an error has been reached unexpectedly while parsing. - * - * @author Werner Keil - * @version 1.2, October 7, 2018 - * @since 1.0 - * @deprecated Use {@link MeasurementParseException}, this exception will be removed in a future version, it is here for backward compatibility only. - */ -@Deprecated -public class ParserException extends MeasurementParseException { - - private static final long serialVersionUID = -3179553925611520368L; - - /** - * Constructs a ParserException with the specified detail message, parsed text and index. A detail message is a String that describes this - * particular exception. - * - * @param message - * the detail message - * @param parsedData - * the parsed text, should not be null - * @param position - * the position where the error was found while parsing. - */ - public ParserException(String message, CharSequence parsedData, int position) { - super(message, parsedData, position); - } - - /** - * Constructs a ParserException with the parsed text and offset. A detail message is a String that describes this particular exception. - * - * @param parsedData - * the parsed text, should not be null - * @param position - * the position where the error is found while parsing. - */ - public ParserException(CharSequence parsedData, int position) { - super(parsedData, position); - } - - /** - * Constructs a ParserException with the specified cause. - * - * @param cause - * the root cause - */ - public ParserException(Throwable cause) { - super(cause); - } -} diff --git a/src/main/java/javax/measure/spi/FormatService.java b/src/main/java/javax/measure/spi/FormatService.java index 58f4344b..c6949435 100644 --- a/src/main/java/javax/measure/spi/FormatService.java +++ b/src/main/java/javax/measure/spi/FormatService.java @@ -38,7 +38,7 @@ * This interface represent the service to obtain instances of {@link UnitFormat} and {@link QuantityFormat}. * * @author Werner Keil - * @version 2.0, November 4, 2020 + * @version 2.1, November 16, 2020 * @since 2.0 */ public interface FormatService { @@ -93,10 +93,11 @@ public static enum FormatType { * Returns the unit format having the specified name or {@code null} if none. * * For example {@code getUnitFormat("Simple")} to return a simple {@link UnitFormat} implementation.
- * The variant is an arbitrary value to allow a variation of a UnitFormat, for example case sensitive vs. case insensitive UCUM format. + * The variant is an arbitrary value to allow a variation of a UnitFormat, for example case sensitive vs. case insensitive UCUM format. + *

If no variant is applicable, the UnitFormat matching the name only is returned.

* @param name * the name of the format. - * @param variant Any arbitrary value used to indicate a variation of a UnitFormat. + * @param variant any arbitrary value used to indicate a variation of a UnitFormat. * @return the corresponding unit format. */ UnitFormat getUnitFormat(String name, String variant); diff --git a/src/main/jdk9/javax/measure/format/ParserException.java b/src/main/jdk9/javax/measure/format/ParserException.java deleted file mode 100644 index d967e77a..00000000 --- a/src/main/jdk9/javax/measure/format/ParserException.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Units of Measurement API - * Copyright (c) 2014-2020, Jean-Marie Dautelle, Werner Keil, Otavio Santana. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions - * and the following disclaimer in the documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of JSR-385 nor the names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package javax.measure.format; - -/** - * Signals that an error has been reached unexpectedly while parsing. - * - * @author Werner Keil - * @version 2.0, March 29, 2020 - * @since 1.0 - * @deprecated Use {@link MeasurementParseException}, this exception will be removed in a future version, it is here for backward compatibility only. - */ -@Deprecated(forRemoval=true, since="2.0") -public class ParserException extends MeasurementParseException { - - private static final long serialVersionUID = -3179553925611520368L; - - /** - * Constructs a ParserException with the specified detail message, parsed text and index. A detail message is a String that describes this - * particular exception. - * - * @param message - * the detail message - * @param parsedData - * the parsed text, should not be null - * @param position - * the position where the error was found while parsing. - */ - public ParserException(String message, CharSequence parsedData, int position) { - super(message, parsedData, position); - } - - /** - * Constructs a ParserException with the parsed text and offset. A detail message is a String that describes this particular exception. - * - * @param parsedData - * the parsed text, should not be null - * @param position - * the position where the error is found while parsing. - */ - public ParserException(CharSequence parsedData, int position) { - super(parsedData, position); - } - - /** - * Constructs a ParserException with the specified cause. - * - * @param cause - * the root cause - */ - public ParserException(Throwable cause) { - super(cause); - } -} diff --git a/src/test/java/javax/measure/test/format/MeasurementParseTest.java b/src/test/java/javax/measure/test/format/MeasurementParseTest.java index a02ba233..05c0af9d 100644 --- a/src/test/java/javax/measure/test/format/MeasurementParseTest.java +++ b/src/test/java/javax/measure/test/format/MeasurementParseTest.java @@ -30,7 +30,6 @@ package javax.measure.test.format; import javax.measure.format.MeasurementParseException; -import javax.measure.format.ParserException; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -49,22 +48,22 @@ public void testExceptionWithMessage() { @Test public void testOldExceptionWithMessageDataAndPos() { - assertThrows(ParserException.class, () -> { - throw new ParserException("Error", " ", 0); + assertThrows(MeasurementParseException.class, () -> { + throw new MeasurementParseException("Error", " ", 0); }); } @Test public void testOldExceptionWithMessageAndPos() { - assertThrows(ParserException.class, () -> { - throw new ParserException("Error", 0); + assertThrows(MeasurementParseException.class, () -> { + throw new MeasurementParseException("Error", 0); }); } @Test public void testOldExceptionWithCause() { - assertThrows(ParserException.class, () -> { - throw new ParserException(new IllegalArgumentException("Error")); + assertThrows(MeasurementParseException.class, () -> { + throw new MeasurementParseException(new IllegalArgumentException("Error")); }); } }