Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/bdgp/apps/dagedit/datamodel/Synonym.java


1   package org.bdgp.apps.dagedit.datamodel;
2   
3   import javax.swing.undo.*;
4   import java.util.*;
5   import org.bdgp.util.*;
6   import java.io.Serializable;
7   
8   public class Synonym implements StateEditable, Cloneable, Serializable {
9   
10      protected String id;
11      protected String text;
12      private static int idgen = 0;
13      protected int privateid;
14      protected Vector references;
15  
16      public Synonym(String text) {
17    this(null, text);
18      }
19  
20      public Synonym(String id, String text) {
21    this.id = id;
22    this.text = text;
23    privateid = idgen++;
24    references = new Vector();
25      }
26  
27      public void addDbxref(Dbxref ref) {
28    if (!references.contains(ref))
29        references.addElement(ref);
30      }
31  
32      public void setDbxrefs(Vector references) {
33    this.references = references;
34      }
35  
36      public Vector getDbxrefs() {
37    return references;
38      }
39  
40      public Object clone() {
41    try {
42        Synonym s = (Synonym) super.clone();
43        s.setDbxrefs(VectorUtil.trueClone(references));
44        return s;
45    } catch (CloneNotSupportedException e) {
46        // will never happen
47        return null;
48    }
49      }
50  
51      public String toString() {
52    String out = text;
53    if (out != null && out.length() > 0) {
54        if (id != null && id.length() > 0)
55      out += ":"+id;      
56    } else
57        out = id;
58    return out;
59      }
60  
61      public void setID(String id) {
62    if (id.length() == 0)
63        this.id = null;
64    else
65        this.id = id;
66      }
67  
68      public String getText() {
69    return text;
70      }
71  
72      public void setText(String text) {
73    if (text.length() == 0)
74        this.text = null;
75    else
76        this.text = text;
77      }
78  
79      public String getID() {
80    return id;
81      }
82  
83      public boolean equals(Object o) {
84    if (o instanceof Synonym) {
85        Synonym in = (Synonym) o;
86        return ObjectUtil.equals(text, in.getText()) &&
87      ObjectUtil.equals(id, in.getID()) &&
88      in.getDbxrefs().equals(references);
89    } else
90        return false;
91      }
92  
93      public void storeState(Hashtable state) {
94    if (id != null)
95        state.put("synonym.id", id);
96    if (text != null)
97        state.put("synonym.text", text);
98    state.put("synonym.refs", references.clone());
99      }
100 
101     public void restoreState(Hashtable state) {
102   String storedID = (String) state.get("synonym.id");
103   String storedText = (String) state.get("synonym.text");
104   Vector storedRefs = (Vector) state.get("synonym.refs");
105   if (storedID != null)
106       id = storedID;
107   if (storedText != null)
108       text = storedText;
109   if (storedRefs != null)
110       references = storedRefs;
111     }
112 }
113 
114 
115 
116 
117 
118