/** * Returns the <code>String</code> representation of this measure * The string produced for a given measure is always the same; * it is not affected by locale. This means that it can be used * as a canonical string representation for exchanging data, * or as a key for a Hashtable, etc. Locale-sensitive * measure formatting and parsing is handled by the {@link * MeasureFormat} class and its subclasses. * * @return the string representation of this measure. */ public String toString() { if (getUnit() instanceof CompoundUnit) return MeasureFormat.DEFAULT.formatCompound(doubleValue(getUnit()), getUnit(), new StringBuffer(), null).toString(); return getValue() + " " + getUnit(); }
/** * Returns the <code>String</code> representation of this measure * The string produced for a given measure is always the same; * it is not affected by locale. This means that it can be used * as a canonical string representation for exchanging data, * or as a key for a Hashtable, etc. Locale-sensitive * measure formatting and parsing is handled by the {@link * MeasureFormat} class and its subclasses. * * @return the string representation of this measure. */ public String toString() { if (getUnit() instanceof CompoundUnit) return MeasureFormat.DEFAULT.formatCompound(doubleValue(getUnit()), getUnit(), new StringBuffer(), null).toString(); return getValue() + " " + getUnit(); }
/** * Returns the <code>String</code> representation of this measure * The string produced for a given measure is always the same; * it is not affected by locale. This means that it can be used * as a canonical string representation for exchanging data, * or as a key for a Hashtable, etc. Locale-sensitive * measure formatting and parsing is handled by the {@link * MeasureFormat} class and its subclasses. * * @return the string representation of this measure. */ public String toString() { if (getUnit() instanceof CompoundUnit) return MeasureFormat.DEFAULT.formatCompound(doubleValue(getUnit()), getUnit(), new StringBuffer(), null).toString(); return getValue() + " " + getUnit(); }
/** * Compares this measure to the specified measurable quantity. * This method compares the {@link Measurable#doubleValue(Unit)} of * both this measure and the specified measurable stated in the * same unit (this measure's {@link #getUnit() unit}). * * @return a negative integer, zero, or a positive integer as this measure * is less than, equal to, or greater than the specified measurable * quantity. * @return <code>Double.compare(this.doubleValue(getUnit()), * that.doubleValue(getUnit()))</code> */ public int compareTo(Measurable<Q> that) { return java.lang.Double.compare(doubleValue(getUnit()), that .doubleValue(getUnit())); }
/** * Compares this measure to the specified measurable quantity. * This method compares the {@link Measurable#doubleValue(Unit)} of * both this measure and the specified measurable stated in the * same unit (this measure's {@link #getUnit() unit}). * * @return a negative integer, zero, or a positive integer as this measure * is less than, equal to, or greater than the specified measurable * quantity. * @return <code>Double.compare(this.doubleValue(getUnit()), * that.doubleValue(getUnit()))</code> */ public int compareTo(Measurable<Q> that) { return java.lang.Double.compare(doubleValue(getUnit()), that .doubleValue(getUnit())); }
/** * Compares this measure to the specified measurable quantity. * This method compares the {@link Measurable#doubleValue(Unit)} of * both this measure and the specified measurable stated in the * same unit (this measure's {@link #getUnit() unit}). * * @return a negative integer, zero, or a positive integer as this measure * is less than, equal to, or greater than the specified measurable * quantity. * @return <code>Double.compare(this.doubleValue(getUnit()), * that.doubleValue(getUnit()))</code> */ public int compareTo(Measurable<Q> that) { return java.lang.Double.compare(doubleValue(getUnit()), that .doubleValue(getUnit())); }
/** * Returns the hash code for this scalar. * * @return the hash code value. */ public int hashCode() { return getUnit().hashCode() + getValue().hashCode(); }
/** * Returns the hash code for this scalar. * * @return the hash code value. */ public int hashCode() { return getUnit().hashCode() + getValue().hashCode(); }
/** * Returns the hash code for this scalar. * * @return the hash code value. */ public int hashCode() { return getUnit().hashCode() + getValue().hashCode(); }
@Override public JsonElement doSerialize(Measure<?, ?> src, Type typeOfSrc, JsonSerializationContext context) { final JsonObject obj = new JsonObject(); obj.add(UNIT, context.serialize(src.getUnit(), Unit.class)); obj.add(VALUE, context.serialize(src.getValue())); obj.addProperty(VALUE_TYPE, src.getValue().getClass().getName()); return obj; } }
@Override public JsonElement doSerialize(Measure<?, ?> src, Type typeOfSrc, JsonSerializationContext context) { final JsonObject obj = new JsonObject(); obj.add(UNIT, context.serialize(src.getUnit(), Unit.class)); obj.add(VALUE, context.serialize(src.getValue())); obj.addProperty(VALUE_TYPE, src.getValue().getClass().getName()); return obj; } }
/** * Compares this measure against the specified object for * strict equality (same unit and amount). * To compare measures stated using different units the * {@link #compareTo} method should be used. * * @param obj the object to compare with. * @return <code>true</code> if both objects are identical (same * unit and same amount); <code>false</code> otherwise. */ @SuppressWarnings("unchecked") public boolean equals(Object obj) { if (!(obj instanceof Measure)) return false; Measure that = (Measure) obj; return this.getUnit().equals(that.getUnit()) && this.getValue().equals(that.getValue()); }
/** * Compares this measure against the specified object for * strict equality (same unit and amount). * To compare measures stated using different units the * {@link #compareTo} method should be used. * * @param obj the object to compare with. * @return <code>true</code> if both objects are identical (same * unit and same amount); <code>false</code> otherwise. */ @SuppressWarnings("unchecked") public boolean equals(Object obj) { if (!(obj instanceof Measure)) return false; Measure that = (Measure) obj; return this.getUnit().equals(that.getUnit()) && this.getValue().equals(that.getValue()); }
/** * Compares this measure against the specified object for * strict equality (same unit and amount). * To compare measures stated using different units the * {@link #compareTo} method should be used. * * @param obj the object to compare with. * @return <code>true</code> if both objects are identical (same * unit and same amount); <code>false</code> otherwise. */ @SuppressWarnings("unchecked") public boolean equals(Object obj) { if (!(obj instanceof Measure)) return false; Measure that = (Measure) obj; return this.getUnit().equals(that.getUnit()) && this.getValue().equals(that.getValue()); }
@Override public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { Measure<?, ?> measure = (Measure<?, ?>) obj; Object value = measure.getValue(); Unit<?> unit = measure.getUnit(); if (value instanceof Number) { if (unit instanceof CompoundUnit) return formatCompound(((Number) value).doubleValue(), unit, toAppendTo, pos); _numberFormat.format(value, toAppendTo, pos); } else { toAppendTo.append(value); } if (!measure.getUnit().equals(Unit.ONE)) { toAppendTo.append(' '); _unitFormat.format(unit, toAppendTo, pos); } return toAppendTo; }
@SuppressWarnings("unchecked") private Object parseCompound(Number highValue, String source, ParsePosition pos) throws ParseException { Unit high = _unitFormat.parseSingleUnit(source, pos); int i = pos.getIndex(); if (i >= source.length() || Character.isWhitespace(source.charAt(i))) return measureOf(highValue, high); Measure lowMeasure = (Measure) parseObject(source, pos); Unit unit = lowMeasure.getUnit(); long l = lowMeasure.longValue(unit) + (long) high.getConverterTo(unit).convert( highValue.longValue()); return Measure.valueOf(l, unit); }
@SuppressWarnings("unchecked") private Object parseCompound(Number highValue, String source, ParsePosition pos) throws ParseException { Unit high = _unitFormat.parseSingleUnit(source, pos); int i = pos.getIndex(); if (i >= source.length() || Character.isWhitespace(source.charAt(i))) return measureOf(highValue, high); Measure lowMeasure = (Measure) parseObject(source, pos); Unit unit = lowMeasure.getUnit(); long l = lowMeasure.longValue(unit) + (long) high.getConverterTo(unit).convert( highValue.longValue()); return Measure.valueOf(l, unit); }
@SuppressWarnings("unchecked") private Object parseCompound(Number highValue, String source, ParsePosition pos) throws ParseException { Unit high = _unitFormat.parseSingleUnit(source, pos); int i = pos.getIndex(); if (i >= source.length() || Character.isWhitespace(source.charAt(i))) return measureOf(highValue, high); Measure lowMeasure = (Measure) parseObject(source, pos); Unit unit = lowMeasure.getUnit(); long l = lowMeasure.longValue(unit) + (long) high.getConverterTo(unit).convert( highValue.longValue()); return Measure.valueOf(l, unit); }
@Override public double calculateTravelTime(Graph<?> graph, Point from, Point to, Unit<Length> distanceUnit, Measure<Double, Velocity> speed, Unit<Duration> outputTimeUnit) { final Measure<Double, Length> distance = Measure.valueOf(graph.connectionLength(from, to), distanceUnit); return Math.max(doCalculateTravelTime(speed, distance, outputTimeUnit), doCalculateTravelTime( Measure.valueOf(getSpeed(graph, from, to), speed.getUnit()), distance, outputTimeUnit)); }
@Override public double calculateTravelTime(Graph<?> graph, Point from, Point to, Unit<Length> distanceUnit, Measure<Double, Velocity> speed, Unit<Duration> outputTimeUnit) { final Measure<Double, Length> distance = Measure.valueOf(graph.connectionLength(from, to), distanceUnit); return Math.max(doCalculateTravelTime(speed, distance, outputTimeUnit), doCalculateTravelTime( Measure.valueOf(getSpeed(graph, from, to), speed.getUnit()), distance, outputTimeUnit)); }