From: bdemsky Date: Tue, 25 Mar 2008 03:10:04 +0000 (+0000) Subject: clean up some equal methods X-Git-Tag: preEdgeChange~206 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9c653cd415997a068fb0a78ec7c522d29db4be9b;p=IRC.git clean up some equal methods --- diff --git a/Robust/src/Analysis/Prefetch/IndexDescriptor.java b/Robust/src/Analysis/Prefetch/IndexDescriptor.java index 0f53e32b..b322183e 100644 --- a/Robust/src/Analysis/Prefetch/IndexDescriptor.java +++ b/Robust/src/Analysis/Prefetch/IndexDescriptor.java @@ -18,92 +18,76 @@ import IR.*; */ public class IndexDescriptor extends Descriptor { - public ArrayList tddesc; - public Integer offset; + public ArrayList tddesc; + public Integer offset; + + public IndexDescriptor(Integer offset) { + super(offset.toString()); + this.offset = offset; + this.tddesc=new ArrayList(); + } + + public IndexDescriptor(TempDescriptor tdesc, Integer offset) { + super(tdesc.toString()); + tddesc = new ArrayList(); + tddesc.add(tdesc); + this.offset = offset; + } + + public IndexDescriptor() { + super("Empty"); + tddesc = new ArrayList(); + offset = 0; + } - public IndexDescriptor(Integer offset) { - super(offset.toString()); - this.offset = offset; + public IndexDescriptor(ArrayList tdesc, Integer offset) { + super(tdesc.toString()); + tddesc = new ArrayList(); + tddesc.addAll(tdesc); + this.offset = offset; + } + + public ArrayList getTempDesc() { + return tddesc; + } + + public TempDescriptor getTempDescAt(int index) { + return ((TempDescriptor) (tddesc.get(index))); + } + + public int getOffset() { + return offset.intValue(); + } + + public String toString() { + String label="["; + if(getTempDesc() == null) { + label += offset.toString(); + return label; + } else { + ListIterator lit = getTempDesc().listIterator(); + for(;lit.hasNext();) { + TempDescriptor td = (TempDescriptor) lit.next(); + label += td.toString()+"+"; + } + label +=offset.toString(); } - - public IndexDescriptor(TempDescriptor tdesc, Integer offset) { - super(tdesc.toString()); - if(tddesc == null) - tddesc = new ArrayList(); - tddesc.add(tdesc); - this.offset = offset; - } - - public IndexDescriptor() { - super("Empty"); - tddesc = new ArrayList(); - offset = 0; - } - - public IndexDescriptor(ArrayList tdesc, Integer offset) { - super(tdesc.toString()); - if(tddesc == null) - tddesc = new ArrayList(); - tddesc.addAll(tdesc); - this.offset = offset; - } - - public ArrayList getTempDesc() { - return tddesc; - } - - public TempDescriptor getTempDescAt(int index) { - return ((TempDescriptor) (tddesc.get(index))); - } - - public int getOffset() { - return offset.intValue(); - } - - public String toString() { - String label="["; - if(getTempDesc() == null) { - label += offset.toString(); - return label; - } else { - ListIterator lit = getTempDesc().listIterator(); - for(;lit.hasNext();) { - TempDescriptor td = (TempDescriptor) lit.next(); - label += td.toString()+"+"; - } - label +=offset.toString(); - } - label += "]"; - return label; - } - - public int hashCode() { - int hashcode = (Integer) offset.hashCode(); - if(tddesc != null) { - ListIterator lit = tddesc.listIterator(); - while(lit.hasNext()) { - hashcode = hashcode ^ lit.next().hashCode(); - } - } - return hashcode; - } - - public boolean equals(Object o) { - if(o instanceof IndexDescriptor) { - IndexDescriptor idesc = (IndexDescriptor) o; - if(!(offset.equals(idesc.offset))) { - return false; - } - if(tddesc == null && idesc.tddesc == null) { - return true; - } else if(tddesc!=null && idesc.tddesc!=null) { - if(tddesc.equals((ArrayList)idesc.tddesc)){ - return true; - } - }else { - return false; - } - } - return false; + label += "]"; + return label; + } + + public int hashCode() { + int hashcode = (Integer) offset.hashCode(); + hashcode^=tddesc.hashCode(); + return hashcode; + } + + public boolean equals(Object o) { + if(o instanceof IndexDescriptor) { + IndexDescriptor idesc = (IndexDescriptor) o; + return offset==idesc.offset&& + tddesc.equals(idesc.tddesc); } + return false; + } } diff --git a/Robust/src/Analysis/Prefetch/PairMap.java b/Robust/src/Analysis/Prefetch/PairMap.java index e896b995..e8f47fa7 100644 --- a/Robust/src/Analysis/Prefetch/PairMap.java +++ b/Robust/src/Analysis/Prefetch/PairMap.java @@ -17,72 +17,61 @@ import IR.*; */ public class PairMap { - public HashMap mappair; + public HashMap mappair; + + public PairMap() { + mappair = new HashMap(); + } + + public void addPair(PrefetchPair ppKey, PrefetchPair ppValue) { + mappair.put(ppKey, ppValue); + } + + public void removePair(PrefetchPair ppKey) { + mappair.remove(ppKey); + } + + public PrefetchPair getPair(PrefetchPair ppKey) { + if(mappair != null) + return mappair.get(ppKey); + return null; + } + + public int hashCode() { + return mappair.hashCode(); + } + + public int size() { + return mappair.size(); + } + + public boolean contains(PrefetchPair ppKey) { + if(mappair.containsKey(ppKey)) + return true; + return false; + } - public PairMap() { - mappair = new HashMap(); + public String toString() { + String label = null; + Set mapping = mappair.entrySet(); + Iterator it = mapping.iterator(); + label = "Mappings are: "; + for(;it.hasNext();) { + Object o = it.next(); + label += o.toString() + " , "; } + return label; + } - public void addPair(PrefetchPair ppKey, PrefetchPair ppValue) { - mappair.put(ppKey, ppValue); - } - - public void removePair(PrefetchPair ppKey) { - mappair.remove(ppKey); - } - - public PrefetchPair getPair(PrefetchPair ppKey) { - if(mappair != null) - return mappair.get(ppKey); - return null; - } - - public int hashCode() { - int hashcode = mappair.hashCode(); - return hashcode; - } - - public int size() { - return mappair.size(); - } - - public boolean contains(PrefetchPair ppKey) { - if(mappair.containsKey(ppKey)) - return true; - return false; - } - - public String toString() { - String label = null; - Set mapping = mappair.entrySet(); - Iterator it = mapping.iterator(); - label = "Mappings are: "; - for(;it.hasNext();) { - Object o = it.next(); - label += o.toString() + " , "; - } - return label; - } - - public boolean equals(Object o) { - if(o instanceof PairMap) { - PairMap pm = (PairMap) o; - if(mappair == null && pm.mappair == null) { - return true; - } else if(mappair != null && pm.mappair != null) { - if(mappair.equals((HashMap) pm.mappair)) { - return true; - } - } else { - return false; - } - } - return false; - } - - public boolean isEmpty() { - if(mappair.isEmpty()) - return true; - return false; + public boolean equals(Object o) { + if(o instanceof PairMap) { + PairMap pm = (PairMap) o; + return mappair.equals(pm.mappair); } + return false; + } + + public boolean isEmpty() { + return mappair.isEmpty(); + } } diff --git a/Robust/src/Analysis/Prefetch/PrefetchPair.java b/Robust/src/Analysis/Prefetch/PrefetchPair.java index 2d3b74de..f9026b01 100644 --- a/Robust/src/Analysis/Prefetch/PrefetchPair.java +++ b/Robust/src/Analysis/Prefetch/PrefetchPair.java @@ -4,121 +4,98 @@ import java.util.*; import IR.*; public class PrefetchPair { - public TempDescriptor base; - public ArrayList desc; + public TempDescriptor base; + public ArrayList desc; + + public PrefetchPair(){ + base = new TempDescriptor(""); + desc = new ArrayList(); + } + + public PrefetchPair(TempDescriptor t, Descriptor f) { + base = t; + desc = new ArrayList(); + desc.add(f); + } - public PrefetchPair(){ - base = new TempDescriptor(""); - desc = new ArrayList(); - } - - public PrefetchPair(TempDescriptor t) { - base = t; - desc = null; - } - - public PrefetchPair(TempDescriptor t, Descriptor f) { - base = t; - if (desc == null) - desc = new ArrayList(); - desc.add(f); - } - - public PrefetchPair(TempDescriptor t, ArrayList descriptor) { - base = t; - if(desc == null){ - desc = new ArrayList(); - } - desc.addAll(descriptor); - } - - public TempDescriptor getBase() { - return base; - } - - public Descriptor getDescAt(int index) { - return desc.get(index); - } + public PrefetchPair(TempDescriptor t, ArrayList descriptor) { + base = t; + desc = new ArrayList(); + desc.addAll(descriptor); + } - public ArrayList getDesc() { - return desc; + public TempDescriptor getBase() { + return base; + } + + public Descriptor getDescAt(int index) { + return desc.get(index); + } + + public ArrayList getDesc() { + return desc; + } + + public FieldDescriptor getFieldDesc(int index) { + return (FieldDescriptor) desc.get(index); + } + + public IndexDescriptor getIndexDesc(int index) { + return (IndexDescriptor) desc.get(index); + } + + public int hashCode() { + int hashcode = base.toString().hashCode(); + if(desc != null) { + hashcode^=desc.hashCode(); } - - public FieldDescriptor getFieldDesc(int index) { - return (FieldDescriptor) desc.get(index); - } - - public IndexDescriptor getIndexDesc(int index) { - return (IndexDescriptor) desc.get(index); - } - - public int hashCode() { - int hashcode = base.toString().hashCode(); - if(desc != null) { - ListIterator li = desc.listIterator(); - while(li.hasNext()) { - hashcode = hashcode ^ li.next().toString().hashCode(); - } - } - return hashcode; + return hashcode; + } + + public String toString() { + String label= getBase().toString(); + if(getDesc() == null) + return label; + ListIterator it=getDesc().listIterator(); + for(;it.hasNext();) { + Object o = it.next(); + if(o instanceof FieldDescriptor) { + FieldDescriptor fd = (FieldDescriptor) o; + label+="."+ fd.toString(); + } else { + IndexDescriptor id = (IndexDescriptor) o; + label+= id.toString(); + } } - - public String toString() { - String label= getBase().toString(); - if(getDesc() == null) - return label; - ListIterator it=getDesc().listIterator(); - for(;it.hasNext();) { - Object o = it.next(); - if(o instanceof FieldDescriptor) { - FieldDescriptor fd = (FieldDescriptor) o; - label+="."+ fd.toString(); - } else { - IndexDescriptor id = (IndexDescriptor) o; - label+= id.toString(); - } - } - return label; - } - - public boolean equals(Object o) { - if(o instanceof PrefetchPair) { - PrefetchPair pp = (PrefetchPair) o; - if(base != pp.base) { - return false; - } - if(desc == null && pp.desc == null) { - return true; - } else if(desc != null && pp.desc != null) { - if(desc.equals((ArrayList)pp.desc)) { - return true; - } - } else { - return false; - } - } - return false; + return label; + } + + public boolean equals(Object o) { + if(o instanceof PrefetchPair) { + PrefetchPair pp = (PrefetchPair) o; + return base == pp.base && desc.equals(pp.desc); } - - public Object clone() { - PrefetchPair newpp = new PrefetchPair(); - ArrayList td = null; - newpp.base = this.base; - for(int i = 0; i < this.desc.size(); i++) { - Object o = desc.get(i); - if(o instanceof FieldDescriptor) { - newpp.desc.add((FieldDescriptor) o); - } else { - td = new ArrayList(); - for(int j = 0; j < ((IndexDescriptor)o).tddesc.size(); j++) { - td.add(((IndexDescriptor)o).getTempDescAt(j)); - } - IndexDescriptor idesc = new IndexDescriptor(); - idesc.tddesc = td; - idesc.offset = ((IndexDescriptor)o).offset; - newpp.desc.add(idesc); - } + return false; + } + + public Object clone() { + PrefetchPair newpp = new PrefetchPair(); + newpp.base = this.base; + for(int i = 0; i < this.desc.size(); i++) { + Object o = desc.get(i); + if(o instanceof FieldDescriptor) { + newpp.desc.add((FieldDescriptor) o); + } else { + ArrayList td = new ArrayList(); + for(int j = 0; j < ((IndexDescriptor)o).tddesc.size(); j++) { + td.add(((IndexDescriptor)o).getTempDescAt(j)); } - return newpp; + IndexDescriptor idesc = new IndexDescriptor(); + idesc.tddesc = td; + idesc.offset = ((IndexDescriptor)o).offset; + newpp.desc.add(idesc); + } } + return newpp; + } }