View Javadoc
1   /*
2    * Copyright 2013-2023 Medical Information Systems Research Group (https://medical.zcu.cz),
3    * Department of Computer Science and Engineering, University of West Bohemia.
4    * Address: Univerzitni 8, 306 14 Plzen, Czech Republic.
5    *
6    * This file is part of Sparkle project.
7    *
8    * Sparkle is free software: you can redistribute it and/or modify
9    * it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation, either version 3 of the License.
11   *
12   * Sparkle is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with Sparkle. If not, see <http://www.gnu.org/licenses/>.
19   */
20  package cz.zcu.mre.sparkle.data;
21  
22  import cz.zcu.mre.sparkle.tools.Definitions;
23  import java.io.Serializable;
24  
25  /**
26   * @author Jan Smucr
27   * @author Petr Vcelak (vcelak@kiv.zcu.cz)
28   * @author Klara Hlavacova
29   */
30  public class StorageEntry
31          implements Serializable {
32  
33      private static final long serialVersionUID = 7636245589791303795L;
34  
35      private final String alternativeURI;
36      private final String namespace;
37      private final String localName;
38      private final String title;
39  
40      public StorageEntry(final String namespace, final String localName) {
41          this(namespace, localName, "");
42      }
43  
44      public StorageEntry(final String namespace, final String localName, String title) {
45          this("", namespace, localName, title);
46      }
47  
48      public StorageEntry(StorageEntry storageEntry) {
49          this(storageEntry.getAlternativeURI(), storageEntry.namespace, storageEntry.localName, storageEntry.title);
50      }
51  
52      public StorageEntry(String alternativeURI, String namespace, String localName, String title) {
53          this.alternativeURI = alternativeURI == null ? "" : alternativeURI;
54          this.namespace = namespace == null ? "" : namespace;
55          this.localName = localName;
56          this.title = title == null ? "" : title;
57      }
58  
59      public String getShortVariant(final PrefixesStorage prefixesStorage) {
60          if (namespace == null || namespace.isEmpty()) {
61              return getIRI();
62          }
63  
64          final String prefix = prefixesStorage.getIriToPrefixReadOnly().get(namespace);
65          if (prefix == null) {
66              return null;
67          }
68  
69          return prefix + Definitions.PREFIXED_NAME_PREFIX_DELIMITER + localName;
70      }
71  
72      public String getNamespace() {
73          return namespace;
74      }
75  
76      public String getLocalName() {
77          return localName;
78      }
79  
80      public String getIRI() {
81          if (namespace == null) {
82              return localName;
83          }
84  
85          return namespace + localName;
86      }
87  
88      public String getWrappedIRI() {
89          return Definitions.IRI_PREFIX + getIRI() + Definitions.IRI_SUFFIX;
90      }
91  
92      public String getTitle() {
93          return title;
94      }
95  
96      private String getAlternativeURI() {
97          return alternativeURI;
98      }
99  
100     @Override
101     public boolean equals(final Object obj) {
102         if (!(obj instanceof StorageEntry)) {
103             return false;
104         }
105         return getIRI().equals(((StorageEntry) obj).getIRI());
106     }
107 
108     @Override
109     public int hashCode() {
110         return getIRI().hashCode();
111     }
112 }