001/*
002 * International System of Units (SI)
003 * Copyright (c) 2005-2019, 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.quantity.impl;
031
032import javax.measure.Unit;
033import javax.measure.quantity.Temperature;
034
035import tech.units.indriya.quantity.NumberQuantity;
036
037/**
038 * @author Werner Keil
039 * @version 1.5.2, $Date: 2016-10-23 $
040 */
041/**
042 * @author werner
043 *
044 */
045/**
046 * @author werner
047 *
048 */
049public final class TemperatureAmount extends NumberQuantity<Temperature> implements Temperature {
050
051    /**
052     * 
053     */
054    // private static final long serialVersionUID = -3444768963576192753L;
055
056    private final Double scalar; // value in reference unit
057
058    private final Double value; // value in unit (Unit unit)
059
060    /**
061     * @param number a number
062     * @param unit a unit
063     */
064    public TemperatureAmount(Number number, Unit<Temperature> unit) {
065        super(number, unit);
066        scalar = (double) 0;
067        value = (double) 0;
068    }
069
070    /**
071     * @return if value is zero
072     */
073    public boolean isZero() {
074        return (value != null) && 0d == (value);
075    }
076
077    /**
078     * @param t
079     * @return
080     */
081    public TemperatureAmount add(TemperatureAmount t) {
082        return new TemperatureAmount(this.value + t.value, getUnit());
083    }
084
085    public TemperatureAmount subtract(TemperatureAmount d1) {
086        return new TemperatureAmount(this.value - d1.value, getUnit());
087    }
088
089    protected boolean eq(TemperatureAmount dq) {
090        return dq != null && dq.getValue().equals(getValue()) && dq.getUnit().equals(getUnit())
091                && dq.getScalar().equals(getScalar());
092    }
093
094    /**
095     * @param v
096     * @return
097     */
098    public TemperatureAmount divide(Double v) {
099        return new TemperatureAmount(value / v, getUnit());
100    }
101
102    //
103    // protected TemperatureAmount convert(TemperatureUnit newUnit) {
104    // return new TemperatureAmount(value.doubleValue() /
105    // newUnit.getFactor(), newUnit);
106    // }
107
108    /**
109     * @return
110     */
111    public Double getScalar() {
112        return scalar;
113    }
114
115    // @Override
116    // public String toString(boolean withUnit, boolean withSpace, int
117    // precision) {
118    // final StringBuilder sb = new StringBuilder();
119    // sb.append(getValue());
120    // if(withUnit) {
121    // if(withSpace) sb.append(" ");
122    // sb.append(getUnit().getSymbol());
123    // }
124    // return sb.toString();
125    // }
126
127    // @Override
128    // public String showInUnit(Unit<?> u, int precision,
129    // SimpleFormat.Show showWith) {
130    // return showInUnit(u, value, precision, showWith);
131    // }
132    //
133    // @Override
134    // public Number getValue() {
135    // return value;
136    // }
137    //
138    // @Override
139    // public Unit<Temperature> getUnit() {
140    // return unit;
141    // }
142
143    @Override
144    public TemperatureAmount multiply(Number that) {
145        return new TemperatureAmount(value * that.doubleValue(), getUnit());
146    }
147
148    @Override
149    public TemperatureAmount divide(Number that) {
150        return divide((Double) that);
151    }
152
153    // @Override
154    // public BigDecimal decimalValue(Unit<Temperature> unit, MathContext ctx)
155    // throws ArithmeticException {
156    // // TODO Auto-generated method stub
157    // return null;
158    // }
159}