001/*
002 * Units of Measurement TCK
003 * Copyright © 2005-2020, Jean-Marie Dautelle, Werner Keil, Otavio Santana.
004 *
005 * All rights reserved.
006 *
007 * Redistribution and use in source and binary forms, with or without modification,
008 * are permitted provided that the following conditions are met:
009 *
010 * 1. Redistributions of source code must retain the above copyright notice,
011 *    this list of conditions and the following disclaimer.
012 *
013 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
014 *    and the following disclaimer in the documentation and/or other materials provided with the distribution.
015 *
016 * 3. Neither the name of JSR-385 nor the names of its contributors may be used to endorse or promote products
017 *    derived from this software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
021 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
023 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
026 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030package tech.units.tck.util;
031
032import javax.measure.Dimension;
033import javax.measure.Prefix;
034import javax.measure.Quantity;
035import javax.measure.Unit;
036import javax.measure.UnitConverter;
037import javax.measure.format.QuantityFormat;
038import javax.measure.format.UnitFormat;
039
040import java.util.Collection;
041import java.util.ServiceLoader;
042
043/**
044 * Libraries that implement this JSR and want to be tested with this TCK must implement this
045 * interface and register it using the {@link ServiceLoader}.
046 *
047 * @author Werner Keil
048 * @version 2.0, November 15, 2020
049 * @since 1.0
050 */
051public interface ServiceConfiguration{
052
053    /**
054     * Return a collection with all {@link Quantity} classes that are implemented. The list
055     * must not be empty and should contain <b>every</b> quantity class implemented.<p>
056     * This enables the TCK to check in addition to the basic implementation compliance, if
057     * according {@code ServiceProvider} is registered/available.
058     *
059     * @return a collection with all implemented amount classes, not null.
060     */
061    @SuppressWarnings("rawtypes")
062    Collection<Class> getQuantityClasses();
063    
064    /**
065     * List a collection of {@link Unit} implementations.<p>
066     * This enables the TCK to check the basic implementation compliance.
067     *
068     * @return a collection with Unit implementations to be tested.
069     */
070    @SuppressWarnings("rawtypes")
071    Collection<Class> getUnitClasses();
072    
073    /**
074     * List a collection of {@link Dimension} implementations.<p>
075     * This enables the TCK to check the basic implementation compliance.
076     *
077     * @return a collection with {@link Dimension} implementations to be tested.
078     */
079    @SuppressWarnings("rawtypes")
080    Collection<Class> getDimensionClasses();
081    
082    /**
083     * List a collection of {@link Prefix} implementations.<p>
084     * This enables the TCK to check the basic implementation compliance.
085     *
086     * @return a collection with {@link Prefix} implementations to be tested.
087     * @since 2.0
088     */
089    @SuppressWarnings("rawtypes")
090    Collection<Class> getPrefixClasses();
091    // Although this is already given by the API it allows to check for additional implementations
092    
093    /**
094     * Return a collection with all supported {@link Quantity} types. The list
095     * must not return <code>null</code>, but could be empty in certain profiles.
096     * 
097     * @return the list of quantity types to be checked, not <code>null</code>. 
098     * It is allowed to return an empty list here, which will return a collection with all implemented amount classes, not null.
099     */
100    @SuppressWarnings("rawtypes")
101    Collection<Class<? extends Quantity>> getSupportedQuantityTypes();
102    
103    /**
104     * Returns a matching unit for the specified quantity type.
105     * This is a "helper method" to avoid direct references to {@code SystemOfUnits} or implementations in profiles without SPI.
106     * 
107     * @param <Q>
108     *            the compile-time quantity type.
109     * @param quantityType
110     *            the quantity type.
111     * @return the unit for the specified quantity.
112     */
113    public <Q extends Quantity<Q>> Unit<Q> getUnit4Type(Class<Q> quantityType);
114
115    /**
116     * This method allows instances of Unit to be tested for requirements and recommendations.
117     *
118     * @return the list of units to be checked, not null. It is allowed to return an empty list here, which will
119     * disable certain TCK tests, e.g. if the result isn't needed by a particular profile.
120     */
121    Collection<? extends Unit<?>> getUnits4Test();
122    
123    /**
124     * This method returns the base dimensions to be tested for requirements and recommendations.
125     *
126     * @return the list of base dimensions to be checked, not null. It is allowed to return an empty list here, which will
127     * disable certain TCK tests, e.g. if the result isn't needed by a particular profile.
128     */
129    Collection<Dimension> getBaseDimensions();
130
131    /**
132     * This method allows instances of UnitConverter to be tested for requirements and recommendations.
133     *
134     * @return the list of unit converters to be checked, not null. It is allowed to return an empty list here, which will
135     * disable TCK tests for UnitConverter instances.
136     */
137    Collection<UnitConverter> getUnitConverters4Test();
138    
139    /**
140     * This method allows instances of UnitFormat to be tested for requirements and recommendations.
141     *
142     * @return the list of unit converters to be checked, not null. It is allowed to return an empty list here, which will
143     * disable certain TCK tests, e.g. if the result isn't needed by a particular profile.
144     */
145    Collection<UnitFormat> getUnitFormats4Test();
146    
147    /**
148     * This method allows instances of QuantityFormat to be tested for requirements and recommendations.
149     *
150     * @return the list of unit converters to be checked, not null. It is allowed to return an empty list here, which will
151     * disable certain TCK tests, e.g. if the result isn't needed by a particular profile.
152     * @since 2.0
153     */
154    Collection<QuantityFormat> getQuantityFormats4Test();
155}