001/* 002 * Units of Measurement Implementation for Java SE 003 * Copyright (c) 2005-2017, Jean-Marie Dautelle, Werner Keil, V2COM. 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-363 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 tec.uom.se; 031 032import java.io.Serializable; 033 034import javax.measure.Quantity; 035import javax.measure.Unit; 036 037/** 038 * Quantity specialized for the Java SE platform. It extends {@link Quantity} with {@linkplain Comparable} and {@linkplain Serializable } 039 * 040 * @see {@link Quantity} 041 * @author otaviojava 042 * @author werner 043 * @param <Q> 044 * @since 1.0 045 */ 046public interface ComparableQuantity<Q extends Quantity<Q>> extends Quantity<Q>, Comparable<Quantity<Q>>, Serializable { 047 048 /** 049 * @see Quantity#add(Quantity) 050 */ 051 ComparableQuantity<Q> add(Quantity<Q> that); 052 053 /** 054 * @see Quantity#subtract(Quantity) 055 */ 056 ComparableQuantity<Q> subtract(Quantity<Q> that); 057 058 /** 059 * @see Quantity#divide(Quantity) 060 */ 061 ComparableQuantity<?> divide(Quantity<?> that); 062 063 /** 064 * @see Quantity#divide(Number) 065 */ 066 ComparableQuantity<Q> divide(Number that); 067 068 /** 069 * @see Quantity#multiply(Quantity) 070 */ 071 ComparableQuantity<?> multiply(Quantity<?> multiplier); 072 073 /** 074 * @see Quantity#multiply(Number) 075 */ 076 ComparableQuantity<Q> multiply(Number multiplier); 077 078 /** 079 * @see Quantity#inverse() 080 */ 081 ComparableQuantity<?> inverse(); 082 083 /** 084 * invert and already cast to defined quantityClass 085 * 086 * @param quantityClass 087 * Quantity to be converted 088 * @see Quantity#inverse() 089 * @see Quantity#asType(Class) 090 */ 091 <T extends Quantity<T>> ComparableQuantity<T> inverse(Class<T> quantityClass); 092 093 /** 094 * @see Quantity#to(Unit) 095 */ 096 ComparableQuantity<Q> to(Unit<Q> unit); 097 098 /** 099 * @see Quantity#asType(Class) 100 */ 101 <T extends Quantity<T>> ComparableQuantity<T> asType(Class<T> type) throws ClassCastException; 102 103 /** 104 * Compares two instances of {@link Quantity <Q>}. Conversion of unit can happen if necessary 105 * 106 * @param that 107 * the {@code quantity<Q>} to be compared with this instance. 108 * @return {@code true} if {@code that > this}. 109 * @throws NullPointerException 110 * if the that is null 111 */ 112 boolean isGreaterThan(Quantity<Q> that); 113 114 /** 115 * Compares two instances of {@link Quantity <Q>}, doing the conversion of unit if necessary. 116 * 117 * @param that 118 * the {@code quantity<Q>} to be compared with this instance. 119 * @return {@code true} if {@code that >= this}. 120 * @throws NullPointerException 121 * if the that is null 122 */ 123 boolean isGreaterThanOrEqualTo(Quantity<Q> that); 124 125 /** 126 * Compares two instances of {@link Quantity <Q>}, doing the conversion of unit if necessary. 127 * 128 * @param that 129 * the {@code quantity<Q>} to be compared with this instance. 130 * @return {@code true} if {@code that < this}. 131 * @throws NullPointerException 132 * if the quantity is null 133 */ 134 boolean isLessThan(Quantity<Q> that); 135 136 /** 137 * Compares two instances of {@link Quantity <Q>}, doing the conversion of unit if necessary. 138 * 139 * @param that 140 * the {@code quantity<Q>} to be compared with this instance. 141 * @return {@code true} if {@code that < this}. 142 * @throws NullPointerException 143 * if the quantity is null 144 */ 145 boolean isLessThanOrEqualTo(Quantity<Q> that); 146 147 /** 148 * Compares two instances of {@link Quantity <Q>}, doing the conversion of unit if necessary. 149 * 150 * @param that 151 * the {@code quantity<Q>} to be compared with this instance. 152 * @return {@code true} if {@code that < this}. 153 * @throws NullPointerException 154 * if the quantity is null 155 */ 156 boolean isEquivalentTo(Quantity<Q> that); 157 158 /** 159 * Multiply and cast the {@link ComparableQuantity} 160 * 161 * @param that 162 * quantity to be multiplied 163 * @param asTypeQuantity 164 * quantity to be converted 165 * @return the QuantityOperations multiplied and converted 166 * @see Quantity#divide(Quantity) 167 * @see Quantity#asType(Class) 168 * @exception NullPointerException 169 */ 170 <T extends Quantity<T>, E extends Quantity<E>> ComparableQuantity<E> divide(Quantity<T> that, Class<E> asTypeQuantity); 171 172 /** 173 * Divide and cast the {@link ComparableQuantity} 174 * 175 * @param that 176 * quantity to be divided 177 * @param asTypeQuantity 178 * quantity to be converted 179 * @return the QuantityOperations multiplied and converted 180 * @see QuantityOperations 181 * @see QuantityOperations#of(Quantity, Class) 182 * @see Quantity#asType(Class) 183 * @see Quantity#multiply(Quantity) 184 * @exception NullPointerException 185 */ 186 <T extends Quantity<T>, E extends Quantity<E>> ComparableQuantity<E> multiply(Quantity<T> that, Class<E> asTypeQuantity); 187}