Skip to content

Commit 6318e20

Browse files
committed
extras change
1 parent 4ac0727 commit 6318e20

2 files changed

Lines changed: 57 additions & 76 deletions

File tree

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,6 @@ public Map<String, Object> getExtras() {
9090
return extras;
9191
}
9292

93-
/**
94-
* Initialize the extras map if not already
95-
*/
96-
public void initializeExtras() {
97-
if (extras == null) {
98-
extras = new LinkedHashMap<>();
99-
}
100-
}
101-
10293
/**
10394
* Determine if there are temporary extras that are not part of the CRS
10495
* definition
@@ -153,7 +144,9 @@ public void setExtras(Map<String, Object> extras) {
153144
* extra value
154145
*/
155146
public void addExtra(String name, Object extra) {
156-
initializeExtras();
147+
if (extras == null) {
148+
extras = new LinkedHashMap<>();
149+
}
157150
extras.put(name, extra);
158151
}
159152

@@ -164,7 +157,9 @@ public void addExtra(String name, Object extra) {
164157
* extra values
165158
*/
166159
public void addExtras(Map<String, Object> extras) {
167-
initializeExtras();
160+
if (this.extras == null) {
161+
this.extras = new LinkedHashMap<>();
162+
}
168163
this.extras.putAll(extras);
169164
}
170165

src/main/java/mil/nga/crs/wkt/CRSReader.java

Lines changed: 51 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,9 +1449,7 @@ public CoordinateReferenceSystem readGeo() throws IOException {
14491449

14501450
if (isDynamic || isKeywordNext(CRSKeyword.DATUM)) {
14511451
readSeparator();
1452-
crs.initializeExtras();
1453-
GeoReferenceFrame referenceFrame = readGeoReferenceFrame(
1454-
crs.getExtras());
1452+
GeoReferenceFrame referenceFrame = readGeoReferenceFrame(crs);
14551453
referenceFrame.setType(baseCrs.getType());
14561454
baseCrs.setReferenceFrame(referenceFrame);
14571455
} else if (isKeywordNext(CRSKeyword.ENSEMBLE)) {
@@ -1569,9 +1567,7 @@ public ProjectedCoordinateReferenceSystem readProjected(
15691567

15701568
if (isDynamic || isKeywordNext(CRSKeyword.DATUM)) {
15711569
readSeparator();
1572-
crs.initializeExtras();
1573-
GeoReferenceFrame referenceFrame = readGeoReferenceFrame(
1574-
crs.getExtras());
1570+
GeoReferenceFrame referenceFrame = readGeoReferenceFrame(crs);
15751571
referenceFrame.setType(crsType);
15761572
crs.setReferenceFrame(referenceFrame);
15771573
} else if (isKeywordNext(CRSKeyword.ENSEMBLE)) {
@@ -1649,9 +1645,7 @@ public CoordinateReferenceSystem readVertical() throws IOException {
16491645

16501646
if (isDynamic || isKeywordNext(CRSKeyword.VDATUM)) {
16511647
readSeparator();
1652-
crs.initializeExtras();
1653-
baseCrs.setReferenceFrame(
1654-
readVerticalReferenceFrame(crs.getExtras()));
1648+
baseCrs.setReferenceFrame(readVerticalReferenceFrame(crs));
16551649
} else if (isKeywordNext(CRSKeyword.ENSEMBLE)) {
16561650
readSeparator();
16571651
baseCrs.setDatumEnsemble(readVerticalDatumEnsemble());
@@ -1730,8 +1724,7 @@ public CoordinateReferenceSystem readEngineering() throws IOException {
17301724
crs.setName(name);
17311725

17321726
readSeparator();
1733-
crs.initializeExtras();
1734-
baseCrs.setDatum(readEngineeringDatum(crs.getExtras()));
1727+
baseCrs.setDatum(readEngineeringDatum(crs));
17351728

17361729
if (derivedCrs != null) {
17371730

@@ -1790,8 +1783,7 @@ public CoordinateReferenceSystem readParametric() throws IOException {
17901783
crs.setName(name);
17911784

17921785
readSeparator();
1793-
crs.initializeExtras();
1794-
baseCrs.setDatum(readParametricDatum(crs.getExtras()));
1786+
baseCrs.setDatum(readParametricDatum(crs));
17951787

17961788
if (derivedCrs != null) {
17971789

@@ -1920,9 +1912,7 @@ public DerivedCoordinateReferenceSystem readDerivedProjected()
19201912

19211913
if (isDynamic || isKeywordNext(CRSKeyword.DATUM)) {
19221914
readSeparator();
1923-
crs.initializeExtras();
1924-
GeoReferenceFrame referenceFrame = readGeoReferenceFrame(
1925-
crs.getExtras());
1915+
GeoReferenceFrame referenceFrame = readGeoReferenceFrame(crs);
19261916
referenceFrame.setType(projectedCrs.getBaseType());
19271917
projectedCrs.setReferenceFrame(referenceFrame);
19281918
} else if (isKeywordNext(CRSKeyword.ENSEMBLE)) {
@@ -2294,16 +2284,16 @@ public GeoReferenceFrame readGeoReferenceFrame() throws IOException {
22942284
/**
22952285
* Read a Geo reference frame
22962286
*
2297-
* @param extras
2298-
* used to store extra elements
2287+
* @param crs
2288+
* coordinate reference system
22992289
*
23002290
* @return geo reference frame
23012291
* @throws IOException
23022292
* upon failure to read
23032293
*/
2304-
public GeoReferenceFrame readGeoReferenceFrame(Map<String, Object> extras)
2305-
throws IOException {
2306-
ReferenceFrame referenceFrame = readReferenceFrame(extras);
2294+
public GeoReferenceFrame readGeoReferenceFrame(
2295+
SimpleCoordinateReferenceSystem crs) throws IOException {
2296+
ReferenceFrame referenceFrame = readReferenceFrame(crs);
23072297
if (!(referenceFrame instanceof GeoReferenceFrame)) {
23082298
throw new CRSException(
23092299
"Reference frame was not an expected Geo Reference Frame");
@@ -2326,16 +2316,16 @@ public VerticalReferenceFrame readVerticalReferenceFrame()
23262316
/**
23272317
* Read a Vertical reference frame
23282318
*
2329-
* @param extras
2330-
* used to store extra elements
2319+
* @param crs
2320+
* coordinate reference system
23312321
*
23322322
* @return vertical reference frame
23332323
* @throws IOException
23342324
* upon failure to read
23352325
*/
23362326
public VerticalReferenceFrame readVerticalReferenceFrame(
2337-
Map<String, Object> extras) throws IOException {
2338-
ReferenceFrame referenceFrame = readReferenceFrame(extras);
2327+
SimpleCoordinateReferenceSystem crs) throws IOException {
2328+
ReferenceFrame referenceFrame = readReferenceFrame(crs);
23392329
if (!(referenceFrame instanceof VerticalReferenceFrame)) {
23402330
throw new CRSException(
23412331
"Reference frame was not an expected Vertical Reference Frame");
@@ -2357,16 +2347,16 @@ public EngineeringDatum readEngineeringDatum() throws IOException {
23572347
/**
23582348
* Read an Engineering datum
23592349
*
2360-
* @param extras
2361-
* used to store extra elements
2350+
* @param crs
2351+
* coordinate reference system
23622352
*
23632353
* @return engineering datum
23642354
* @throws IOException
23652355
* upon failure to read
23662356
*/
2367-
public EngineeringDatum readEngineeringDatum(Map<String, Object> extras)
2368-
throws IOException {
2369-
ReferenceFrame referenceFrame = readReferenceFrame(extras);
2357+
public EngineeringDatum readEngineeringDatum(
2358+
SimpleCoordinateReferenceSystem crs) throws IOException {
2359+
ReferenceFrame referenceFrame = readReferenceFrame(crs);
23702360
if (!(referenceFrame instanceof EngineeringDatum)) {
23712361
throw new CRSException(
23722362
"Reference frame was not an expected Engineering Datum");
@@ -2388,16 +2378,16 @@ public ParametricDatum readParametricDatum() throws IOException {
23882378
/**
23892379
* Read a Parametric datum
23902380
*
2391-
* @param extras
2392-
* used to store extra elements
2381+
* @param crs
2382+
* coordinate reference system
23932383
*
23942384
* @return parametric datum
23952385
* @throws IOException
23962386
* upon failure to read
23972387
*/
2398-
public ParametricDatum readParametricDatum(Map<String, Object> extras)
2399-
throws IOException {
2400-
ReferenceFrame referenceFrame = readReferenceFrame(extras);
2388+
public ParametricDatum readParametricDatum(
2389+
SimpleCoordinateReferenceSystem crs) throws IOException {
2390+
ReferenceFrame referenceFrame = readReferenceFrame(crs);
24012391
if (!(referenceFrame instanceof ParametricDatum)) {
24022392
throw new CRSException(
24032393
"Reference frame was not an expected Parametric Datum");
@@ -2419,15 +2409,15 @@ public ReferenceFrame readReferenceFrame() throws IOException {
24192409
/**
24202410
* Read a Reference frame (datum)
24212411
*
2422-
* @param extras
2423-
* used to store extra elements
2412+
* @param crs
2413+
* coordinate reference system
24242414
*
24252415
* @return reference frame
24262416
* @throws IOException
24272417
* upon failure to read
24282418
*/
2429-
public ReferenceFrame readReferenceFrame(Map<String, Object> extras)
2430-
throws IOException {
2419+
public ReferenceFrame readReferenceFrame(
2420+
SimpleCoordinateReferenceSystem crs) throws IOException {
24312421

24322422
ReferenceFrame referenceFrame = null;
24332423
GeoReferenceFrame geoReferenceFrame = null;
@@ -2466,8 +2456,8 @@ public ReferenceFrame readReferenceFrame(Map<String, Object> extras)
24662456

24672457
if (keyword == CRSKeyword.TOWGS84) {
24682458
double[] toWGS84 = readToWGS84Compat();
2469-
if (extras != null) {
2470-
extras.put(CRSKeyword.TOWGS84.name(), toWGS84);
2459+
if (crs != null) {
2460+
crs.addExtra(CRSKeyword.TOWGS84.name(), toWGS84);
24712461
}
24722462
keyword = readToKeyword(CRSKeyword.ANCHOR, CRSKeyword.ID);
24732463
}
@@ -2485,8 +2475,8 @@ public ReferenceFrame readReferenceFrame(Map<String, Object> extras)
24852475

24862476
if (keyword == CRSKeyword.TOWGS84) {
24872477
double[] toWGS84 = readToWGS84Compat();
2488-
if (extras != null) {
2489-
extras.put(CRSKeyword.TOWGS84.name(), toWGS84);
2478+
if (crs != null) {
2479+
crs.addExtra(CRSKeyword.TOWGS84.name(), toWGS84);
24902480
}
24912481
}
24922482

@@ -3945,9 +3935,7 @@ public GeoCoordinateReferenceSystem readGeoCompat(CRSType expectedType)
39453935
crs.setName(reader.readExpectedToken());
39463936

39473937
readSeparator();
3948-
crs.initializeExtras();
3949-
GeoReferenceFrame referenceFrame = readGeoReferenceFrame(
3950-
crs.getExtras());
3938+
GeoReferenceFrame referenceFrame = readGeoReferenceFrame(crs);
39513939
referenceFrame.setType(crsType);
39523940
crs.setReferenceFrame(referenceFrame);
39533941

@@ -4174,8 +4162,7 @@ public VerticalCoordinateReferenceSystem readVerticalCompat()
41744162
crs.setName(reader.readExpectedToken());
41754163

41764164
readSeparator();
4177-
crs.initializeExtras();
4178-
crs.setReferenceFrame(readVerticalDatumCompat(crs.getExtras()));
4165+
crs.setReferenceFrame(readVerticalDatumCompat(crs));
41794166

41804167
crs.setCoordinateSystem(readCoordinateSystemCompat(CRSType.VERTICAL,
41814168
crs.getReferenceFrame()));
@@ -4215,8 +4202,7 @@ public EngineeringCoordinateReferenceSystem readEngineeringCompat()
42154202
crs.setName(reader.readExpectedToken());
42164203

42174204
readSeparator();
4218-
crs.initializeExtras();
4219-
crs.setDatum(readEngineeringDatumCompat(crs.getExtras()));
4205+
crs.setDatum(readEngineeringDatumCompat(crs));
42204206

42214207
crs.setCoordinateSystem(readCoordinateSystemCompat(CRSType.ENGINEERING,
42224208
crs.getDatum()));
@@ -4361,16 +4347,16 @@ public VerticalReferenceFrame readVerticalDatumCompat() throws IOException {
43614347
/**
43624348
* Read a Backward Compatible vertical datum
43634349
*
4364-
* @param extras
4365-
* used to store extra elements
4350+
* @param crs
4351+
* coordinate reference system
43664352
*
43674353
* @return vertical reference frame
43684354
* @throws IOException
43694355
* upon failure to read
43704356
*/
43714357
public VerticalReferenceFrame readVerticalDatumCompat(
4372-
Map<String, Object> extras) throws IOException {
4373-
ReferenceFrame referenceFrame = readDatumCompat(extras);
4358+
SimpleCoordinateReferenceSystem crs) throws IOException {
4359+
ReferenceFrame referenceFrame = readDatumCompat(crs);
43744360
if (!(referenceFrame instanceof VerticalReferenceFrame)) {
43754361
throw new CRSException(
43764362
"Datum was not an expected Vertical Reference Frame");
@@ -4392,16 +4378,16 @@ public EngineeringDatum readEngineeringDatumCompat() throws IOException {
43924378
/**
43934379
* Read a Backward Compatible engineering datum
43944380
*
4395-
* @param extras
4396-
* used to store extra elements
4381+
* @param crs
4382+
* coordinate reference system
43974383
*
43984384
* @return engineering datum
43994385
* @throws IOException
44004386
* upon failure to read
44014387
*/
44024388
public EngineeringDatum readEngineeringDatumCompat(
4403-
Map<String, Object> extras) throws IOException {
4404-
ReferenceFrame referenceFrame = readDatumCompat(extras);
4389+
SimpleCoordinateReferenceSystem crs) throws IOException {
4390+
ReferenceFrame referenceFrame = readDatumCompat(crs);
44054391
if (!(referenceFrame instanceof EngineeringDatum)) {
44064392
throw new CRSException(
44074393
"Datum was not an expected Engineering Datum");
@@ -4423,14 +4409,14 @@ public ReferenceFrame readDatumCompat() throws IOException {
44234409
/**
44244410
* Read a Backward Compatible datum
44254411
*
4426-
* @param extras
4427-
* used to store extra elements
4412+
* @param crs
4413+
* coordinate reference system
44284414
*
44294415
* @return reference frame
44304416
* @throws IOException
44314417
* upon failure to read
44324418
*/
4433-
public ReferenceFrame readDatumCompat(Map<String, Object> extras)
4419+
public ReferenceFrame readDatumCompat(SimpleCoordinateReferenceSystem crs)
44344420
throws IOException {
44354421

44364422
ReferenceFrame referenceFrame = null;
@@ -4453,8 +4439,8 @@ public ReferenceFrame readDatumCompat(Map<String, Object> extras)
44534439

44544440
readSeparator();
44554441
double datumType = reader.readNumber();
4456-
if (extras != null) {
4457-
extras.put(WKTConstants.DATUM_TYPE, Double.toString(datumType));
4442+
if (crs != null) {
4443+
crs.addExtra(WKTConstants.DATUM_TYPE, Double.toString(datumType));
44584444
}
44594445

44604446
CRSKeyword keyword = readToKeyword(CRSKeyword.ID, CRSKeyword.EXTENSION);
@@ -4466,8 +4452,8 @@ public ReferenceFrame readDatumCompat(Map<String, Object> extras)
44664452

44674453
if (keyword == CRSKeyword.EXTENSION) {
44684454
Map<String, Object> extensions = readExtensionsCompat();
4469-
if (extras != null) {
4470-
extras.putAll(extensions);
4455+
if (crs != null) {
4456+
crs.addExtras(extensions);
44714457
}
44724458
}
44734459

0 commit comments

Comments
 (0)