001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026: package org.cougaar.planning.ldm.measure;
027:
028: import java.io.Serializable;
029:
030: /** Base interface for all Measure classes.
031: *
032: * All concrete subclasses of AbstractMeasure are required to
033: * implement the method:
034: * public static AbstractMeasure newMeasure(String s, int unit);
035: * Other AbstractMeasure-level constructors may be defined, depending
036: * on each the primative-types that each concrete class can handle.
037: * For instance, Distance is based on a double value, so in addition to
038: * the above, Distance.newMeasure(double d, int unit) will be defined.
039: *
040: * The allowed values of the unit specifier depends on (and is defined
041: * in) each Measure type. Example: Distance.FEET is a static final int
042: * with the correct value for use in constructing Distances in Feet.
043: *
044: * Each Measure class will also define a getValue(int unit) method
045: * returning whatever primitive type it is based on (usually double).
046: *
047: * All Measure classes are equals() comparable (exact internal value
048: * equality), define toString() (the value in a standard unit and a unit
049: * abbreviation, e.g. "4.5m"), and define hashCode() (for completeness).
050: *
051: * @see AbstractMeasure for base implementation class of all measures.
052: **/
053:
054: public interface Measure extends Comparable, Serializable {
055: /** @return a commonly-used unit used by this measure. NOTE that this
056: * is only a convenience and should not be depended on for computational
057: * use, since the notion of a common unit is extremely dependent on
058: * context.
059: **/
060: int getCommonUnit();
061:
062: /**
063: * The Measure holds the value in a native unit - what is it?
064: * @return the native unit - what the measure uses as the internal unit
065: */
066: int getNativeUnit();
067:
068: /** @return the value of the highest-valued unit known by this measure.
069: * There is no implied relationship between "highest valued" unit and "size"
070: * of that unit.
071: **/
072: int getMaxUnit();
073:
074: /**
075: * The result is undefined if the unit is not valid for this measure class.
076: * @param unit to get name of
077: * @return the name of the unit specified.
078: **/
079: String getUnitName(int unit);
080:
081: /** @return the value of the measure in terms of the specified units.
082: * @param unit must be in the range from 0 to getMaxUnit.
083: **/
084: double getValue(int unit);
085:
086: double getNativeValue();
087:
088: Measure add(Measure other);
089:
090: Measure subtract(Measure other);
091:
092: Measure negate();
093:
094: Measure scale(double scale);
095:
096: Measure floor(int unit);
097:
098: Measure valueOf(double value);
099:
100: Measure valueOf(double value, int unit);
101:
102: Duration divide(Rate rate);
103:
104: Measure min(Measure other);
105:
106: Measure max(Measure other);
107:
108: Measure apply(UnaryOperator op);
109:
110: Measure apply(BinaryOperator op, Measure other);
111: }
|