01 /*
02 * Copyright (c) 1995-2010, The University of Sheffield. See the file
03 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
04 *
05 * This file is part of GATE (see http://gate.ac.uk/), and is free
06 * software, licenced under the GNU Library General Public License,
07 * Version 2, June 1991 (in the distribution as file licence.html,
08 * and also available at http://gate.ac.uk/gate/licence.html).
09 *
10 * Valentin Tablan, 24 Apr 2008
11 *
12 * $Id: AnnotationDataImpl.java 12006 2009-12-01 17:24:28Z thomas_heitz $
13 */
14 package gate.gui.annedit;
15
16 import gate.Annotation;
17 import gate.AnnotationSet;
18
19 /**
20 * A simple reusable implementation of {@link AnnotationData}.
21 */
22 public class AnnotationDataImpl implements AnnotationData {
23 public AnnotationDataImpl(AnnotationSet set, Annotation ann){
24 this.ann = ann;
25 this.set = set;
26 }
27
28
29 Annotation ann;
30 AnnotationSet set;
31 /**
32 * @return the ann
33 */
34 public Annotation getAnnotation() {
35 return ann;
36 }
37 /**
38 * @return the set
39 */
40 public AnnotationSet getAnnotationSet() {
41 return set;
42 }
43 /* (non-Javadoc)
44 * @see java.lang.Object#hashCode()
45 */
46 @Override
47 public int hashCode() {
48 final int prime = 31;
49 int result = 1;
50 result = prime * result + ((ann == null) ? 0 : ann.hashCode());
51 String setName = set.getName();
52 result = prime * result + ((setName == null) ? 0 : setName.hashCode());
53 return result;
54 }
55 /* (non-Javadoc)
56 * @see java.lang.Object#equals(java.lang.Object)
57 */
58 @Override
59 public boolean equals(Object obj) {
60 if(this == obj) return true;
61 if(obj == null) return false;
62 if(!(obj instanceof AnnotationDataImpl)) return false;
63 final AnnotationDataImpl other = (AnnotationDataImpl)obj;
64 if(ann == null) {
65 if(other.ann != null) return false;
66 }
67 else if(!ann.equals(other.ann)) return false;
68 if(set == null) {
69 if(other.set != null) return false;
70 }
71 else if(set != other.set) return false;
72 return true;
73 }
74 }
|