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:
027: package org.cougaar.planning.ldm.plan;
028:
029: import java.io.Serializable;
030:
031: /**
032: * Implementation of Preference.
033: **/
034:
035: public class PreferenceImpl implements Preference, AspectType,
036: Cloneable, Serializable {
037: private int aspect;
038: private ScoringFunction scorefun;
039: private float theweight;
040:
041: // Default constructor
042:
043: public PreferenceImpl() {
044: super ();
045: }
046:
047: /** Simple Constructor
048: * @param aspecttype
049: * @param scoringfunction
050: * @see org.cougaar.planning.ldm.plan.AspectValue
051: */
052: public PreferenceImpl(int aspecttype,
053: ScoringFunction scoringfunction) {
054: super ();
055: aspect = aspecttype;
056: scorefun = scoringfunction;
057: theweight = (float) 1.0;
058: }
059:
060: /** Constructor that takes aspect type, scoring function and weight.
061: * @param aspecttype
062: * @param scoringfunction
063: * @param weight
064: * @see org.cougaar.planning.ldm.plan.AspectValue
065: */
066: public PreferenceImpl(int aspecttype,
067: ScoringFunction scoringfunction, double weight) {
068: super ();
069: aspect = aspecttype;
070: scorefun = scoringfunction;
071: this .theweight = (float) weight;
072: }
073:
074: public Object clone() {
075: ScoringFunction scoringFunction = (ScoringFunction) getScoringFunction();
076: return new PreferenceImpl(getAspectType(),
077: (ScoringFunction) scoringFunction.clone(), getWeight());
078: }
079:
080: //Preference interface implementations
081:
082: /** @return int The AspectType that this preference represents
083: * @see org.cougaar.planning.ldm.plan.AspectType
084: */
085: public final int getAspectType() {
086: return aspect;
087: }
088:
089: /** @return ScoringFunction
090: * @see org.cougaar.planning.ldm.plan.ScoringFunction
091: */
092: public final ScoringFunction getScoringFunction() {
093: return scorefun;
094: }
095:
096: /** A Weighting of this preference from 0.0-1.0, 1.0 being high and
097: * 0.0 being low.
098: * @return double The weight
099: */
100: public final float getWeight() {
101: return theweight;
102: }
103:
104: public boolean equals(Object o) {
105: if (o instanceof PreferenceImpl) {
106: PreferenceImpl p = (PreferenceImpl) o;
107: return aspect == p.getAspectType()
108: && theweight == p.getWeight()
109: && scorefun.equals(p.getScoringFunction());
110: } else
111: return false;
112: }
113:
114: public int hashCode() {
115: return aspect + ((int) theweight * 1000) + scorefun.hashCode();
116: }
117:
118: public String toString() {
119: return "<Preference " + aspect + " " + scorefun + " ("
120: + theweight + ")>";
121: }
122: }
|