Skip to content

Commit b87769a

Browse files
committed
operation methods and parameters refactor
1 parent 27a9331 commit b87769a

21 files changed

Lines changed: 1310 additions & 1451 deletions

src/main/java/mil/nga/crs/CRS.java

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package mil.nga.crs;
22

33
import java.io.IOException;
4+
import java.util.LinkedHashMap;
5+
import java.util.Map;
46
import java.util.logging.Level;
57
import java.util.logging.Logger;
68

@@ -24,6 +26,12 @@ public abstract class CRS implements ScopeExtentIdentifierRemark {
2426
*/
2527
private CRSType type = null;
2628

29+
/**
30+
* Temporary extras that are not included as part of the CRS definition. Not
31+
* included in equality and hashing.
32+
*/
33+
private Map<String, Object> extras = null;
34+
2735
/**
2836
* Constructor
2937
*/
@@ -73,6 +81,88 @@ public CategoryType getCategoryType() {
7381
return categoryType;
7482
}
7583

84+
/**
85+
* Get temporary extras that are not part of the CRS definition
86+
*
87+
* @return extras
88+
*/
89+
public Map<String, Object> getExtras() {
90+
return extras;
91+
}
92+
93+
/**
94+
* Determine if there are temporary extras that are not part of the CRS
95+
* definition
96+
*
97+
* @return true if extras
98+
*/
99+
public boolean hasExtras() {
100+
return extras != null && !extras.isEmpty();
101+
}
102+
103+
/**
104+
* Get the number of temporary extras that are not part of the CRS
105+
* definition
106+
*
107+
* @return number of extras
108+
*/
109+
public int numExtras() {
110+
return extras != null ? extras.size() : 0;
111+
}
112+
113+
/**
114+
* Get the temporary extra with the name
115+
*
116+
* @param name
117+
* extra name
118+
* @return extra value or null
119+
*/
120+
public Object getExtra(String name) {
121+
Object extra = null;
122+
if (hasExtras()) {
123+
extra = extras.get(name);
124+
}
125+
return extra;
126+
}
127+
128+
/**
129+
* Set the temporary extras that are not part of the CRS definition
130+
*
131+
* @param extras
132+
* extras
133+
*/
134+
public void setExtras(Map<String, Object> extras) {
135+
this.extras = extras;
136+
}
137+
138+
/**
139+
* Add the temporary extra which is not part of the CRS definition
140+
*
141+
* @param name
142+
* extra name
143+
* @param extra
144+
* extra value
145+
*/
146+
public void addExtra(String name, Object extra) {
147+
if (extras == null) {
148+
extras = new LinkedHashMap<>();
149+
}
150+
extras.put(name, extra);
151+
}
152+
153+
/**
154+
* Add the temporary extras which are not part of the CRS definition
155+
*
156+
* @param extras
157+
* extra values
158+
*/
159+
public void addExtras(Map<String, Object> extras) {
160+
if (this.extras == null) {
161+
this.extras = new LinkedHashMap<>();
162+
}
163+
this.extras.putAll(extras);
164+
}
165+
76166
/**
77167
* {@inheritDoc}
78168
*/

src/main/java/mil/nga/crs/operation/CoordinateOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public CoordinateOperation(String name, CoordinateReferenceSystem source,
5050
*/
5151
@Override
5252
public OperationType getOperationType() {
53-
return OperationType.COORDINATE_OPERATION;
53+
return OperationType.COORDINATE;
5454
}
5555

5656
/**

src/main/java/mil/nga/crs/operation/OperationMethod.java

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ public class OperationMethod implements Identifiable {
3131
/**
3232
* Operation parameters
3333
*/
34-
private List<Parameter> parameters = null;
34+
private List<OperationParameter> parameters = null;
3535

3636
/**
3737
* Identifiers
3838
*/
3939
private List<Identifier> identifiers = null;
4040

41+
/**
42+
* Commonly encountered operation methods
43+
*/
44+
private OperationMethods method;
45+
4146
/**
4247
* Constructor
4348
*/
@@ -52,7 +57,19 @@ public OperationMethod() {
5257
* name
5358
*/
5459
public OperationMethod(String name) {
55-
setName(name);
60+
this.name = name;
61+
updateMethod();
62+
}
63+
64+
/**
65+
* Constructor
66+
*
67+
* @param method
68+
* operation method
69+
*/
70+
public OperationMethod(OperationMethods method) {
71+
this.name = method.getName();
72+
this.method = method;
5673
}
5774

5875
/**
@@ -72,14 +89,15 @@ public String getName() {
7289
*/
7390
public void setName(String name) {
7491
this.name = name;
92+
updateMethod();
7593
}
7694

7795
/**
7896
* Get the parameters
7997
*
8098
* @return parameters
8199
*/
82-
public List<Parameter> getParameters() {
100+
public List<OperationParameter> getParameters() {
83101
return parameters;
84102
}
85103

@@ -108,7 +126,7 @@ public int numParameters() {
108126
* parameter index
109127
* @return parameter
110128
*/
111-
public Parameter getParameter(int index) {
129+
public OperationParameter getParameter(int index) {
112130
return parameters.get(index);
113131
}
114132

@@ -118,9 +136,8 @@ public Parameter getParameter(int index) {
118136
* @param parameters
119137
* parameters
120138
*/
121-
public void setParameters(List<Parameter> parameters) {
122-
this.parameters = null;
123-
addParameters(parameters);
139+
public void setParameters(List<OperationParameter> parameters) {
140+
this.parameters = parameters;
124141
}
125142

126143
/**
@@ -129,7 +146,7 @@ public void setParameters(List<Parameter> parameters) {
129146
* @param parameter
130147
* parameter
131148
*/
132-
public void addParameter(Parameter parameter) {
149+
public void addParameter(OperationParameter parameter) {
133150
if (this.parameters == null) {
134151
this.parameters = new ArrayList<>();
135152
}
@@ -142,10 +159,11 @@ public void addParameter(Parameter parameter) {
142159
* @param parameters
143160
* parameters
144161
*/
145-
public void addParameters(List<Parameter> parameters) {
146-
for (Parameter parameter : parameters) {
147-
addParameter(parameter);
162+
public void addParameters(List<OperationParameter> parameters) {
163+
if (this.parameters == null) {
164+
this.parameters = new ArrayList<>();
148165
}
166+
this.parameters.addAll(parameters);
149167
}
150168

151169
/**
@@ -210,6 +228,41 @@ public void addIdentifiers(List<Identifier> identifiers) {
210228
this.identifiers.addAll(identifiers);
211229
}
212230

231+
/**
232+
* Get the commonly known method type
233+
*
234+
* @return method type or null
235+
*/
236+
public OperationMethods getMethod() {
237+
return method;
238+
}
239+
240+
/**
241+
* Is a commonly known method type
242+
*
243+
* @return true if has common method type
244+
*/
245+
public boolean hasMethod() {
246+
return getMethod() != null;
247+
}
248+
249+
/**
250+
* Set the commonly known method type
251+
*
252+
* @param method
253+
* method type or null
254+
*/
255+
public void setMethod(OperationMethods method) {
256+
this.method = method;
257+
}
258+
259+
/**
260+
* Update the commonly known method type using the name
261+
*/
262+
public void updateMethod() {
263+
setMethod(OperationMethods.getMethod(getName()));
264+
}
265+
213266
/**
214267
* {@inheritDoc}
215268
*/

0 commit comments

Comments
 (0)