View Javadoc

1   package org.kite9.diagram.adl;
2   
3   import com.thoughtworks.xstream.annotations.XStreamAlias;
4   import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
5   
6   
7   @XStreamAlias("symbol")
8   public class Symbol implements Comparable<Symbol> {
9   
10  	private static final long serialVersionUID = 3578883565482903409L;
11  	
12  	@XStreamAsAttribute
13  	String id;
14  	
15  	public String getID() {
16  		return id;
17  	}
18  
19  	@XStreamAsAttribute
20  	char theChar;
21  	
22  	@XStreamAsAttribute
23  	SymbolShape shape;
24  	
25  	public enum SymbolShape { HEXAGON, CIRCLE,  DIAMOND };
26  
27  	@Override
28  	public boolean equals(Object arg0) {
29  		if (arg0 == this)
30  			return true;
31  	
32  		if (arg0 instanceof Symbol)
33  			return ((Symbol)arg0).getID().equals(getID());
34  		else
35  			return false;
36  	}
37  
38  	@Override
39  	public String toString() {
40  		return "Symbol: "+getID();
41  	}
42  	
43  	public Symbol() {
44  	}
45  
46  	public Symbol(String text, char preferredChar, SymbolShape shape) {
47  		this.id = text;
48  		this.theChar = preferredChar;
49  		this.shape = shape;
50  	}
51  
52  	public char getChar() {
53  		return theChar;
54  	}
55  
56  	public void setChar(char theChar) {
57  		this.theChar = theChar;
58  	}
59  
60  	public SymbolShape getShape() {
61  		return shape;
62  	}
63  
64  	public void setShape(SymbolShape shape) {
65  		this.shape = shape;
66  	}
67  
68  	public int compareTo(Symbol o) {
69  		int out = ((Character)this.theChar).compareTo(o.theChar);
70  		if (out==0) {
71  			return this.shape.compareTo(o.shape);
72  		} else {
73  			return out;
74  		}
75  	}
76  	
77  	
78  	
79  }