001/*
002 * Units of Measurement API
003 * Copyright (c) 2014-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 javax.measure.test.quantity;
031
032import javax.measure.Quantity;
033import javax.measure.Unit;
034import javax.measure.quantity.Volume;
035import javax.measure.test.unit.AreaUnit;
036import javax.measure.test.unit.DistanceUnit;
037import javax.measure.test.unit.VolumeUnit;
038
039/**
040 * @author Werner Keil
041 * @version 0.6
042 */
043public class VolumeQuantity extends TestQuantity<Volume> {
044    public VolumeQuantity() {
045        super(Volume.class);
046    }
047
048    public VolumeQuantity(double val, VolumeUnit un) {
049        this();
050        value = val;
051        unit = un;
052        scalar = val * unit.getMultFactor();
053    }
054
055    public VolumeQuantity(Number val, Unit un) {
056        this(val.doubleValue(), (VolumeUnit) un);
057    }
058
059    public VolumeQuantity add(VolumeQuantity d1) {
060        VolumeQuantity dn = new VolumeQuantity();
061        Object o = super.add(dn, this, d1, VolumeUnit.REF_UNIT);
062        return (VolumeQuantity) o;
063    }
064
065    public VolumeQuantity subtract(VolumeQuantity d1) {
066        VolumeQuantity dn = new VolumeQuantity();
067        Object o = super.subtract(dn, this, d1, VolumeUnit.REF_UNIT);
068        return (VolumeQuantity) o;
069    }
070
071    public boolean eq(VolumeQuantity d1) {
072        return super.eq(d1);
073    }
074
075    public boolean ne(VolumeQuantity d1) {
076        return super.ne(d1);
077    }
078
079    public boolean gt(VolumeQuantity d1) {
080        return super.gt(d1);
081    }
082
083    public boolean lt(VolumeQuantity d1) {
084        return super.lt(d1);
085    }
086
087    public boolean ge(VolumeQuantity d1) {
088        return super.ge(d1);
089    }
090
091    public boolean le(VolumeQuantity d1) {
092        return super.le(d1);
093    }
094
095    public VolumeQuantity multiply(double v) {
096        return new VolumeQuantity(value * v, (VolumeUnit) unit);
097    }
098
099    public VolumeQuantity divide(double v) {
100        return new VolumeQuantity(value / v, (VolumeUnit) unit);
101    }
102
103    // mixed type operations
104
105    public AreaQuantity divide(DistanceQuantity d1) {
106        VolumeQuantity dq0 = convert(VolumeUnit.cumetre);
107        DistanceQuantity dq1 = d1.convert(DistanceUnit.m);
108        return new AreaQuantity(dq0.value / dq1.value, AreaUnit.sqmetre);
109    }
110
111    public DistanceQuantity divide(AreaQuantity a1) {
112        VolumeQuantity dq0 = convert(VolumeUnit.cumetre);
113        AreaQuantity dq1 = a1.convert(AreaUnit.sqmetre);
114        return new DistanceQuantity(dq0.value / dq1.value, DistanceUnit.m);
115    }
116
117    public VolumeQuantity convert(VolumeUnit newUnit) {
118        return new VolumeQuantity(scalar / newUnit.getMultFactor(), newUnit);
119    }
120
121    public String showInUnits(VolumeUnit u, int precision) {
122        return super.showInUnits(u, precision);
123    }
124
125    public Quantity<?> divide(Quantity<?> that) {
126        // TODO Auto-generated method stub
127        return null;
128    }
129
130    public Quantity<Volume> subtract(Quantity<Volume> that) {
131        // TODO Auto-generated method stub
132        return null;
133    }
134
135    public Quantity<Volume> add(Quantity<Volume> that) {
136        // TODO Auto-generated method stub
137        return null;
138    }
139
140    public Quantity<Volume> divide(Number that) {
141        return divide(that.doubleValue());
142    }
143
144    public Quantity<Volume> inverse() {
145        // TODO Auto-generated method stub
146        return null;
147    }
148
149    public Quantity<Volume> multiply(Number that) {
150        return multiply(that.doubleValue());
151    }
152
153    public Quantity<Volume> to(Unit<Volume> unit) {
154        // TODO Auto-generated method stub
155        return null;
156    }
157
158    public Quantity<?> multiply(Quantity<?> that) {
159        // TODO Auto-generated method stub
160        return null;
161    }
162
163    @Override
164    public Quantity<Volume> negate() {
165        return new VolumeQuantity(-value, getUnit());
166    }
167
168    @SuppressWarnings({ "unchecked", "rawtypes" })
169    public final <T extends Quantity<T>> Quantity<T> asType(Class<T> type) throws ClassCastException {
170        this.getUnit().asType(type); // Raises ClassCastException is dimension
171        // mismatches.
172        return (Quantity) this;
173    }
174}