View Javadoc

1   /*
2    *  Copyright (C) 2003-2005 SINTEF
3    *  Author:  fredrik dot vraalsen at sintef dot no
4    *  Webpage: http://coras.sourceforge.net/
5    *
6    *  This program is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public License
8    *  as published by the Free Software Foundation; either version 2.1
9    *  of the License, or (at your option) any later version.
10   *
11   *  This program is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this program; if not, write to the Free
18   *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19   *  02111-1307 USA
20   */
21  package no.sintef.assetrepository;
22  
23  import java.io.Serializable;
24  import java.util.ArrayList;
25  import java.util.Collection;
26  import java.util.Collections;
27  
28  import no.sintef.assetrepository.interfaces.AssetVersionPK;
29  
30  /***
31   * @author fvr
32   *
33   * TODO To change the template for this generated type comment go to
34   * Window - Preferences - Java - Code Style - Code Templates
35   */
36  public class VersionHistory implements Serializable {
37  
38      private AssetVersionPK rootVersion;
39      private Collection versions;
40  
41      public VersionHistory() {
42          this(null, new ArrayList());
43      }
44      
45      /***
46       * @param rootVersion
47       * @param versions
48       */
49      public VersionHistory(AssetVersionPK rootVersion, Collection versions) {
50          this.rootVersion = rootVersion;
51          this.versions = versions;
52      }
53  
54      public AssetVersionPK getRootVersion() {
55          return rootVersion;
56      }
57      public void setRootVersion(AssetVersionPK rootVersion) {
58          this.rootVersion = rootVersion;
59      }
60      
61      public Collection getVersions() {
62          return Collections.unmodifiableCollection(versions);
63      }
64      public void addVersion(AssetVersionPK newVersion) {
65          versions.add(newVersion);
66      }
67      public void removeVersion(AssetVersionPK oldVersion) {
68          versions.remove(oldVersion);
69      }
70      
71      public boolean equals(Object obj) {
72          if (obj instanceof VersionHistory) {
73              boolean equals = true;
74              VersionHistory other = (VersionHistory) obj;
75              equals &= (rootVersion == other.rootVersion || 
76                      (rootVersion != null && rootVersion.equals(other.rootVersion)));
77              equals &= (versions == other.versions ||
78                      (versions != null && versions.equals(other.versions)));
79              return equals;
80          } else {
81              return false;
82          }
83      }
84      public int hashCode() {
85          int result = 0;
86          result += 37 * (rootVersion != null ? rootVersion.hashCode() : 0);
87          result += 37 * (versions != null ? versions.hashCode() : 0);
88          return result;
89      }
90  
91  }