/*
* JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
* Copyright (C) 2006 - JScience (http://jscience.org/)
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software is
* freely granted, provided that this notice is preserved.
*/
package javax.measure.unit;
import javax.measure.converter.UnitConverter;
import javax.measure.quantity.Quantity;
/**
* This class represents the multi-radix units (such as "hour:min:sec").
* Instances of this class are created using the {@link Unit#compound
* Unit.compound} method.
*
* Examples of compound units:[code]
* Unit HOUR_MINUTE_SECOND = HOUR.compound(MINUTE).compound(SECOND);
* Unit DEGREE_MINUTE_ANGLE = DEGREE_ANGLE.compound(MINUTE_ANGLE);
* [/code]
*
* @author Jean-Marie Dautelle
* @version 3.1, April 22, 2006
*/
public final class CompoundUnit extends DerivedUnit {
/**
* Holds the higher unit.
*/
private final Unit _high;
/**
* Holds the lower unit.
*/
private final Unit _low;
/**
* Creates a compound unit from the specified units.
*
* @param high the high unit.
* @param low the lower unit(s)
* @throws IllegalArgumentException if both units do not the same system
* unit.
*/
CompoundUnit(Unit high, Unit low) {
if (!high.getStandardUnit().equals(low.getStandardUnit()))
throw new IllegalArgumentException(
"Both units do not have the same system unit");
_high = high;
_low = low;
}
/**
* Returns the lower unit of this compound unit.
*
* @return the lower unit.
*/
public Unit getLower() {
return _low;
}
/**
* Returns the higher unit of this compound unit.
*
* @return the higher unit.
*/
public Unit getHigher() {
return _high;
}
/**
* Indicates if this compound unit is considered equals to the specified
* object (both are compound units with same composing units in the
* same order).
*
* @param that the object to compare for equality.
* @return true if this and that
* are considered equals; falseotherwise.
*/
public boolean equals(Object that) {
if (this == that)
return true;
if (!(that instanceof CompoundUnit))
return false;
CompoundUnit> thatUnit = (CompoundUnit>) that;
return this._high.equals(thatUnit._high)
&& this._low.equals(thatUnit._low);
}
@Override
public int hashCode() {
return _high.hashCode() ^ _low.hashCode();
}
@Override
public Unit super Q> getStandardUnit() {
return _low.getStandardUnit();
}
@Override
public UnitConverter toStandardUnit() {
return _low.toStandardUnit();
}
private static final long serialVersionUID = 1L;
}
Ads help maintain this website.