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.program.execution.impl;
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.check.ParameterCheckerUtils.checkNull;
31 import static net.sourceforge.plantumldependency.common.utils.comparable.ComparableResult.EQUAL;
32 import static net.sourceforge.plantumldependency.commoncli.constants.log.ErrorConstants.OPTION_EXECUTIONS_NULL_ERROR;
33
34 import java.util.Set;
35 import java.util.TreeSet;
36 import java.util.logging.Logger;
37
38 import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
39 import net.sourceforge.plantumldependency.commoncli.option.execution.OptionExecution;
40 import net.sourceforge.plantumldependency.commoncli.program.execution.JavaProgramExecution;
41
42
43
44
45
46
47
48
49 public class JavaProgramExecutionImpl implements JavaProgramExecution {
50
51
52 private static final long serialVersionUID = 8850565339062462441L;
53
54
55 private static final transient Logger LOGGER = getLogger(JavaProgramExecutionImpl.class.getName());
56
57
58 private Set < OptionExecution > optionExecutions;
59
60
61
62
63
64
65
66
67 public JavaProgramExecutionImpl(final Set < OptionExecution > executions) {
68 setOptionExecutions(executions);
69 }
70
71
72
73
74
75
76 @Override
77 public int compareTo(final JavaProgramExecution o) {
78 return EQUAL.getResult();
79 }
80
81
82
83
84
85
86 @Override
87 public JavaProgramExecution deepClone() {
88 JavaProgramExecutionImpl j = null;
89
90 try {
91 j = (JavaProgramExecutionImpl) super.clone();
92 j.optionExecutions = new TreeSet < OptionExecution >();
93 for (final OptionExecution optionExecution : getOptionExecutions()) {
94 j.optionExecutions.add(optionExecution.deepClone());
95 }
96 } catch (final CloneNotSupportedException cnse) {
97 LOGGER.log(SEVERE, UNEXPECTED_ERROR, cnse);
98 }
99
100 return j;
101 }
102
103
104
105
106
107
108 @Override
109 public boolean equals(final Object obj) {
110 if (this == obj) {
111 return true;
112 }
113 if (obj == null) {
114 return false;
115 }
116 if (getClass() != obj.getClass()) {
117 return false;
118 }
119 final JavaProgramExecutionImpl other = (JavaProgramExecutionImpl) obj;
120 if (optionExecutions == null) {
121 if (other.optionExecutions != null) {
122 return false;
123 }
124 } else if (!optionExecutions.equals(other.optionExecutions)) {
125 return false;
126 }
127 return true;
128 }
129
130
131
132
133
134
135 @Override
136 public void execute() throws CommandLineException {
137 for (final OptionExecution optionExecution : getOptionExecutions()) {
138 optionExecution.execute();
139 }
140 }
141
142
143
144
145
146
147 @Override
148 public Set < OptionExecution > getOptionExecutions() {
149 return optionExecutions;
150 }
151
152
153
154
155
156
157 @Override
158 public int hashCode() {
159 final int prime = 31;
160 int result = 1;
161 result = prime * result + ((optionExecutions == null) ? 0 : optionExecutions.hashCode());
162 return result;
163 }
164
165
166
167
168
169
170
171
172
173 private void setOptionExecutions(final Set < OptionExecution > value) {
174 checkNull(value, OPTION_EXECUTIONS_NULL_ERROR);
175
176 optionExecutions = value;
177 }
178
179
180
181
182
183
184 @Override
185 public String toString() {
186 return getClass().getSimpleName() + " [optionExecutions=" + optionExecutions + "]";
187 }
188 }