/** * Indicates if this Factor is the reciprocal of another Factor. * * @param that * The other factor. * @return <code>true</code> if and only if this Factor is the reciprocal of * <code>that</code>. */ public boolean isReciprocalOf(final Factor that) { return getBase().equals(that.getBase()) && getExponent() == -that.getExponent(); }
/** * Raises this Factor to a power. * * @param power * The power by which to raise this Factor. * @return The Factor resulting from raising this Factor to the given power. */ public Factor pow(final int power) { return new Factor(getBase(), getExponent() * power); }
public int compare(Factor f1, Factor f2) { int comp = f2.getExponent() - f1.getExponent(); if (comp == 0) comp = f1.getID().compareTo(f2.getID()); return comp; } };
/** * Constructs from a Factor and an exponent. * * @param factor * The factor. * @param exponent * The exponent. */ public Factor(final Factor factor, final int exponent) { this(factor.getBase(), exponent); }
final int comp = f1.getID().compareTo(f2.getID()); if (comp < 0) { newFactors[k++] = f1; final int exponent = f1.getExponent() + f2.getExponent(); if (exponent != 0) { newFactors[k++] = new Factor(f1, exponent);
/** * Constructs the unit dimension corresponding to a base unit. * @param baseUnit A base unit. */ public UnitDimension(BaseUnit baseUnit) { super(new Factor(baseUnit)); }
/** * Formats a Factor. * * @param factor The factor to be formatted. * @param buf The buffer to append to. * @return The appended-to buffer. */ public StringBuffer format(Factor factor, StringBuffer buf) { return buf.append(factor.toString()); }
/** * Indicates if this dimension is dimensionless. A dimension is * dimensionless if it has no Factor-s or if all Factor-s are, themselves, * dimensionless. * * @return <code>true</code> if and only if this dimension is dimensionless. */ public final boolean isDimensionless() { for (int i = _factors.length; --i >= 0;) { if (!_factors[i].isDimensionless()) { return false; } } return true; }
/** * Returns the hash code of this instance. * * @return The hash code of this instance. */ @Override public int hashCode() { if (hashCode == 0) { int hash = 0; for (int i = 0; i < _factors.length; i++) { hash ^= _factors[i].hashCode(); } hashCode = hash; } return hashCode; }
/** * Raises this dimension to a power. * * @param power * The power to raise this dimension by. * @return The Factor-s of this dimension raised to the power * <code>power</code>. */ protected Factor[] pow(final int power) { Factor[] factors; if (power == 0) { factors = new Factor[0]; } else { factors = getFactors(); if (power != 1) { for (int i = factors.length; --i >= 0;) { factors[i] = factors[i].pow(power); } } } return factors; }
/** * Indicates if this Dimension is the reciprocal of another dimension. * * @param that * The other dimension. * @return <code>true</code> if and only if this dimension is the reciprocal * of the other dimension. */ public final boolean isReciprocalOf(final Dimension that) { final Factor[] theseFactors = _factors; final Factor[] thoseFactors = that._factors; boolean isReciprocalOf; if (theseFactors.length != thoseFactors.length) { isReciprocalOf = false; } else { int i; for (i = theseFactors.length; --i >= 0;) { if (!theseFactors[i].isReciprocalOf(thoseFactors[i])) { break; } } isReciprocalOf = i < 0; } return isReciprocalOf; }
int i = _factors.length; while (--i >= 0) { if (!_factors[i].equals(thatFactors[i])) { break;
/** * Constructs from a Factor and an exponent. * * @param factor * The factor. * @param exponent * The exponent. */ public Factor(final Factor factor, final int exponent) { this(factor.getBase(), exponent); }
final int comp = f1.getID().compareTo(f2.getID()); if (comp < 0) { newFactors[k++] = f1; final int exponent = f1.getExponent() + f2.getExponent(); if (exponent != 0) { newFactors[k++] = new Factor(f1, exponent);
/** * Constructs from a base quantity. * @param baseQuantity The base quantity constituting the dimension. */ public QuantityDimension(BaseQuantity baseQuantity) { super(new Factor(baseQuantity)); }
/** * Formats a Factor. * * @param factor The factor to be formatted. * @param buf The buffer to append to. * @return The appended-to buffer. */ public StringBuffer format(Factor factor, StringBuffer buf) { return buf.append(factor.toString()); }
/** * Indicates if this dimension is dimensionless. A dimension is * dimensionless if it has no Factor-s or if all Factor-s are, themselves, * dimensionless. * * @return <code>true</code> if and only if this dimension is dimensionless. */ public final boolean isDimensionless() { for (int i = _factors.length; --i >= 0;) { if (!_factors[i].isDimensionless()) { return false; } } return true; }
/** * Returns the hash code of this instance. * * @return The hash code of this instance. */ @Override public int hashCode() { if (hashCode == 0) { int hash = 0; for (int i = 0; i < _factors.length; i++) { hash ^= _factors[i].hashCode(); } hashCode = hash; } return hashCode; }
/** * Raises this dimension to a power. * * @param power * The power to raise this dimension by. * @return The Factor-s of this dimension raised to the power * <code>power</code>. */ protected Factor[] pow(final int power) { Factor[] factors; if (power == 0) { factors = new Factor[0]; } else { factors = getFactors(); if (power != 1) { for (int i = factors.length; --i >= 0;) { factors[i] = factors[i].pow(power); } } } return factors; }
/** * Indicates if this Dimension is the reciprocal of another dimension. * * @param that * The other dimension. * @return <code>true</code> if and only if this dimension is the reciprocal * of the other dimension. */ public final boolean isReciprocalOf(final Dimension that) { final Factor[] theseFactors = _factors; final Factor[] thoseFactors = that._factors; boolean isReciprocalOf; if (theseFactors.length != thoseFactors.length) { isReciprocalOf = false; } else { int i; for (i = theseFactors.length; --i >= 0;) { if (!theseFactors[i].isReciprocalOf(thoseFactors[i])) { break; } } isReciprocalOf = i < 0; } return isReciprocalOf; }