1 cananian 1.1.2.2 // WeightedSet.java, created Wed Jun 21  3:22:28 2000 by pnkfelix
 2 cananian 1.1.2.2 // Copyright (C) 2001 Felix S. Klock II <pnkfelix@mit.edu>
 3 cananian 1.1.2.2 // Licensed under the terms of the GNU GPL; see COPYING for details.
 4 pnkfelix 1.1.2.1 package harpoon.Analysis.Instr;
 5 pnkfelix 1.1.2.1 
 6 cananian 1.3     import net.cscott.jutil.CollectionWrapper;
 7 pnkfelix 1.1.2.1 
 8 pnkfelix 1.1.2.1 import java.util.Set;
 9 pnkfelix 1.1.2.1 import java.util.AbstractSet;
10 pnkfelix 1.1.2.1 import java.util.Iterator;
11 pnkfelix 1.1.2.1 
12 cananian 1.1.2.2 /** wrapper around set with an associated weight.
13 cananian 1.1.2.2     @author  Felix S. Klock II <pnkfelix@mit.edu>
14 cananian 1.3         @version $Id: WeightedSet.java,v 1.3 2004/02/08 01:52:07 cananian Exp $
15 cananian 1.1.2.2 */
16 pnkfelix 1.1.2.1 class WeightedSet extends CollectionWrapper implements Set, Comparable {
17 pnkfelix 1.1.2.1     Set temps;
18 pnkfelix 1.1.2.1     int weight;
19 pnkfelix 1.1.2.1     WeightedSet(Set s, int i) {
20 pnkfelix 1.1.2.1         super(s);
21 pnkfelix 1.1.2.1         this.weight = i;
22 pnkfelix 1.1.2.1     }
23 pnkfelix 1.1.2.1     public int compareTo(Object o) {
24 pnkfelix 1.1.2.1         WeightedSet s = (WeightedSet) o;
25 pnkfelix 1.1.2.1         return (s.weight - this.weight);
26 pnkfelix 1.1.2.1     } 
27 pnkfelix 1.1.2.1     public boolean equals(Object o) {
28 pnkfelix 1.1.2.1         try {
29 pnkfelix 1.1.2.1             WeightedSet ws = (WeightedSet) o;
30 pnkfelix 1.1.2.1             return (super.equals(ws) &&
31 pnkfelix 1.1.2.1                     this.weight == ws.weight);
32 pnkfelix 1.1.2.1         } catch (ClassCastException e) {
33 pnkfelix 1.1.2.1             return false;
34 pnkfelix 1.1.2.1         }
35 pnkfelix 1.1.2.1     }
36 pnkfelix 1.1.2.1     public String toString() { 
37 pnkfelix 1.1.2.1         return "<Set:"+super.toString()+
38 pnkfelix 1.1.2.1             ",Weight:"+weight+
39 pnkfelix 1.1.2.1             (temps==null?"":(",Temps:"+temps))+">"; 
40 pnkfelix 1.1.2.1     }
41 cananian 1.2     }