sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1766816 - in /sis/branches/JDK8: core/sis-utility/src/main/java/org/apache/sis/internal/system/ core/sis-utility/src/main/java/org/apache/sis/measure/ core/sis-utility/src/main/resources/META-INF/services/ core/sis-utility/src/test/java/or...
Date Thu, 27 Oct 2016 13:17:56 GMT
Author: desruisseaux
Date: Thu Oct 27 13:17:55 2016
New Revision: 1766816

URL: http://svn.apache.org/viewvc?rev=1766816&view=rev
Log:
Declare a javax.measure.spi.ServiceProvider for the JSR-363 implementation.

Added:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitServices.java
  (with props)
    sis/branches/JDK8/core/sis-utility/src/main/resources/META-INF/services/javax.measure.spi.ServiceProvider
  (with props)
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitServicesTest.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Loggers.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitRegistry.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
    sis/branches/JDK8/ide-project/NetBeans/build.xml

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Loggers.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Loggers.java?rev=1766816&r1=1766815&r2=1766816&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Loggers.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Loggers.java
[UTF-8] Thu Oct 27 13:17:55 2016
@@ -57,6 +57,11 @@ public final class Loggers extends Stati
     public static final String MATH = "org.apache.sis.math";
 
     /**
+     * The logger for operations related to units of measurement.
+     */
+    public static final String MEASURE = "org.apache.sis.measure";
+
+    /**
      * The logger for operations related to JDBC operations.
      */
     public static final String SQL = "org.apache.sis.sql";

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java?rev=1766816&r1=1766815&r2=1766816&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
[UTF-8] Thu Oct 27 13:17:55 2016
@@ -291,6 +291,8 @@ public class UnitFormat extends Format i
      * instructs this formatter to use the “meter” spelling instead of “metre”.
      *
      * @param  locale  the new locale for this {@code UnitFormat}.
