001: //
002: // Copyright (C) 2005 United States Government as represented by the
003: // Administrator of the National Aeronautics and Space Administration
004: // (NASA). All Rights Reserved.
005: //
006: // This software is distributed under the NASA Open Source Agreement
007: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
008: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
009: // directory tree for the complete NOSA document.
010: //
011: // THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
012: // KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
013: // LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
014: // SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
015: // A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
016: // THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
017: // DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
018: //
019: package gov.nasa.ltl.graph;
020:
021: import java.util.Iterator;
022: import java.util.TreeSet;
023:
024: /**
025: * DOCUMENT ME!
026: */
027: public class ColorPair extends Pair implements Comparable {
028: public ColorPair(int colorIn, TreeSet iMaxSetIn) {
029: super (colorIn, iMaxSetIn);
030: }
031:
032: public void setColor(int colorIn) {
033: super .setValue(colorIn);
034: }
035:
036: public int getColor() {
037: return super .getValue();
038: }
039:
040: public void setIMaxSet(TreeSet iMaxSetIn) {
041: super .setElement(iMaxSetIn);
042: }
043:
044: public TreeSet getIMaxSet() {
045: return (TreeSet) super .getElement();
046: }
047:
048: public int compareTo(Object o) {
049: ColorPair other = (ColorPair) o;
050: TreeSet otherSet = other.getIMaxSet();
051:
052: if (getIMaxSet().size() < otherSet.size()) {
053: return -1;
054: }
055:
056: if (getIMaxSet().size() > otherSet.size()) {
057: return 1;
058: }
059:
060: // TreeSets are ordered !!
061: int index = 0;
062:
063: for (Iterator i = getIMaxSet().iterator(); i.hasNext();) {
064: ITypeNeighbor currNeigh = (ITypeNeighbor) i.next();
065: Object[] otherArray = otherSet.toArray();
066: int comparison = currNeigh
067: .compareTo((ITypeNeighbor) otherArray[index]);
068:
069: if ((comparison < 0) || (comparison > 0)) {
070: return comparison;
071: }
072:
073: index++;
074: }
075:
076: if (getColor() < other.getColor()) {
077: return -1;
078: }
079:
080: if (getColor() > other.getColor()) {
081: return 1;
082: }
083:
084: return 0;
085: }
086:
087: public boolean equals(Object o) {
088: ColorPair other = (ColorPair) o;
089: TreeSet otherSet = other.getIMaxSet();
090:
091: if (getIMaxSet().size() < otherSet.size()) {
092: return false;
093: }
094:
095: if (getIMaxSet().size() > otherSet.size()) {
096: return false;
097: }
098:
099: if (getColor() != other.getColor()) {
100: return false;
101: }
102:
103: // TreeSets are ordered
104: int index = 0;
105:
106: for (Iterator i = getIMaxSet().iterator(); i.hasNext();) {
107: ITypeNeighbor currNeigh = (ITypeNeighbor) i.next();
108: Object[] otherArray = otherSet.toArray();
109: int comparison = currNeigh
110: .compareTo((ITypeNeighbor) otherArray[index]);
111:
112: if ((comparison < 0) || (comparison > 0)) {
113: return false;
114: }
115:
116: index++;
117: }
118:
119: return true;
120: }
121: }
|