001/*
002 * International System of Units (SI)
003 * Copyright (c) 2005-2018, Jean-Marie Dautelle, 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, Units of Measurement nor the names of their contributors may be used to
017 *    endorse or promote products 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 si.uom.impl.quantity;
031
032import javax.measure.Unit;
033import javax.measure.quantity.Temperature;
034
035import tec.uom.se.quantity.NumberQuantity;
036
037/**
038 * @author Werner Keil
039 * @version 1.5.2, $Date: 2015-07-26 $
040 */
041public final class TemperatureAmount extends NumberQuantity<Temperature>
042                implements Temperature {
043
044        /**
045         * 
046         */
047        private static final long serialVersionUID = -3444768963576192753L;
048
049        private final Double scalar; // value in reference unit
050
051        private final Double value; // value in unit (Unit unit)
052
053        public TemperatureAmount(Number number, Unit<Temperature> unit) {
054                super(number, unit);
055                scalar = (double) 0;
056                value = (double) 0;
057        }
058
059        public boolean isZero() {
060                return (value != null) && 0d == (value);
061        }
062
063        public TemperatureAmount add(TemperatureAmount d1) {
064        return new TemperatureAmount(this.value + d1.value, getUnit());
065        }
066
067        public TemperatureAmount subtract(TemperatureAmount d1) {
068        return new TemperatureAmount(this.value - d1.value, getUnit());
069        }
070
071        protected boolean eq(TemperatureAmount dq) {
072                return dq != null && dq.getValue().equals(getValue())
073                                && dq.getUnit().equals(getUnit())
074                                && dq.getScalar().equals(getScalar());
075        }
076
077        public TemperatureAmount divide(Double v) {
078                return new TemperatureAmount(value / v,
079                                getUnit());
080        }
081
082        //
083        // protected TemperatureAmount convert(TemperatureUnit newUnit) {
084        // return new TemperatureAmount(value.doubleValue() /
085        // newUnit.getFactor(), newUnit);
086        // }
087
088        public Double getScalar() {
089                return scalar;
090        }
091
092        // @Override
093        // public String toString(boolean withUnit, boolean withSpace, int
094        // precision) {
095        // final StringBuilder sb = new StringBuilder();
096        // sb.append(getValue());
097        // if(withUnit) {
098        // if(withSpace) sb.append(" ");
099        // sb.append(getUnit().getSymbol());
100        // }
101        // return sb.toString();
102        // }
103
104        // @Override
105        // public String showInUnit(Unit<?> u, int precision,
106        // SimpleFormat.Show showWith) {
107        // return showInUnit(u, value, precision, showWith);
108        // }
109        //
110        // @Override
111        // public Number getValue() {
112        // return value;
113        // }
114        //
115        // @Override
116        // public Unit<Temperature> getUnit() {
117        // return unit;
118        // }
119
120        @Override
121        public TemperatureAmount multiply(Number that) {
122                return new TemperatureAmount(value * that.doubleValue(),
123                                getUnit());
124        }
125
126        @Override
127        public TemperatureAmount divide(Number that) {
128                return divide((Double) that);
129        }
130
131//      @Override
132//      public BigDecimal decimalValue(Unit<Temperature> unit, MathContext ctx)
133//                      throws ArithmeticException {
134//              // TODO Auto-generated method stub
135//              return null;
136//      }
137}