+     *
+     * @see UnitServices#getUnitFormat(String)
      */
     public void setLocale(final Locale locale) {
         ArgumentChecks.ensureNonNull("locale", locale);

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitRegistry.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitRegistry.java?rev=1766816&r1=1766815&r2=1766816&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitRegistry.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitRegistry.java
[UTF-8] Thu Oct 27 13:17:55 2016
@@ -55,21 +55,18 @@ final class UnitRegistry implements Syst
 
     /**
      * Identifies units defined outside the SI system but accepted for use with SI.
-     * The {@link #SI} value can be used as a bitmask for identifying the SI or accepted
units.
      */
-    static final byte ACCEPTED = 3;
-
-    // All following constants shall have an even value (unless accepted for use with SI).
+    static final byte ACCEPTED = 2;
 
     /**
      * Identifies units defined for use in British imperial system.
      */
-    static final byte IMPERIAL = 2;
+    static final byte IMPERIAL = 4;
 
     /**
      * Identifies units defined in another system than the above.
      */
-    static final byte OTHER = 4;
+    static final byte OTHER = 8;
 
     /**
      * All {@link UnitDimension}, {@link SystemUnit} or {@link ConventionalUnit} that are
hard-coded in Apache SIS.
@@ -180,6 +177,17 @@ final class UnitRegistry implements Syst
     }
 
     /**
+     * Name of this system of units.
+     */
+    final String name;
+
+    /**
+     * The bitmask for units to include. Can be any combination of {@link #SI}, {@link #ACCEPTED},
+     * {@link #IMPERIAL} or {@link #OTHER} bits.
+     */
+    private final int includes;
+
+    /**
      * The value returned by {@link #getUnits()}, created when first needed.
      */
     private transient Set<Unit<?>> units;
@@ -187,16 +195,17 @@ final class UnitRegistry implements Syst
     /**
      * Creates a new unit system.
      */
-    UnitRegistry() {
+    UnitRegistry(final String name, final int includes) {
+        this.name     = name;
+        this.includes = includes;
     }
 
     /**
-     * Returns the well-known acronym that stands for "Système International"
-     * together with the name of other systems used.
+     * Returns the name of this system of units.
      */
     @Override
     public String getName() {
-        return "SI and others";
+        return name;
     }
 
     /**
@@ -220,8 +229,11 @@ final class UnitRegistry implements Syst
                 if (units == null) {
                     units = new HashSet<>();
                     for (final Object value : HARD_CODED.values()) {
-                        if (value instanceof Unit<?>) {
-                            units.add((Unit<?>) value);
+                        if (value instanceof AbstractUnit<?>) {
+                            final AbstractUnit<?> unit = (AbstractUnit<?>) value;
+                            if ((unit.scope & includes) != 0) {
+                                units.add(unit);
+                            }
                         }
                     }
                     units = Collections.unmodifiableSet(units);

Added: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitServices.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitServices.java?rev=1766816&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitServices.java
(added)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitServices.java
[UTF-8] Thu Oct 27 13:17:55 2016
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.measure;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
+import javax.measure.Quantity;
+import javax.measure.format.UnitFormat;
+import javax.measure.spi.QuantityFactory;
+import javax.measure.spi.ServiceProvider;
+import javax.measure.spi.SystemOfUnits;
+import javax.measure.spi.SystemOfUnitsService;
+import javax.measure.spi.UnitFormatService;
+import org.apache.sis.internal.util.UnmodifiableArrayList;
+import org.apache.sis.internal.system.Loggers;
+import org.apache.sis.util.logging.Logging;
+import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.CharSequences;
+import org.apache.sis.util.Characters;
+
+
+/**
+ * The central point from which all unit services (parsing, formatting, listing, <i>etc</i>)
can be obtained.
+ * Apache SIS does not use this class (SIS rather uses {@link Units} pre-defined constants
and {@link UnitFormat}
+ * directly since they are designed specifically for SIS needs).
+ * This class is provided for allowing other applications to discover Apache SIS implementation
of JSR-363
+ * without direct dependency. A {@code UnitServices} instance can be obtained by call to
{@link #current()}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+public class UnitServices extends ServiceProvider implements SystemOfUnitsService, UnitFormatService
{
+    /**
+     * All system of units known to this provider.
+     * The last element in the array is the default system with all units known to SIS.
+     */
+    private final UnitRegistry[] systems;
+
+    /**
+     * Creates a new service provider. {@code UnitServices} should not be instantiated
+     * directly unless the caller wants specifically the Apache SIS implementation.
+     * For obtaining the default implementation, use {@link #current()} instead.
+     */
+    public UnitServices() {
+        systems = new UnitRegistry[] {
+            new UnitRegistry("SI",            UnitRegistry.SI),
+            new UnitRegistry("SI + accepted", UnitRegistry.SI | UnitRegistry.ACCEPTED),
+            new UnitRegistry("Imperial",      UnitRegistry.IMPERIAL),
+            new UnitRegistry("SI + other",    -1)                       // Must be last.
+        };
+    }
+
+    /**
+     * Returns the default system of units used by Apache SIS.
+     * This include the International System of Units (SI) together with some imperial units
and other units.
+     * This system includes at least all the constants defined in the {@link Units} class.
+     *
+     * @return the system of units used by Apache SIS.
+     */
+    @Override
+    public SystemOfUnits getSystemOfUnits() {
+        return systems[systems.length - 1];
+    }
+
+    /**
+     * Returns the system of units having the specified name, or {@code null} if none.
+     * The argument can be any name in the following table:
+     *
+     * <table class="sis">
+     *   <caption>Available system of units</caption>
+     *   <tr><th>Name</th>          <th>Examples</th></tr>
+     *   <tr><td>SI</td>            <td>m, km, m³, s, m∕s, K,
°C, hPa, rad, µrad</td></tr>
+     *   <tr><td>SI + accepted</td> <td>s, min, h, m∕s, km∕h,
°, ′, ″, ha</td></tr>
+     *   <tr><td>Imperial</td>      <td>in, ft, mi (statute mile)</td></tr>
+     *   <tr><td>SI + other</td>    <td>m, m∕s, km∕h, ft, mi,
M (nautical mile)</td></tr>
+     * </table>
+     *
+     * The search for name is case-insensitive and ignore whitespaces.
+     *
+     * @param  name  the name of the desired system of units.
+     * @return the system of units for the given name, or {@code null} if none.
+     */
+    @Override
+    public SystemOfUnits getSystemOfUnits(final String name) {
+        ArgumentChecks.ensureNonEmpty("name", name);
+        for (final UnitRegistry s : systems) {
+            if (CharSequences.equalsFiltered(s.name, name, Characters.Filter.UNICODE_IDENTIFIER,
true)) {
+                return s;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the list of all available systems of units.
+     *
+     * @return list of available systems of units.
+     */
+    @Override
+    public Collection<SystemOfUnits> getAvailableSystemsOfUnits() {
+        return UnmodifiableArrayList.wrap(systems);
+    }
+
+    /**
+     * Returns the service to obtain a {@link SystemOfUnits} instances.
+     * The default implementation returns {@code this} since this {@code UnitServices} class
+     * implements directly all relevant interfaces. The methods related to system of units
are:
+     *
+     * <ul>
+     *   <li>{@link #getSystemOfUnits()}</li>
+     *   <li>{@link #getSystemOfUnits(String)}</li>
+     *   <li>{@link #getAvailableSystemsOfUnits()}</li>
+     * </ul>
+     *
+     * @return the service to obtain a {@link SystemOfUnits}, or {@code null} if none.
+     */
+    @Override
+    public SystemOfUnitsService getSystemOfUnitsService() {
+        return this;
+    }
+
+    /**
+     * Returns an unit format instance for human-readable unit symbols in the default locale.
+     * The format style is {@link org.apache.sis.measure.UnitFormat.Style#SYMBOL}.
+     * This style requires support for Unicode characters;
+     * for example square metres are formatted as “m²”, not “m2”.
+     *
+     * @return a {@link org.apache.sis.measure.UnitFormat} instance for unit symbols.
+     */
+    @Override
+    public UnitFormat getUnitFormat() {
+        return new org.apache.sis.measure.UnitFormat(Locale.getDefault(Locale.Category.FORMAT));
+    }
+
+    /**
+     * Returns the unit format for the given name. The argument can be the name of
+     * any value in the {@link org.apache.sis.measure.UnitFormat.Style} enumeration.
+     * The argument can be any name in the following table:
+     *
+     * <table class="sis">
+     *   <caption>Available unit format name</caption>
+     *   <tr><th>Name</th>      <th>Examples</th></tr>
+     *   <tr><td>SYMBOL</td>    <td>km, m³, m∕s, N⋅m, K, °C,
hPa, rad, µrad</td></tr>
+     *   <tr><td>UCUM</td>      <td>km, m3, m/s, N.m</td></tr>
+     *   <tr><td>NAME</td>      <td>kilometre, cubic metre, metres
per second</td></tr>
+     * </table>
+     *
+     * The {@code "NAME"} format is locale-sensitive. The format locale can be modified by
a call
+     * to {@link org.apache.sis.measure.UnitFormat#setLocale(Locale)} on the returned object.
+     *
+     * @param  name the name of the desired format.
+     * @return the corresponding unit format, or {@code null} if none.
+     */
+    @Override
+    public UnitFormat getUnitFormat(String name) {
+        final Locale locale = Locale.getDefault(Locale.Category.FORMAT);
+        name = name.toUpperCase(locale).trim();
+        final org.apache.sis.measure.UnitFormat.Style style;
+        try {
+            style = org.apache.sis.measure.UnitFormat.Style.valueOf(name);
+        } catch (IllegalArgumentException e) {
+            // JSR-363 specification mandate that we return null.
+            Logging.recoverableException(Logging.getLogger(Loggers.MEASURE), UnitServices.class,
"getUnitFormat", e);
+            return null;
+        }
+        org.apache.sis.measure.UnitFormat f = new org.apache.sis.measure.UnitFormat(locale);
+        f.setStyle(style);
+        return f;
+    }
+
+    /**
+     * Returns a list of available format names. The default implementation returns the names
+     * of all values in the {@link org.apache.sis.measure.UnitFormat.Style} enumeration.
+     *
+     * @return list of available formats.
+     */
+    @Override
+    public Set<String> getAvailableFormatNames() {
+        final Set<String> names = new HashSet<>(4);
+        for (final Enum<?> e : org.apache.sis.measure.UnitFormat.Style.values()) {
+            names.add(e.name());
+        }
+        return names;
+    }
+
+    /**
+     * Returns the service to obtain a {@link UnitFormat} instances.
+     * The default implementation returns {@code this} since this {@code UnitServices} class
+     * implements directly all relevant interfaces. The methods related to unit formats are:
+     *
+     * <ul>
+     *   <li>{@link #getUnitFormat()}</li>
+     *   <li>{@link #getUnitFormat(String)}</li>
+     *   <li>{@link #getAvailableFormatNames()}</li>
+     * </ul>
+     *
+     * @return the service to obtain a {@link UnitFormat}, or {@code null} if none.
+     */
+    @Override
+    public UnitFormatService getUnitFormatService() {
+        return this;
+    }
+
+    /**
+     * Return a factory for the given {@code Quantity} type, or {@code null} if none.
+     * Current implementation returns {@code null}.
+     *
+     * @param  <Q>   compile-time value of the {@code type} argument.
+     * @param  type  type of the desired the quantity.
+     * @return the service to obtain {@link Quantity} instances, or {@code null} if none.
+     */
+    @Override
+    public <Q extends Quantity<Q>> QuantityFactory<Q> getQuantityFactory(final
Class<Q> type) {
+        return null;
+    }
+}

Propchange: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitServices.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitServices.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK8/core/sis-utility/src/main/resources/META-INF/services/javax.measure.spi.ServiceProvider
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/resources/META-INF/services/javax.measure.spi.ServiceProvider?rev=1766816&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/resources/META-INF/services/javax.measure.spi.ServiceProvider
(added)
+++ sis/branches/JDK8/core/sis-utility/src/main/resources/META-INF/services/javax.measure.spi.ServiceProvider
[UTF-8] Thu Oct 27 13:17:55 2016
@@ -0,0 +1,2 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more contributor license
agreements.
+org.apache.sis.measure.UnitServices

Propchange: sis/branches/JDK8/core/sis-utility/src/main/resources/META-INF/services/javax.measure.spi.ServiceProvider
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-utility/src/main/resources/META-INF/services/javax.measure.spi.ServiceProvider
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitServicesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitServicesTest.java?rev=1766816&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitServicesTest.java
(added)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitServicesTest.java
[UTF-8] Thu Oct 27 13:17:55 2016
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.measure;
+
+import java.util.Set;
+import java.util.Arrays;
+import java.util.Locale;
+import javax.measure.Unit;
+import javax.measure.format.UnitFormat;
+import javax.measure.spi.ServiceProvider;
+import org.apache.sis.test.DependsOn;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Test {@link UnitServicesTest}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+@DependsOn(UnitsTest.class)
+public final strictfp class UnitServicesTest {
+    /**
+     * Tests the default system of units.
+     */
+    @Test
+    public void testDefaultSystemOfUnits() {
+        final ServiceProvider provider = ServiceProvider.current();
+        Set<? extends Unit<?>> units = provider.getSystemOfUnitsService().getSystemOfUnits().getUnits();
+        assertTrue("METRE",                units.contains(Units.METRE));
+        assertTrue("KILOMETRE",            units.contains(Units.KILOMETRE));
+        assertTrue("CUBIC_METRE",          units.contains(Units.CUBIC_METRE));
+        assertTrue("METRES_PER_SECOND",    units.contains(Units.METRES_PER_SECOND));
+        assertTrue("KILOMETRES_PER_HOUR",  units.contains(Units.KILOMETRES_PER_HOUR));
+        assertTrue("NAUTICAL_MILE",        units.contains(Units.NAUTICAL_MILE));
+        assertTrue("STATUTE_MILE",         units.contains(Units.STATUTE_MILE));
+        assertTrue("DEGREE",               units.contains(Units.DEGREE));
+        assertTrue("RADIAN",               units.contains(Units.RADIAN));
+        assertTrue("GRAD",                 units.contains(Units.GRAD));
+    }
+
+    /**
+     * Tests the "SI" system of units.
+     */
+    @Test
+    public void testSI() {
+        final ServiceProvider provider = ServiceProvider.current();
+        Set<? extends Unit<?>> units = provider.getSystemOfUnitsService().getSystemOfUnits("SI").getUnits();
+        assertTrue ("METRE",                units.contains(Units.METRE));
+        assertTrue ("KILOMETRE",            units.contains(Units.KILOMETRE));
+        assertTrue ("CUBIC_METRE",          units.contains(Units.CUBIC_METRE));
+        assertTrue ("METRES_PER_SECOND",    units.contains(Units.METRES_PER_SECOND));
+        assertFalse("KILOMETRES_PER_HOUR",  units.contains(Units.KILOMETRES_PER_HOUR));
+        assertFalse("NAUTICAL_MILE",        units.contains(Units.NAUTICAL_MILE));
+        assertFalse("STATUTE_MILE",         units.contains(Units.STATUTE_MILE));
+        assertFalse("DEGREE",               units.contains(Units.DEGREE));
+        assertTrue ("RADIAN",               units.contains(Units.RADIAN));
+        assertFalse("GRAD",                 units.contains(Units.GRAD));
+    }
+
+    /**
+     * Tests the "SI + accepted" system of units.
+     */
+    @Test
+    public void testAccepted() {
+        final ServiceProvider provider = ServiceProvider.current();
+        Set<? extends Unit<?>> units = provider.getSystemOfUnitsService().getSystemOfUnits("SI
+ accepted").getUnits();
+        assertTrue ("METRE",                units.contains(Units.METRE));
+        assertTrue ("KILOMETRE",            units.contains(Units.KILOMETRE));
+        assertTrue ("CUBIC_METRE",          units.contains(Units.CUBIC_METRE));
+        assertTrue ("METRES_PER_SECOND",    units.contains(Units.METRES_PER_SECOND));
+        assertTrue ("KILOMETRES_PER_HOUR",  units.contains(Units.KILOMETRES_PER_HOUR));
+        assertFalse("NAUTICAL_MILE",        units.contains(Units.NAUTICAL_MILE));
+        assertFalse("STATUTE_MILE",         units.contains(Units.STATUTE_MILE));
+        assertTrue ("DEGREE",               units.contains(Units.DEGREE));
+        assertTrue ("RADIAN",               units.contains(Units.RADIAN));
+        assertFalse("GRAD",                 units.contains(Units.GRAD));
+    }
+
+    /**
+     * Tests the "Imperial" system of units.
+     */
+    @Test
+    public void testImperial() {
+        final ServiceProvider provider = ServiceProvider.current();
+        Set<? extends Unit<?>> units = provider.getSystemOfUnitsService().getSystemOfUnits("Imperial").getUnits();
+        assertFalse("METRE",                units.contains(Units.METRE));
+        assertFalse("KILOMETRE",            units.contains(Units.KILOMETRE));
+        assertFalse("CUBIC_METRE",          units.contains(Units.CUBIC_METRE));
+        assertFalse("METRES_PER_SECOND",    units.contains(Units.METRES_PER_SECOND));
+        assertFalse("KILOMETRES_PER_HOUR",  units.contains(Units.KILOMETRES_PER_HOUR));
+        assertTrue ("STATUTE_MILE",         units.contains(Units.STATUTE_MILE));
+        assertFalse("DEGREE",               units.contains(Units.DEGREE));
+        assertFalse("RADIAN",               units.contains(Units.RADIAN));
+        assertFalse("GRAD",                 units.contains(Units.GRAD));
+    }
+
+    /**
+     * Tests {@link UnitServices#getAvailableFormatNames()}.
+     */
+    @Test
+    public void testGetAvailableFormatNames() {
+        final ServiceProvider provider = ServiceProvider.current();
+        assertSetEquals(Arrays.asList("SYMBOL", "UCUM", "NAME"),
+                provider.getUnitFormatService().getAvailableFormatNames());
+    }
+
+    /**
+     * Tests {@link UnitServices#getUnitFormat(String)}.
+     */
+    @Test
+    public void testGetUnitFormat() {
+        final ServiceProvider provider = ServiceProvider.current();
+        final UnitFormat f = provider.getUnitFormatService().getUnitFormat("name");
+        ((org.apache.sis.measure.UnitFormat) f).setLocale(Locale.US);
+        assertEquals("CUBIC_METRE", "cubic meter", f.format(Units.CUBIC_METRE));
+    }
+}

Propchange: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitServicesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitServicesTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1766816&r1=1766815&r2=1766816&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] Thu Oct 27 13:17:55 2016
@@ -51,7 +51,7 @@ import org.junit.BeforeClass;
     org.apache.sis.util.LocalesTest.class,
     org.apache.sis.util.resources.LoaderTest.class,
     org.apache.sis.util.resources.IndexedResourceBundleTest.class,
-    org.apache.sis.util.ArgumentChecksTest.class, // Uses resources.
+    org.apache.sis.util.ArgumentChecksTest.class,                       // Uses resources.
     org.apache.sis.util.logging.PerformanceLevelTest.class,
     org.apache.sis.util.logging.WarningListenersTest.class,
     org.apache.sis.util.logging.MonolineFormatterTest.class,
@@ -109,6 +109,7 @@ import org.junit.BeforeClass;
     org.apache.sis.measure.ConventionalUnitTest.class,
     org.apache.sis.measure.UnitFormatTest.class,
     org.apache.sis.measure.UnitsTest.class,
+    org.apache.sis.measure.UnitServicesTest.class,
     org.apache.sis.measure.RangeTest.class,
     org.apache.sis.measure.DateRangeTest.class,
     org.apache.sis.measure.NumberRangeTest.class,
@@ -136,7 +137,7 @@ import org.junit.BeforeClass;
     org.apache.sis.internal.converter.ArrayConverterTest.class,
     org.apache.sis.internal.converter.ConverterRegistryTest.class,
     org.apache.sis.internal.converter.SystemRegistryTest.class,
-    org.apache.sis.internal.converter.NumberConverterTest.class, // Shall be after SystemRegistryTest.
+    org.apache.sis.internal.converter.NumberConverterTest.class,        // Shall be after
SystemRegistryTest.
 
     // XML most basic types.
     org.apache.sis.xml.XLinkTest.class,

Modified: sis/branches/JDK8/ide-project/NetBeans/build.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/ide-project/NetBeans/build.xml?rev=1766816&r1=1766815&r2=1766816&view=diff
==============================================================================
--- sis/branches/JDK8/ide-project/NetBeans/build.xml (original)
+++ sis/branches/JDK8/ide-project/NetBeans/build.xml Thu Oct 27 13:17:55 2016
@@ -77,6 +77,13 @@
       </fileset>
     </concat>
 
+    <!-- Units of Measurement implementations to be loaded by ServiceLoader. -->
+    <concat destfile="${build.classes.dir}/META-INF/services/javax.measure.spi.ServiceProvider"
encoding="UTF-8" fixlastline="yes">
+      <fileset dir="${project.root}">
+        <include name="*/*/src/main/resources/META-INF/services/javax.measure.spi.ServiceProvider"/>
+      </fileset>
+    </concat>
+
 
 
     <!-- ==== GeoAPI service providers =============================================================================
-->



Mime
View raw message