applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / client / VorbaId.java
1 /*
2  * This file is part of the Vamsas Client version 0.1. 
3  * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, 
4  *  Andrew Waterhouse and Dominik Lindner.
5  * 
6  * Earlier versions have also been incorporated into Jalview version 2.4 
7  * since 2008, and TOPALi version 2 since 2007.
8  * 
9  * The Vamsas Client is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *  
14  * The Vamsas Client is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  * 
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with the Vamsas Client.  If not, see <http://www.gnu.org/licenses/>.
21  */
22 package uk.ac.vamsas.client;
23
24 import java.io.Serializable;
25
26 /**
27  * The unique reference id for a Vamsas document Vobject, used by applications
28  * to refer to the vamsas Vobject within their own data space in the vamsas
29  * document. This is serializable (thanks to Dominik Lindner) so an application
30  * can store it easily.
31  * 
32  * @author jimp
33  */
34 public class VorbaId implements Serializable {
35   /**
36    * 1 is first vamsas release ID version.
37    */
38   private static final long serialVersionUID = 1L;
39
40   protected String id;
41
42   protected VorbaId() {
43     super();
44   }
45
46   private VorbaId(String Id) {
47     super();
48     id = Id;
49   }
50
51   /**
52    * 
53    * @param vorbaObject
54    *          the source of vorba Ids
55    * @param vobject
56    *          the Vobject to be registered with a new vorba id
57    * @return
58    */
59   protected static VorbaId newId(IVorbaIdFactory vorbaObject, Vobject vobject) {
60     // Make unique id from appSpace info in vorbaObject
61     synchronized (vorbaObject) {
62       vobject.vorbaId = vorbaObject.makeVorbaId(vobject);
63       return vobject.vorbaId;
64     }
65   }
66
67   /**
68    * protected VorbaId constructor used when turning XML ID strings into vorba
69    * IDs
70    * 
71    * @param id
72    * @return VorbaId object or null if string was null.
73    */
74   protected static VorbaId newId(String id) {
75     return (id == null) ? null : new VorbaId(id);
76   }
77
78   /**
79    * @return Returns the id.
80    */
81   public String getId() {
82     return id;
83   }
84
85   /*
86    * (non-Javadoc)
87    * 
88    * @see java.lang.Object#equals(java.lang.Object)
89    */
90   public boolean equals(Object obj) {
91     if (obj instanceof String)
92       return id.equals(obj);
93     else if (obj instanceof VorbaId)
94       return id.equals(((VorbaId) obj).id);
95     return false;
96   }
97
98   /*
99    * (non-Javadoc)
100    * 
101    * @see java.lang.Object#hashCode()
102    */
103   public int hashCode() {
104     return id.hashCode();
105   }
106
107   /*
108    * (non-Javadoc)
109    * 
110    * @see java.lang.Object#toString()
111    */
112   public String toString() {
113     return id;
114   }
115
116 }