This repository has been archived by the owner on Sep 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
475 additions
and
12,183 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
Manifest-Version: 1.0 | ||
Export-Package: javax.measure;uses:="javax.measure.unit,junit.framework", | ||
javax.measure.quantity, | ||
javax.measure.unit;uses:="junit.framework" | ||
Bundle-Version: 0.9.5 | ||
Tool: Bundlor 1.0.0.BUILD-20091207202403 | ||
Bundle-Name: Units of Measure | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Vendor: JScience | ||
Bundle-SymbolicName: javax.measure | ||
Bundle-Name: Measures and Units | ||
Bundle-Version: 0.9.3 | ||
Export-Package: javax.measure, | ||
javax.measure.converter, | ||
javax.measure.quantity, | ||
javax.measure.unit, | ||
javax.measure.unit.format | ||
Import-Package: junit.framework | ||
Provide-Package: javax.measure,javax.measure.quantity,javax.measure.un | ||
it | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,9 +127,9 @@ | |
* | ||
* @author <a href="mailto:[email protected]">Jean-Marie Dautelle</a> | ||
* @author <a href="mailto:[email protected]">Werner Keil</a> | ||
* @version 1.0.3 ($Revision: 76 $), $Date: 2009-12-03 23:53:52 +0100 (Do, 03 Dez 2009) $ | ||
* @version 1.0.4 ($Revision: 96 $), $Date: 2010-02-03 19:21:17 +0100 (Mi, 03 Feb 2010) $ | ||
*/ | ||
public interface Measurable<Q extends Quantity> extends Comparable<Measurable<Q>> { | ||
interface Measurable<Q extends Quantity> extends Comparable<Measurable<Q>> { | ||
|
||
/** | ||
* Returns the integral <code>int</code> value of this measurable when | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,13 +80,12 @@ | |
*/ | ||
package javax.measure; | ||
|
||
import java.io.Serializable; | ||
import java.math.BigDecimal; | ||
import java.math.MathContext; | ||
|
||
import java.text.ParsePosition; | ||
import javax.measure.converter.UnitConverter; | ||
import javax.measure.quantity.Quantity; | ||
import javax.measure.unit.UnitConverter; | ||
import javax.measure.unit.Unit; | ||
|
||
/** | ||
|
@@ -143,10 +142,9 @@ | |
* | ||
* @author <a href="mailto:[email protected]">Jean-Marie Dautelle</a> | ||
* @author <a href="mailto:[email protected]">Werner Keil</a> | ||
* @version 1.0.4 ($Revision: 76 $), $Date: 2009-12-03 23:53:52 +0100 (Do, 03 Dez 2009) $ | ||
* @version 1.1.2 ($Revision: 102 $), $Date: 2010-02-07 23:46:37 +0100 (So, 07 Feb 2010) $ | ||
*/ | ||
public abstract class Measure<Q extends Quantity> implements Measurable<Q>, | ||
Serializable { | ||
public abstract class Measure<Q extends Quantity> extends Number implements Measurable<Q> { | ||
|
||
/** | ||
* | ||
|
@@ -193,7 +191,7 @@ public long round(Unit<Q> unit) { | |
* @throws ArithmeticException if the result is inexact and the quotient | ||
* has a non-terminating decimal expansion. | ||
*/ | ||
public Measure<Q> toSI() { | ||
public Measure<Q> toSI() { // TODO needed? | ||
return to(this.getUnit().toSI()); | ||
} | ||
|
||
|
@@ -312,20 +310,32 @@ public int hashCode() { | |
} | ||
|
||
/** | ||
* Returns the <code>String</code> representation of this measure. The | ||
* string produced for a given measure is always the same; it is not | ||
* Returns the standard <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 measure, 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 <code>UnitFormat.getInternational().format(this)</code> | ||
* @return <code>UnitFormat.getStandard().format(this)</code> | ||
*/ | ||
@Override | ||
public String toString() { | ||
return MeasureFormat.getStandard().format(this); | ||
} | ||
|
||
/** | ||
* Returns the locale <code>String</code> representation of this measure | ||
* (usually nicer looking than {@link #toString}. The | ||
* string produced for a given measure is not always the same depending | ||
* on the locale. | ||
* | ||
* @return <code>UnitFormat.getInstance().format(this)</code> | ||
*/ | ||
// public String toStringLocale() { | ||
// return MeasureFormat.getInstance().format(this); | ||
// } | ||
|
||
// Implements Measurable | ||
public final int intValue(Unit<Q> unit) throws ArithmeticException { | ||
long longValue = longValue(unit); | ||
|
@@ -343,12 +353,20 @@ public long longValue(Unit<Q> unit) throws ArithmeticException { | |
} | ||
return (long) result; | ||
} | ||
|
||
public long longValue() { | ||
return longValue(getUnit()); | ||
} | ||
|
||
// Implements Measurable | ||
public final float floatValue(Unit<Q> unit) { | ||
return (float) doubleValue(unit); | ||
} | ||
|
||
public final float floatValue() { | ||
return floatValue(getUnit()); | ||
} | ||
|
||
/** | ||
* Casts this measure to a parameterized unit of specified nature or throw a | ||
* <code>ClassCastException</code> if the dimension of the specified | ||
|
@@ -369,7 +387,7 @@ public final float floatValue(Unit<Q> unit) { | |
@SuppressWarnings("unchecked") | ||
public <T extends Quantity> Measure<T> asType(Class<T> type) | ||
throws ClassCastException { | ||
this.getUnit().asType(type); // Raises ClassCastException is dimension | ||
this.getUnit().asType(type); // Raises ClassCastException if dimension | ||
// mismatches. | ||
return (Measure<T>) this; | ||
} | ||
|
@@ -414,35 +432,35 @@ private static class IntegerMeasure<T extends Quantity> extends Measure<T> { | |
*/ | ||
private static final long serialVersionUID = 5355395476874521709L; | ||
|
||
int _value; | ||
int value; | ||
|
||
Unit<T> _unit; | ||
Unit<T> unit; | ||
|
||
public IntegerMeasure(int value, Unit<T> unit) { | ||
_value = value; | ||
_unit = unit; | ||
this.value = value; | ||
this.unit = unit; | ||
} | ||
|
||
@Override | ||
public Integer getValue() { | ||
return _value; | ||
return value; | ||
} | ||
|
||
@Override | ||
public Unit<T> getUnit() { | ||
return _unit; | ||
return unit; | ||
} | ||
|
||
// Implements Measurable | ||
public double doubleValue(Unit<T> unit) { | ||
return (_unit.equals(unit)) ? _value : _unit.getConverterTo(unit).convert(_value); | ||
return (this.unit.equals(unit)) ? value : this.unit.getConverterTo(unit).convert(value); | ||
} | ||
|
||
// Implements Measurable | ||
public BigDecimal decimalValue(Unit<T> unit, MathContext ctx) | ||
throws ArithmeticException { | ||
BigDecimal decimal = BigDecimal.valueOf(_value); | ||
return (_unit.equals(unit)) ? decimal : _unit.getConverterTo(unit).convert(decimal, ctx); | ||
BigDecimal decimal = BigDecimal.valueOf(value); | ||
return (this.unit.equals(unit)) ? decimal : this.unit.getConverterTo(unit).convert(decimal, ctx); | ||
} | ||
} | ||
|
||
|
@@ -646,7 +664,7 @@ public Unit<T> getUnit() { | |
return unit; | ||
} | ||
|
||
// Implements Measurable | ||
|
||
public double doubleValue(Unit<T> unit) { | ||
return (this.unit.equals(unit)) ? value.doubleValue() : this.unit.getConverterTo(unit).convert(value.doubleValue()); | ||
} | ||
|
@@ -657,4 +675,14 @@ public BigDecimal decimalValue(Unit<T> unit, MathContext ctx) | |
return (this.unit.equals(unit)) ? value : this.unit.getConverterTo(unit).convert(value, ctx); | ||
} | ||
} | ||
|
||
@Override | ||
public double doubleValue() { | ||
return doubleValue(getUnit()); | ||
} | ||
|
||
@Override | ||
public int intValue() { | ||
return intValue(getUnit()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,7 +102,7 @@ | |
* | ||
* @author <a href="mailto:[email protected]">Jean-Marie Dautelle</a> | ||
* @author <a href="mailto:[email protected]">Werner Keil</a> | ||
* @version 1.0.1 ($Revision: 76 $), $Date: 2009-12-03 23:53:52 +0100 (Do, 03 Dez 2009) $ | ||
* @version 1.0.1 ($Revision: 89 $), $Date: 2010-01-31 23:15:22 +0100 (So, 31 Jän 2010) $ | ||
*/ | ||
public abstract class MeasureFormat extends Format { | ||
|
||
|
@@ -348,7 +348,7 @@ public Appendable format(Measure measure, Appendable dest) | |
if (measure.getUnit().equals(Unit.ONE)) | ||
return dest; | ||
dest.append(' '); | ||
return UnitFormat.getStandard().format(unit, dest); | ||
return UnitFormat.getInstance().format(unit, dest); | ||
} | ||
} | ||
|
||
|
@@ -369,7 +369,7 @@ public Measure<?> parse(CharSequence csq, ParsePosition cursor) | |
BigDecimal decimal = new BigDecimal(csq.subSequence(startDecimal, | ||
endDecimal).toString()); | ||
cursor.setIndex(endDecimal + 1); | ||
Unit unit = UnitFormat.getStandard().parse(csq, cursor); | ||
Unit unit = UnitFormat.getInstance().parse(csq, cursor); | ||
return Measure.valueOf(decimal, unit); | ||
} | ||
} | ||
|
Oops, something went wrong.