01: package org.umlgraph.doclet;
02:
03: /**
04: * A map from relation types to directions
05: * @author wolf
06: *
07: */
08: public class RelationPattern {
09: /**
10: * A map from RelationType (indexes) to Direction objects
11: */
12: RelationDirection[] directions;
13:
14: /**
15: * Creates a new pattern using the same direction for every relation kind
16: * @param defaultDirection The direction used to initialize this pattern
17: */
18: public RelationPattern(RelationDirection defaultDirection) {
19: directions = new RelationDirection[RelationType.values().length];
20: for (int i = 0; i < directions.length; i++) {
21: directions[i] = defaultDirection;
22: }
23: }
24:
25: /**
26: * Adds, eventually merging, a direction for the specified relation type
27: * @param relationType
28: * @param direction
29: */
30: public void addRelation(RelationType relationType,
31: RelationDirection direction) {
32: int idx = relationType.ordinal();
33: directions[idx] = directions[idx].sum(direction);
34: }
35:
36: /**
37: * Returns true if this patterns matches at least the direction of one
38: * of the relations in the other relation patterns. Matching is defined
39: * by {@linkplain RelationDirection#contains(RelationDirection)}
40: * @param relationPattern
41: * @return
42: */
43: public boolean matchesOne(RelationPattern relationPattern) {
44: for (int i = 0; i < directions.length; i++) {
45: if (directions[i].contains(relationPattern.directions[i]))
46: return true;
47: }
48: return false;
49: }
50:
51: }
|