/* * Created on 29 nov. 2004 * */ package fr.lifl.stc.stan.signature; import java.io.Serializable; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Set; /** * @author ryl * */ public class Signature implements Serializable { static final long serialVersionUID = 0; private HashMap m; private boolean locked = false; public Signature() { m = new HashMap(); } public void lock() { locked = true; } public boolean isLocked() { return locked; } public boolean isFinal() { return isLocked(); } public void setFinal(boolean b) { if(b) locked = true; else locked = false; } public void add (PartialSignature ps){ m.put(ps.getClassId(),ps); } public PartialSignature getPartialSignature (String classname){ return m.get(classname); } public Collection getPartialSignatures() { return m.values(); } public boolean equals (Object o){ if (o == null || !(o instanceof Signature)) return false; Collection c1 = m.values(); Collection c2 = ((Signature)o).m.values(); Iterator it; it = c1.iterator(); while(it.hasNext()) { if (!c2.contains(it.next())) return false; } it = c2.iterator(); while(it.hasNext()) { if (!c1.contains(it.next())) return false; } return true; } public boolean compatibleWith(Signature sign) { Collection s1 = m.values(); // Collection s2 = sign.m.values(); boolean res = true; Iterator it1 = s1.iterator(); while(it1.hasNext()) { PartialSignature ps1 = it1.next(); PartialSignature ps2 = sign.getPartialSignature(ps1.getClassId()); res = res && ps1.compatibleWith(ps2); } return res; } public Object clone() { Signature res = new Signature(); Set s = m.keySet(); Iterator it = s.iterator(); while(it.hasNext()) { PartialSignature ps = m.get(it.next()); res.add((PartialSignature) ps.clone()); } return res; } public void makeAccept(Signature sign) { if(locked) { System.err.println("Signature locked"); //System.err.println("Incompatible signature for this method"); //System.exit(1); } Collection s1 = m.values(); Iterator it1 = s1.iterator(); while(it1.hasNext()) { PartialSignature ps1 = it1.next(); PartialSignature ps2 = sign.getPartialSignature(ps1.getClassId()); ps1.makeAccept(ps2); } } public String toString() { String res = ""; Collection c = m.values(); Iterator it = c.iterator(); while(it.hasNext()) { res += it.next() + "\n"; } return res; } public String toHTMLString() { String res = ""; Collection c = m.values(); Iterator it = c.iterator(); while(it.hasNext()) { res += it.next().toHTMLString() + "\n"; } return res; } }