001/*
002 * Units of Measurement TCK
003 * Copyright © 2005-2023, 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.*;
033import javax.measure.format.QuantityFormat;
034import javax.measure.format.UnitFormat;
035
036import java.util.Arrays;
037import java.util.Collection;
038import java.util.ServiceLoader;
039
040/**
041 * Libraries that implement this JSR and want to be tested with this TCK must implement this
042 * interface and register it using the {@link ServiceLoader}.
043 *
044 * @author Werner Keil
045 * @version 2.1, December 5, 2022
046 * @since 1.0
047 */
048public interface ServiceConfiguration{
049
050    /**
051     * Return a collection with all {@link Quantity} classes that are implemented. The list
052     * must not be empty and should contain <b>every</b> quantity class implemented.<p>
053     * This enables the TCK to check in addition to the basic implementation compliance, if
054     * according {@code ServiceProvider} is registered/available.
055     *
056     * @return a collection with all implemented amount classes, not null.
057     */
058    @SuppressWarnings("rawtypes")
059    Collection<Class> getQuantityClasses();
060
061    /**
062     * List a collection of {@link Unit} implementations.<p>
063     * This enables the TCK to check the basic implementation compliance.
064     *
065     * @return a collection with Unit implementations to be tested.
066     */
067    @SuppressWarnings("rawtypes")
068    Collection<Class> getUnitClasses();
069
070    /**
071     * List a collection of {@link Dimension} implementations.<p>
072     * This enables the TCK to check the basic implementation compliance.
073     *
074     * @return a collection with {@link Dimension} implementations to be tested.
075     */
076    @SuppressWarnings("rawtypes")
077    Collection<Class> getDimensionClasses();
078
079    /**
080     * List a collection of {@link Prefix} implementations.<p>
081     * This enables the TCK to check the basic implementation compliance.
082     *
083     * @return a collection with {@link Prefix} implementations to be tested.
084     * @since 2.0
085     */
086    @SuppressWarnings("rawtypes")
087    default Collection<Class> getPrefixClasses() {
088                return Arrays.asList(new Class[] { BinaryPrefix.class, MetricPrefix.class });
089        }
090
091    /**
092     * Return a collection with all supported {@link Quantity} types. The list
093     * must not return <code>null</code>, but could be empty in certain profiles.
094     *
095     * @return the list of quantity types to be checked, not <code>null</code>.
096     * It is allowed to return an empty list here, which will return a collection with all implemented quantity classes, not null.
097     */
098    @SuppressWarnings("rawtypes")
099    Collection<Class<? extends Quantity>> getSupportedQuantityTypes();
100
101    /**
102     * Returns a matching unit for the specified quantity type.
103     * This is a "helper method" to avoid direct references to {@code SystemOfUnits} or implementations in profiles without SPI.
104     *
105     * @param <Q>
106     *            the compile-time quantity type.
107     * @param quantityType
108     *            the quantity type.
109     * @return the unit for the specified quantity.
110     */
111    public <Q extends Quantity<Q>> Unit<Q> getUnit4Type(Class<Q> quantityType);
112
113    /**
114     * This method allows instances of Unit to be tested for requirements and recommendations.
115     *
116     * @return the list of units to be checked, not null. It is allowed to return an empty list here, which will
117     * disable certain TCK tests, e.g. if the result isn't needed by a particular profile.
118     */
119    Collection<? extends Unit<?>> getUnits4Test();
120
121    /**
122     * This method returns the base dimensions to be tested for requirements and recommendations.
123     *
124     * @return the list of base dimensions to be checked, not null. It is allowed to return an empty list here, which will
125     * disable certain TCK tests, e.g. if the result isn't needed by a particular profile.
126     */
127    Collection<Dimension> getBaseDimensions();
128
129    /**
130     * This method allows instances of UnitConverter to be tested for requirements and recommendations.
131     *
132     * @return the list of unit converters to be checked, not null. It is allowed to return an empty list here, which will
133     * disable TCK tests for UnitConverter instances.
134     */
135    Collection<UnitConverter> getUnitConverters4Test();
136
137    /**
138     * This method allows instances of UnitFormat to be tested for requirements and recommendations.
139     *
140     * @return the list of unit converters to be checked, not null. It is allowed to return an empty list here, which will
141     * disable certain TCK tests, e.g. if the result isn't needed by a particular profile.
142     */
143    Collection<UnitFormat> getUnitFormats4Test();
144
145    /**
146     * This method allows instances of QuantityFormat to be tested for requirements and recommendations.
147     *
148     * @return the list of unit converters to be checked, not null. It is allowed to return an empty list here, which will
149     * disable certain TCK tests, e.g. if the result isn't needed by a particular profile.
150     * @since 2.0
151     */
152    Collection<QuantityFormat> getQuantityFormats4Test();
153}