1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package net.sourceforge.plantumldependency.commoncli.option.execution;
26
27 import static java.util.logging.Level.SEVERE;
28 import static java.util.logging.Logger.getLogger;
29 import static net.sourceforge.plantumldependency.common.constants.log.ErrorConstants.UNEXPECTED_ERROR;
30 import static net.sourceforge.plantumldependency.common.utils.comparable.ComparableResult.AFTER;
31 import static net.sourceforge.plantumldependency.common.utils.comparable.ComparableResult.BEFORE;
32 import static net.sourceforge.plantumldependency.common.utils.comparable.ComparableResult.EQUAL;
33
34 import java.util.logging.Logger;
35
36
37
38
39
40
41
42
43 public abstract class AbstractOptionExecution implements OptionExecution {
44
45
46 private static final transient Logger LOGGER = getLogger(AbstractOptionExecution.class.getName());
47
48
49 private static final long serialVersionUID = -6822376158952497623L;
50
51
52 private int priority;
53
54
55
56
57
58
59
60
61
62 protected AbstractOptionExecution(final int optionPriority) {
63 setPriority(optionPriority);
64 }
65
66
67
68
69
70
71 @Override
72 public int compareTo(final OptionExecution o) {
73 final int comparison;
74 if (getPriority() < o.getPriority()) {
75 comparison = BEFORE.getResult();
76 } else if (getPriority() == o.getPriority()) {
77 comparison = EQUAL.getResult();
78 } else {
79 comparison = AFTER.getResult();
80 }
81 return comparison;
82 }
83
84
85
86
87
88
89 @Override
90 public OptionExecution deepClone() {
91 OptionExecution o = null;
92
93 try {
94 o = (AbstractOptionExecution) super.clone();
95 } catch (final CloneNotSupportedException cnse) {
96 LOGGER.log(SEVERE, UNEXPECTED_ERROR, cnse);
97 }
98
99 return o;
100 }
101
102
103
104
105
106
107 @Override
108 public boolean equals(final Object obj) {
109 if (this == obj) {
110 return true;
111 }
112 if (obj == null) {
113 return false;
114 }
115 if (getClass() != obj.getClass()) {
116 return false;
117 }
118 final AbstractOptionExecution other = (AbstractOptionExecution) obj;
119 if (priority != other.priority) {
120 return false;
121 }
122 return true;
123 }
124
125
126
127
128
129
130 @Override
131 public int getPriority() {
132 return priority;
133 }
134
135
136
137
138
139
140 @Override
141 public int hashCode() {
142 final int prime = 31;
143 int result = 1;
144 result = prime * result + priority;
145 return result;
146 }
147
148
149
150
151
152
153
154
155
156 private void setPriority(final int value) {
157 priority = value;
158 }
159
160
161
162
163
164
165 @Override
166 public String toString() {
167 return getClass().getSimpleName() + " [priority=" + priority + "]";
168 }
169 }