/** * Indicates if this unit is semantically identical to an object. * * @param object The object. * @return <code>true</code> if and only if this unit is semantically * identical to <code>object * </code>. */ @Override public boolean equals(final Object object) { if (this == object) { return true; } if (!(object instanceof TimeScaleUnit)) { return false; } final TimeScaleUnit that = (TimeScaleUnit) object; return _origin.equals(that._origin) && _unit.equals(that._unit); }
/** * Indicates if this unit is semantically identical to an object. * * @param object The object. * @return <code>true</code> if and only if this unit is semantically * identical to <code>object * </code>. */ @Override public boolean equals(final Object object) { if (this == object) { return true; } if (!(object instanceof TimeScaleUnit)) { return false; } final TimeScaleUnit that = (TimeScaleUnit) object; return _origin.equals(that._origin) && _unit.equals(that._unit); }
private static void myAssert(StandardUnitFormat parser, final String spec, final Unit unit) throws NoSuchUnitException, UnitParseException, SpecificationException, UnitDBException, PrefixDBException, UnitSystemException { if (!parser.parse(spec).equals(unit)) { throw new AssertionError(spec + " != " + unit); } System.out.println(spec + " -> " + unit); }
/** * Indicates if this unit is semantically identical to an object. * * @param object * The object. * @return <code>true</code> if an only if this unit is semantically * identical to <code>object * </code>. */ public boolean equals(final Object object) { if (this == object) { return true; } if (_scale == 1) { return object.equals(_unit); } if (!(object instanceof ScaledUnit)) { return false; } ScaledUnit that = (ScaledUnit) object; if (Double.compare(that._scale, _scale) != 0) return false; if (!_unit.equals(that._unit)) return false; return true; }
private static void myAssert(StandardUnitFormat parser, final String spec, final Unit unit) throws NoSuchUnitException, UnitParseException, SpecificationException, UnitDBException, PrefixDBException, UnitSystemException { if (!parser.parse(spec).equals(unit)) { throw new AssertionError(spec + " != " + unit); } System.out.println(spec + " -> " + unit); }
/** * Indicates if this unit is semantically identical to an object. * * @param object * The object. * @return <code>true</code> if and only if this unit is semantically * identical to <code>object * </code>. */ @Override public boolean equals(final Object object) { if (this == object) { return true; } if (_offset == 0) { return object.equals(_unit); } if (!(object instanceof OffsetUnit)) { return false; } OffsetUnit that = (OffsetUnit) object; if (Double.compare(that._offset, _offset) != 0) return false; return _unit.equals(that._unit); }
/** * Indicates if this unit is semantically identical to an object. * * @param object * The object. * @return <code>true</code> if and only if this unit is semantically * identical to <code>object * </code>. */ @Override public boolean equals(final Object object) { if (this == object) { return true; } if (_offset == 0) { return object.equals(_unit); } if (!(object instanceof OffsetUnit)) { return false; } OffsetUnit that = (OffsetUnit) object; if (Double.compare(that._offset, _offset) != 0) return false; return _unit.equals(that._unit); }
/** * Indicates if this unit is semantically identical to an object. * * @param object * The object. * @return <code>true</code> if an only if this unit is semantically * identical to <code>object * </code>. */ public boolean equals(final Object object) { if (this == object) { return true; } if (_scale == 1) { return object.equals(_unit); } if (!(object instanceof ScaledUnit)) { return false; } ScaledUnit that = (ScaledUnit) object; if (Double.compare(that._scale, _scale) != 0) return false; if (!_unit.equals(that._unit)) return false; return true; }
/** * Adds a unique unit to a map.. * * @param map * The map to be added to. * @param key * The key for the unit entry. * @param newUnit * The unit to be added. * @throws UnitExistsException * Attempt to redefine an existing unit. */ private static final void addUnique(final Map<String, Unit> map, final String key, final Unit newUnit) throws UnitExistsException { final Unit oldUnit = map.put(key, newUnit); if (oldUnit != null && !oldUnit.equals(newUnit)) { throw new UnitExistsException(oldUnit, newUnit); } } }
/** * Adds a unique unit to a map.. * * @param map * The map to be added to. * @param key * The key for the unit entry. * @param newUnit * The unit to be added. * @throws UnitExistsException * Attempt to redefine an existing unit. */ private static final void addUnique(final Map<String, Unit> map, final String key, final Unit newUnit) throws UnitExistsException { final Unit oldUnit = map.put(key, newUnit); if (oldUnit != null && !oldUnit.equals(newUnit)) { throw new UnitExistsException(oldUnit, newUnit); } } }
/** * Indicates if numeric values in this unit are convertible with another * unit. * * @param that * The other unit. * @return <code>true</code> if and only if numeric values in this unit are * convertible the other unit. */ public boolean isCompatible(final Unit that) { // jeffm: for some reason just calling getDerivedUnit().equals(...) // with jikes 1.1.7 as the compiler causes the jvm to crash. // The Unit u1=... does not crash. final Unit u1 = getDerivedUnit(); return u1.equals(that.getDerivedUnit()); // return getDerivedUnit().equals(that.getDerivedUnit()); }
/** * Indicates if numeric values in this unit are convertible with another * unit. * * @param that * The other unit. * @return <code>true</code> if and only if numeric values in this unit are * convertible the other unit. */ public boolean isCompatible(final Unit that) { // jeffm: for some reason just calling getDerivedUnit().equals(...) // with jikes 1.1.7 as the compiler causes the jvm to crash. // The Unit u1=... does not crash. final Unit u1 = getDerivedUnit(); return u1.equals(that.getDerivedUnit()); // return getDerivedUnit().equals(that.getDerivedUnit()); }
final ScaledUnit nauticalMile = new ScaledUnit(1852f, meter); System.out.println("nauticalMile.getUnit().equals(meter)=" + nauticalMile.getUnit().equals(meter)); final ScaledUnit nauticalMileMeter = (ScaledUnit) nauticalMile .multiplyBy(meter);
final ScaledUnit nauticalMile = new ScaledUnit(1852f, meter); System.out.println("nauticalMile.getUnit().equals(meter)=" + nauticalMile.getUnit().equals(meter)); final ScaledUnit nauticalMileMeter = (ScaledUnit) nauticalMile .multiplyBy(meter);
+ kelvin.getConverterTo(celsius).convert(273.15) + '"'); myAssert(kelvin.isCompatible(celsius)); myAssert(!kelvin.equals(celsius)); myAssert(kelvin.hashCode() != celsius.hashCode()); Unit fahrenheit = format.parse("fahrenheit");
+ kelvin.getConverterTo(celsius).convert(273.15) + '"'); myAssert(kelvin.isCompatible(celsius)); myAssert(!kelvin.equals(celsius)); myAssert(kelvin.hashCode() != celsius.hashCode()); Unit fahrenheit = format.parse("fahrenheit");
myAssert(parser, "s @ 1970-01-01T00:00:00.00 -12", epoch .shiftTo(new Date(12 * 60 * 60 * 1000))); if (!parser.parse("days since 2009-06-14 04:00:00").equals( parser.parse("days since 2009-06-14 04:00:00 +00:00"))) { throw new AssertionError();
myAssert(parser, "s @ 1970-01-01T00:00:00.00 -12", epoch .shiftTo(new Date(12 * 60 * 60 * 1000))); if (!parser.parse("days since 2009-06-14 04:00:00").equals( parser.parse("days since 2009-06-14 04:00:00 +00:00"))) { throw new AssertionError();