1
18
19 package gate.creole.ontology;
20
21 import java.util.*;
22
23 public class OClassImpl extends TClassImpl implements OClass {
24
25 private Set disjointClassesSet;
26 private Set sameClassesSet;
27 private Set propertiesSet;
28
29
36 public OClassImpl(String anId, String aName, String aComment, Ontology anOntology) {
37 super(anId, aName, aComment, anOntology);
38 disjointClassesSet = new HashSet();
39 sameClassesSet = new HashSet();
40 propertiesSet = new HashSet();
41 }
42
43 public void setDisjointWith(OClass theClass) {
44 if (theClass == null)
45 return;
46 disjointClassesSet.add(theClass);
47 }
48
49 public void setSameClassAs(OClass theClass) {
50 if (theClass == null)
51 return;
52 this.sameClassesSet.add(theClass);
53 }
54
55 public Set getDisjointClasses() {
56 if (this.disjointClassesSet.isEmpty())
57 return null;
58 return this.disjointClassesSet;
59 }
60
61 public Set getSameClasses() {
62 if (this.sameClassesSet.isEmpty())
63 return null;
64 return this.sameClassesSet;
65 }
66
67 public Set getProperties() {
68 if (this.propertiesSet.isEmpty())
69 return null;
70 return this.propertiesSet;
71 }
72
73 public Set getPropertiesByName(String name) {
74 HashSet resultSet = new HashSet();
75 if (this.propertiesSet.isEmpty())
76 return resultSet;
77 if (name == null)
78 return resultSet;
79 Iterator iter = this.propertiesSet.iterator();
80 while (iter.hasNext()) {
81 Property property = (Property) iter.next();
82 if (name.equals(property.getName()))
83 resultSet.add(property);
84 }
85 return resultSet;
86 }
87
88 public Set getInheritedProperties() {
89 Set superClasses = null;
90 try {
91 this.getSuperClasses(OClass.TRANSITIVE_CLOSURE);
92 } catch (NoSuchClosureTypeException ex) {};
93
94 Set inheritedProperties = new HashSet();
95 if (superClasses == null || superClasses.isEmpty())
96 return inheritedProperties;
97 Iterator iter = superClasses.iterator();
98 while (iter.hasNext()) {
99 Set classProperties = ((OClass)iter.next()).getProperties();
100 if (classProperties != null)
101 inheritedProperties.addAll(classProperties);
102 } return inheritedProperties;
104 }
105
106 public boolean addProperty(Property theProperty) {
107 if (this.propertiesSet == null)
108 this.propertiesSet = new HashSet();
109 if (! this.equals(theProperty.getDomain()))
110 return false;
111 this.propertiesSet.add(theProperty);
112 return true;
113 }
114
115 public String toString() {
116 return this.getName();
117 }
118 }