1 2 package gov.nasa.ltl.graph; 21 22 import java.util.Iterator ; 23 import java.util.TreeSet ; 24 25 26 29 public class ColorPair extends Pair implements Comparable { 30 public ColorPair (int colorIn, TreeSet iMaxSetIn) { 31 super(colorIn, iMaxSetIn); 32 } 33 34 public void setColor (int colorIn) { 35 super.setValue(colorIn); 36 } 37 38 public int getColor () { 39 return super.getValue(); 40 } 41 42 public void setIMaxSet (TreeSet iMaxSetIn) { 43 super.setElement(iMaxSetIn); 44 } 45 46 public TreeSet getIMaxSet () { 47 return (TreeSet ) super.getElement(); 48 } 49 50 public int compareTo (Object o) { 51 ColorPair other = (ColorPair) o; 52 TreeSet otherSet = other.getIMaxSet(); 53 54 if (getIMaxSet().size() < otherSet.size()) { 55 return -1; 56 } 57 58 if (getIMaxSet().size() > otherSet.size()) { 59 return 1; 60 } 61 62 int index = 0; 64 65 for (Iterator i = getIMaxSet().iterator(); i.hasNext();) { 66 ITypeNeighbor currNeigh = (ITypeNeighbor) i.next(); 67 Object [] otherArray = otherSet.toArray(); 68 int comparison = currNeigh.compareTo( 69 (ITypeNeighbor) otherArray[index]); 70 71 if ((comparison < 0) || (comparison > 0)) { 72 return comparison; 73 } 74 75 index++; 76 } 77 78 if (getColor() < other.getColor()) { 79 return -1; 80 } 81 82 if (getColor() > other.getColor()) { 83 return 1; 84 } 85 86 return 0; 87 } 88 89 public boolean equals (Object o) { 90 ColorPair other = (ColorPair) o; 91 TreeSet otherSet = other.getIMaxSet(); 92 93 if (getIMaxSet().size() < otherSet.size()) { 94 return false; 95 } 96 97 if (getIMaxSet().size() > otherSet.size()) { 98 return false; 99 } 100 101 if (getColor() != other.getColor()) { 102 return false; 103 } 104 105 int index = 0; 107 108 for (Iterator i = getIMaxSet().iterator(); i.hasNext();) { 109 ITypeNeighbor currNeigh = (ITypeNeighbor) i.next(); 110 Object [] otherArray = otherSet.toArray(); 111 int comparison = currNeigh.compareTo( 112 (ITypeNeighbor) otherArray[index]); 113 114 if ((comparison < 0) || (comparison > 0)) { 115 return false; 116 } 117 118 index++; 119 } 120 121 return true; 122 } 123 } | Popular Tags |