/** * Multiplies this unit dimension by another. * @param that The other unit dimension. * @return The product of this unit dimension multiplied * by the other. */ public UnitDimension multiplyBy(UnitDimension that) { return new UnitDimension(mult(that)); }
/** * Returns the hash code of this instance. * * @return The hash code of this instance. */ @Override public int hashCode() { return this instanceof BaseUnit ? System.identityHashCode(this) : dimension.hashCode(); }
/** * Indicates if this derived unit is dimensionless. * * @return <code>true</code> if and only if this derived unit is * dimensionless. */ public boolean isDimensionless() { return dimension.isDimensionless(); }
/** * Raises this unit dimension to a power. * @param power The power. * @return The result of raising this unit dimension * to the power. */ public UnitDimension raiseTo(int power) { return new UnitDimension(pow(power)); }
private StringBuffer format(DerivedUnit unit, StringBuffer buf) { Factor[] factors = unit.getDimension().getFactors(); Arrays.sort(factors, factorComparator); for (int i = 0; i < factors.length; i++) format(factors[i], buf).append('.'); if (factors.length != 0) buf.setLength(buf.length() - 1); return buf; }
new UnitDimension() + '"'); UnitDimension timeDimension = new UnitDimension( BaseUnit.getOrCreate( UnitName.newUnitName("second", null, "s"), System.out.println("timeDimension = \"" + timeDimension + '"'); UnitDimension lengthDimension = new UnitDimension( BaseUnit.getOrCreate( UnitName.newUnitName("meter", null, "m"), System.out.println( "lengthDimension.isReciprocalOf(timeDimension) = \"" + lengthDimension.isReciprocalOf(timeDimension) + '"'); UnitDimension hertzDimension = timeDimension.raiseTo(-1); System.out.println("hertzDimension = \"" + hertzDimension + '"'); System.out.println( "hertzDimension.isReciprocalOf(timeDimension) = \"" + hertzDimension.isReciprocalOf(timeDimension) + '"'); System.out.println("lengthDimension.divideBy(timeDimension) = \"" + lengthDimension.divideBy(timeDimension) + '"'); System.out.println( "lengthDimension.divideBy(timeDimension).raiseTo(2) = \"" + lengthDimension.divideBy(timeDimension).raiseTo(2) + '"');
/** * Multiplies this derived unit by another. * * @param that * The other unit. * @return The product of the two units. * @throws MultiplyException * Can't multiply these units. */ @Override protected Unit myMultiplyBy(final Unit that) throws MultiplyException { Unit result; if (dimension.getRank() == 0) { result = that; } else { if (!(that instanceof DerivedUnit)) { result = that.multiplyBy(this); } else { final UnitDimension thatDimension = ((DerivedUnit) that) .getDimension(); result = thatDimension.getRank() == 0 ? this : new DerivedUnitImpl(dimension .multiplyBy(thatDimension)); } } return result; }
/** * Divides this derived unit by another. * * @param that * The other unit. * @return The quotient of the two units. * @throws OperationException * Can't divide these units. */ @Override protected Unit myDivideBy(final Unit that) throws OperationException { Unit result; if (dimension.getRank() == 0) { result = that.raiseTo(-1); } else { if (!(that instanceof DerivedUnit)) { result = that.divideInto(this); } else { final UnitDimension thatDimension = ((DerivedUnit) that) .getDimension(); result = thatDimension.getRank() == 0 ? this : new DerivedUnitImpl(dimension.divideBy(thatDimension)); } } return result; }
/** * Constructs a dimensionless derived unit from nothing. */ protected DerivedUnitImpl() { // dimensionless derived unit this(new UnitDimension(), dimensionlessID()); }
/** * Indicates if this derived unit is the reciprocal of another derived unit * (e.g. "second" and "hertz"). * * @param that * The other, derived unit. */ public final boolean isReciprocalOf(final DerivedUnit that) { return dimension.isReciprocalOf(that.getDimension()); }
/** * Returns the quantity dimension of this derived unit. * * @return The quantity dimension of this derived unit. */ public final QuantityDimension getQuantityDimension() { return getDimension().getQuantityDimension(); }
/** * Indicates if this derived unit is semantically identical to an object. * * @param object * The object * @return <code>true</code> if and only if this derived unit is * semantically identical to <code> * object</code>. */ @Override public boolean equals(final Object object) { if (this == object) { return true; } if (!(object instanceof DerivedUnit)) { return false; } final DerivedUnit that = (DerivedUnit) object; return (this instanceof BaseUnit && that instanceof BaseUnit) ? false : dimension.equals(that.getDimension()); }
private StringBuffer format(DerivedUnit unit, StringBuffer buf) { Factor[] factors = unit.getDimension().getFactors(); Arrays.sort(factors, factorComparator); for (int i = 0; i < factors.length; i++) format(factors[i], buf).append('.'); if (factors.length != 0) buf.setLength(buf.length() - 1); return buf; }
new UnitDimension() + '"'); UnitDimension timeDimension = new UnitDimension( BaseUnit.getOrCreate( UnitName.newUnitName("second", null, "s"), System.out.println("timeDimension = \"" + timeDimension + '"'); UnitDimension lengthDimension = new UnitDimension( BaseUnit.getOrCreate( UnitName.newUnitName("meter", null, "m"), System.out.println( "lengthDimension.isReciprocalOf(timeDimension) = \"" + lengthDimension.isReciprocalOf(timeDimension) + '"'); UnitDimension hertzDimension = timeDimension.raiseTo(-1); System.out.println("hertzDimension = \"" + hertzDimension + '"'); System.out.println( "hertzDimension.isReciprocalOf(timeDimension) = \"" + hertzDimension.isReciprocalOf(timeDimension) + '"'); System.out.println("lengthDimension.divideBy(timeDimension) = \"" + lengthDimension.divideBy(timeDimension) + '"'); System.out.println( "lengthDimension.divideBy(timeDimension).raiseTo(2) = \"" + lengthDimension.divideBy(timeDimension).raiseTo(2) + '"');
/** * Raises this unit dimension to a power. * @param power The power. * @return The result of raising this unit dimension * to the power. */ public UnitDimension raiseTo(int power) { return new UnitDimension(pow(power)); }
/** * Multiplies this derived unit by another. * * @param that * The other unit. * @return The product of the two units. * @throws MultiplyException * Can't multiply these units. */ @Override protected Unit myMultiplyBy(final Unit that) throws MultiplyException { Unit result; if (dimension.getRank() == 0) { result = that; } else { if (!(that instanceof DerivedUnit)) { result = that.multiplyBy(this); } else { final UnitDimension thatDimension = ((DerivedUnit) that) .getDimension(); result = thatDimension.getRank() == 0 ? this : new DerivedUnitImpl(dimension .multiplyBy(thatDimension)); } } return result; }
/** * Divides this derived unit by another. * * @param that * The other unit. * @return The quotient of the two units. * @throws OperationException * Can't divide these units. */ @Override protected Unit myDivideBy(final Unit that) throws OperationException { Unit result; if (dimension.getRank() == 0) { result = that.raiseTo(-1); } else { if (!(that instanceof DerivedUnit)) { result = that.divideInto(this); } else { final UnitDimension thatDimension = ((DerivedUnit) that) .getDimension(); result = thatDimension.getRank() == 0 ? this : new DerivedUnitImpl(dimension.divideBy(thatDimension)); } } return result; }
/** * Constructs a dimensionless derived unit from nothing. */ protected DerivedUnitImpl() { // dimensionless derived unit this(new UnitDimension(), dimensionlessID()); }
/** * Indicates if this derived unit is the reciprocal of another derived unit * (e.g. "second" and "hertz"). * * @param that * The other, derived unit. */ public final boolean isReciprocalOf(final DerivedUnit that) { return dimension.isReciprocalOf(that.getDimension()); }
/** * Returns the quantity dimension of this derived unit. * * @return The quantity dimension of this derived unit. */ public final QuantityDimension getQuantityDimension() { return getDimension().getQuantityDimension(); }