1 package org.molwind.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.HashMap;
23
24
25
26
27
28
29
30 public class BaseWorldEntity implements WorldEntity {
31
32 protected ArrayList relationships;
33 private HashMap attributes;
34
35
36
37
38
39
40
41
42
43
44 public void putAttribute(String name,Object value){
45
46 attributes.put(name,value);
47
48 }
49
50
51
52
53
54
55
56
57
58
59
60 public Object getAttribute(final String name){
61 return attributes.get(name);
62
63 }
64
65 protected BaseWorldEntity() {
66 relationships = new ArrayList();
67 attributes = new HashMap();
68 }
69
70
71
72
73
74
75
76 public Iterator getRelationships() {
77 return relationships.iterator();
78 }
79
80
81
82
83
84
85
86
87
88
89 public boolean existRelationship(final Relationship relation) {
90 return relationships.contains(relation);
91 }
92
93
94
95
96
97
98
99 public void addRelationship(final Relationship relation) {
100 if ((relation.getLeft() == null)
101 && (relation instanceof BaseRelationship)) {
102 ((BaseRelationship) relation).setLeft(this);
103 }
104
105 if ((relation.getRight() == null)
106 && (relation instanceof BaseRelationship)) {
107 ((BaseRelationship) relation).setRight(this);
108 }
109
110 relationships.add(relation);
111 }
112
113
114
115
116
117
118
119
120
121 public Relationship[] getRelationship(final Relationship relation) {
122 Iterator it = getRelationships();
123 ArrayList matches = new ArrayList();
124 BaseRelationship baseRelation = null;
125
126 if (relation instanceof PartialMatch) {
127 baseRelation = (BaseRelationship) relation;
128 }
129
130 while (it.hasNext()) {
131 Relationship rel = (Relationship) it.next();
132 boolean addIt = false;
133
134 if (baseRelation != null) {
135 addIt = baseRelation.matches(rel);
136 } else {
137 addIt = rel.equals(relation);
138 }
139
140 if (addIt) {
141 matches.add(rel);
142 }
143 }
144
145 Relationship[] relations = new Relationship[matches.size()];
146
147 return ((Relationship[]) matches.toArray(relations));
148 }
149
150
151
152
153
154 public int getDimension(){
155 return 0;
156 }
157
158 }