00001 package gov.nasa.arc.ase.util.graph;
00002
00003 import java.io.*;
00004 import java.util.TreeSet;
00005 import java.util.Iterator;
00006
00007 public class ColorPair extends Pair implements Comparable{
00008
00009 public ColorPair(int colorIn, TreeSet iMaxSetIn) {
00010 super(colorIn, iMaxSetIn);
00011 }
00012 public int compareTo(Object o) {
00013 ColorPair other = (ColorPair)o;
00014 TreeSet otherSet = other.getIMaxSet();
00015 if (getIMaxSet().size() < otherSet.size())
00016 return -1;
00017
00018 if (getIMaxSet().size() > otherSet.size())
00019 return 1;
00020
00021
00022 int index = 0;
00023 for (Iterator i = getIMaxSet().iterator(); i.hasNext();) {
00024 ITypeNeighbor currNeigh = (ITypeNeighbor)i.next();
00025 Object[] otherArray = otherSet.toArray();
00026 int comparison = currNeigh.compareTo((ITypeNeighbor)otherArray[index]);
00027 if ((comparison < 0) || (comparison > 0))
00028 return comparison;
00029 index++;
00030 }
00031 if (getColor() < other.getColor())
00032 return -1;
00033 if (getColor() > other.getColor())
00034 return 1;
00035 return 0;
00036 }
00037 public boolean equals(Object o) {
00038 ColorPair other = (ColorPair) o;
00039 TreeSet otherSet = other.getIMaxSet();
00040 if (getIMaxSet().size() < otherSet.size())
00041 return false;
00042
00043 if (getIMaxSet().size() > otherSet.size())
00044 return false;
00045
00046 if (getColor() != other.getColor())
00047 return false;
00048
00049
00050 int index = 0;
00051 for (Iterator i = getIMaxSet().iterator(); i.hasNext();) {
00052 ITypeNeighbor currNeigh = (ITypeNeighbor)i.next();
00053 Object[] otherArray = otherSet.toArray();
00054 int comparison = currNeigh.compareTo((ITypeNeighbor)otherArray[index]);
00055 if ((comparison < 0) || (comparison > 0))
00056 return false;
00057 index++;
00058 }
00059 return true;
00060 }
00061 public int getColor() {
00062 return super.getValue();
00063 }
00064 public TreeSet getIMaxSet() {
00065 return (TreeSet)super.getElement();
00066 }
00067 public void setColor(int colorIn) {
00068 super.setValue(colorIn);
00069 }
00070 public void setIMaxSet(TreeSet iMaxSetIn) {
00071 super.setElement(iMaxSetIn);
00072 }
00073 }