/** * Returns the hash code of this instance. * * @return The hash code of this instance. */ @Override public int hashCode() { return getExponent() == 0 ? getClass().hashCode() : getExponent() ^ getBase().hashCode(); }
/** * Returns the hash code of this instance. * * @return The hash code of this instance. */ @Override public int hashCode() { return getExponent() == 0 ? getClass().hashCode() : getExponent() ^ getBase().hashCode(); }
/** * Returns the string representation of this Factor. * * @return The string representation of this Factor. */ @Override public final String toString() { return getExponent() == 0 ? "" : getExponent() == 1 ? getBase().toString() : getBase().toString() + getExponent(); }
/** * Returns the string representation of this Factor. * * @return The string representation of this Factor. */ @Override public final String toString() { return getExponent() == 0 ? "" : getExponent() == 1 ? getBase().toString() : getBase().toString() + getExponent(); }
public int compare(Factor f1, Factor f2) { int comp = f2.getExponent() - f1.getExponent(); if (comp == 0) comp = f1.getID().compareTo(f2.getID()); return comp; } };
public int compare(Factor f1, Factor f2) { int comp = f2.getExponent() - f1.getExponent(); if (comp == 0) comp = f1.getID().compareTo(f2.getID()); return comp; } };
/** * 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(); }
/** * 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(); }
/** * Indicates if this Factor is semantically identical to another object. * * @param object * The object. * @return <code>true</code> if and only if this Factor is semantically * identical to <code>object< * /code>. */ @Override public boolean equals(final Object object) { boolean equals; if (this == object) { equals = true; } else if (!(object instanceof Factor)) { equals = false; } else { final Factor that = (Factor) object; equals = getExponent() != that.getExponent() ? false : getExponent() == 0 || getBase().equals(that.getBase()); } return equals; }
/** * Indicates if this Factor is semantically identical to another object. * * @param object * The object. * @return <code>true</code> if and only if this Factor is semantically * identical to <code>object< * /code>. */ @Override public boolean equals(final Object object) { boolean equals; if (this == object) { equals = true; } else if (!(object instanceof Factor)) { equals = false; } else { final Factor that = (Factor) object; equals = getExponent() != that.getExponent() ? false : getExponent() == 0 || getBase().equals(that.getBase()); } return equals; }
/** * 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); }
/** * Indicates if this factor is dimensionless. A Factor is dimensionless if * and only if the exponent is zero or the Base entity is dimensionless. * * @return <code>true</code> if and only if this Factor is dimensionless. */ public boolean isDimensionless() { return getExponent() == 0 || getBase().isDimensionless(); } }
/** * 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); }
/** * Indicates if this factor is dimensionless. A Factor is dimensionless if * and only if the exponent is zero or the Base entity is dimensionless. * * @return <code>true</code> if and only if this Factor is dimensionless. */ public boolean isDimensionless() { return getExponent() == 0 || getBase().isDimensionless(); } }
final int exponent = f1.getExponent() + f2.getExponent(); if (exponent != 0) { newFactors[k++] = new Factor(f1, exponent);
final int exponent = f1.getExponent() + f2.getExponent(); if (exponent != 0) { newFactors[k++] = new Factor(f1, exponent);
/** * Returns the corresponding quantity dimension. * @return The quantity dimension corresponding to this * unit dimension. */ public QuantityDimension getQuantityDimension() { Factor[] factors = getFactors(); for (int i = factors.length; --i >= 0; ) { Factor factor = factors[i]; factors[i] = new Factor( ((BaseUnit)factor.getBase()).getBaseQuantity(), factor.getExponent()); } return new QuantityDimension(factors); }
/** * Returns the corresponding quantity dimension. * @return The quantity dimension corresponding to this * unit dimension. */ public QuantityDimension getQuantityDimension() { Factor[] factors = getFactors(); for (int i = factors.length; --i >= 0; ) { Factor factor = factors[i]; factors[i] = new Factor( ((BaseUnit)factor.getBase()).getBaseQuantity(), factor.getExponent()); } return new QuantityDimension(factors); }