001/* 002 * Units of Measurement Enum Implementation 003 * Copyright © 2005-2021, Werner Keil and others. 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, Unit-API nor the names of their 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.uom.impl.enums.unit; 031 032import tech.uom.lib.common.util.DescriptiveEnum; 033import tech.uom.impl.enums.quantity.ShirtSize; 034 035import java.util.HashMap; 036import java.util.Map; 037 038import javax.measure.Dimension; 039import javax.measure.IncommensurableException; 040import javax.measure.Prefix; 041import javax.measure.Quantity; 042import javax.measure.UnconvertibleException; 043import javax.measure.Unit; 044import javax.measure.UnitConverter; 045 046/** 047 * @author Werner Keil 048 * @version 1.0, $Date: 2020-10-03 $ 049 */ 050public enum ShirtSizeUnit implements Unit<ShirtSize>, 051 DescriptiveEnum<ShirtSizeUnit> { 052 SML("S-M-L", "Small to Large"); 053 054 private final String symbol; 055 private final String description; 056 057 private ShirtSizeUnit(final String symbol, final String name) { 058 this.symbol = symbol; 059 this.description = name; 060 } 061 062 public String getSymbol() { 063 return symbol; 064 } 065 066 public Unit<ShirtSize> getSystemUnit() { 067 return SML; 068 } 069 070 public String getName() { 071 return name(); 072 } 073 074 public Map<? extends Unit<ShirtSize>, Integer> getBaseUnits() { 075 Map<Unit<ShirtSize>, Integer> prodUnits = new HashMap<Unit<ShirtSize>, Integer>(); 076 prodUnits.put(SML, Integer.valueOf(1)); 077 return prodUnits; 078 } 079 080 public static ShirtSizeUnit getBySymbol(String symbol) { 081 if (SML.getSymbol().equals(symbol)) { 082 return SML; 083 } 084 return SML; 085 } 086 087 public UnitConverter getConverterTo(Unit<ShirtSize> that) 088 throws UnconvertibleException { 089 // currently unused 090 return null; 091 } 092 093 public UnitConverter getConverterToAny(Unit<?> that) 094 throws IncommensurableException, UnconvertibleException { 095 // currently unused 096 return null; 097 } 098 099 public Unit<ShirtSize> alternate(String s) { 100 return null; // To change body of implemented methods use File | 101 // Settings | File TemplateBuilder. 102 } 103 104 public Dimension getDimension() { 105 return SimpleDimension.INSTANCE; 106 } 107 108 public Unit<?> inverse() { 109 return this; 110 } 111 112 public Unit<ShirtSize> divide(double v) { 113 return null; // To change body of implemented methods use File | 114 // Settings | File TemplateBuilder. 115 } 116 117 public Unit<?> divide(Unit<?> unit) { 118 return null; // To change body of implemented methods use File | 119 // Settings | File TemplateBuilder. 120 } 121 122 public boolean isCompatible(Unit<?> that) { 123 if (that instanceof ShirtSizeUnit) 124 return true; 125 return false; 126 } 127 128 @SuppressWarnings("unchecked") 129 public <T extends Quantity<T>> Unit<T> asType(Class<T> tClass) { 130 Unit<T> metricUnit = (Unit<T>) getSystemUnit(); 131 if ((metricUnit == null) || metricUnit.isCompatible(this)) 132 return (Unit<T>) this; 133 throw new ClassCastException("The unit: " + this //$NON-NLS-1$ 134 + " is not of parameterized type " + tClass); //$NON-NLS-1$ 135 } 136 137 public Unit<ShirtSize> multiply(double factor) { 138 return this; 139 } 140 141 public Unit<?> multiply(Unit<?> that) { 142 return this; 143 } 144 145 public Unit<?> pow(int n) { 146 return this; 147 } 148 149 public Unit<?> root(int n) { 150 return this; 151 } 152 153 public Unit<ShirtSize> transform(UnitConverter operation) { 154 return this; 155 } 156 157 public Unit<ShirtSize> shift(double v) { 158 return this; 159 } 160 161 public String getDescription() { 162 return description; 163 } 164 165 public DescriptiveEnum<ShirtSizeUnit>[] dValues() { 166 return ShirtSizeUnit.values(); 167 } 168 169 @Override 170 public Unit<ShirtSize> prefix(Prefix prefix) { 171 return this.multiply(Math.pow(prefix.getValue().doubleValue(), prefix.getExponent())); 172 } 173 174 @Override 175 public Unit<ShirtSize> shift(Number offset) { 176 return this; 177 } 178 179 @Override 180 public Unit<ShirtSize> multiply(Number multiplier) { 181 return this; 182 } 183 184 @Override 185 public Unit<ShirtSize> divide(Number divisor) { 186 return this; 187 } 188 189 @Override 190 public boolean isEquivalentTo(Unit<ShirtSize> that) { 191 return equals(that); 192 } 193}