1 | package de.ugoe.cs.quest.tasktrees.nodeequality; |
---|
2 | |
---|
3 | /** |
---|
4 | * <p> |
---|
5 | * A node equality denotes, how equal two task tree nodes are. There are different equality levels |
---|
6 | * which are similar to the usual design levels of GUI design. These levels are |
---|
7 | * <ul> |
---|
8 | * <li>conceptual design: defines the concepts to be edited using a GUI</li> |
---|
9 | * <li>semantical design: defines the possible functions for editing the concepts</li> |
---|
10 | * <li>syntactical design: defines, which steps are needed to execute the functions</li> |
---|
11 | * <li>lexical design: defines on the key stroke level, how the steps for executing a function |
---|
12 | * can be performed</li> |
---|
13 | * </ul> |
---|
14 | * It is not possible to compare two task nodes conceptually. But the other design levels can be |
---|
15 | * identified and compared. |
---|
16 | * </p> |
---|
17 | * <p> |
---|
18 | * Nodes can be identical. This is the case if in the java virtual machine, their comparison |
---|
19 | * using the <code>==</code> operator or the equals method return true. |
---|
20 | * </p> |
---|
21 | * <p> |
---|
22 | * Nodes are lexically equal, if they represent the same events on a key stroke level to be |
---|
23 | * carried out to execute the task. Identical nodes are also syntactically equal. |
---|
24 | * </p> |
---|
25 | * <p> |
---|
26 | * Nodes are syntactically equal, if they differ in their events on key stroke level, but the |
---|
27 | * syntactical result is the same. For example, entering the text "hello" into a text field can |
---|
28 | * be done by entering the letters in their correct order, but also by copying the text into the |
---|
29 | * text field. The syntactical result is the same: The text hello was entered. But the tasks |
---|
30 | * lexically differ because the events on key stroke level are different. On the other hand, |
---|
31 | * lexically equal nodes are also syntactically equal. |
---|
32 | * </p> |
---|
33 | * <p> |
---|
34 | * Task tree nodes are semantically equal, if they execute the same function for editing the |
---|
35 | * concepts. An example are a click on a button and a short cut, both executing the same function. |
---|
36 | * These task tree nodes are syntactically and, therefore, also lexically different, but |
---|
37 | * semantically equal. Syntactically equal task tree nodes are always also semantically equal. |
---|
38 | * </p> |
---|
39 | * |
---|
40 | * @version $Revision: $ $Date: 19.02.2012$ |
---|
41 | * @author 2012, last modified by $Author: patrick$ |
---|
42 | */ |
---|
43 | public enum NodeEquality { |
---|
44 | IDENTICAL, |
---|
45 | LEXICALLY_EQUAL, |
---|
46 | SYNTACTICALLY_EQUAL, |
---|
47 | SEMANTICALLY_EQUAL, |
---|
48 | UNEQUAL; |
---|
49 | |
---|
50 | /** |
---|
51 | * <p> |
---|
52 | * Checks for the current node equality, if it is at least identical to the |
---|
53 | * provided one or even more concrete. As an example, the node equality identical also |
---|
54 | * indicates, that the nodes are e.g. lexically, syntactically and semantically equal. |
---|
55 | * Therefore, the method called on <code>IDENTICAL</code> with <code>SEMANTICALLY_EQUAL</code> |
---|
56 | * as parameter will return true. If this method is called on <code>SYNTACTICALLY_EQUAL</code> |
---|
57 | * with the parameter <code>IDENTICAL</code> instead, it returns false; |
---|
58 | * </p> |
---|
59 | * |
---|
60 | * @param nodeEquality the node equality to compare with. |
---|
61 | * |
---|
62 | * @return as described |
---|
63 | */ |
---|
64 | public boolean isAtLeast(NodeEquality nodeEquality) |
---|
65 | { |
---|
66 | switch (nodeEquality) { |
---|
67 | case IDENTICAL: |
---|
68 | return |
---|
69 | (this == IDENTICAL); |
---|
70 | case LEXICALLY_EQUAL: |
---|
71 | return |
---|
72 | (this == IDENTICAL) || |
---|
73 | (this == LEXICALLY_EQUAL); |
---|
74 | case SYNTACTICALLY_EQUAL: |
---|
75 | return |
---|
76 | (this == IDENTICAL) || |
---|
77 | (this == LEXICALLY_EQUAL) || |
---|
78 | (this == SYNTACTICALLY_EQUAL); |
---|
79 | case SEMANTICALLY_EQUAL: |
---|
80 | return |
---|
81 | (this == IDENTICAL) || |
---|
82 | (this == LEXICALLY_EQUAL) || |
---|
83 | (this == SYNTACTICALLY_EQUAL) || |
---|
84 | (this == SEMANTICALLY_EQUAL); |
---|
85 | case UNEQUAL: |
---|
86 | return |
---|
87 | (this == UNEQUAL); |
---|
88 | default : |
---|
89 | return false; |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | /** |
---|
94 | * <p> |
---|
95 | * returns the common denominator of this node equality and the provided one. I.e. if one |
---|
96 | * equality is e.g. syntactical and the other one only semantical, then semantical is returned. |
---|
97 | * </p> |
---|
98 | * |
---|
99 | * @param equality the equality, to compare this with |
---|
100 | * @return |
---|
101 | */ |
---|
102 | public NodeEquality getCommonDenominator(NodeEquality otherEquality) { |
---|
103 | if (this.isAtLeast(otherEquality)) { |
---|
104 | return otherEquality; |
---|
105 | } |
---|
106 | else if (otherEquality.isAtLeast(this)) { |
---|
107 | return this; |
---|
108 | } |
---|
109 | else { |
---|
110 | return NodeEquality.UNEQUAL; |
---|
111 | } |
---|
112 | } |
---|
113 | } |
---|