Skip to content

Commit 4120445

Browse files
authored
Merge pull request #178 from jenetics/issues/JPX-177-Convert_'geom'_classes_to_records
#177: Convert 'geom' classes to records.
2 parents aaf2335 + db19f84 commit 4120445

File tree

10 files changed

+129
-191
lines changed

10 files changed

+129
-191
lines changed

jpx/src/main/java/io/jenetics/jpx/format/CompositeFormat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626

2727
/**
2828
* @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
29-
* @version 2.2
29+
* @version !__version__!
3030
* @since 1.4
3131
*/
32-
class CompositeFormat implements Format {
32+
final class CompositeFormat implements Format {
3333

3434
private final List<Format> _formats;
3535

jpx/src/main/java/io/jenetics/jpx/format/Elevation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import java.util.Optional;
2222

2323
/**
24-
* This field allows to access the elevation (in meter) of a given location.
24+
* This field allows accessing the elevation (in meter) of a given location.
2525
*
26-
* @version 2.2
26+
* @version !__version__!
2727
* @since 2.2
2828
*/
2929
final class Elevation extends Field {

jpx/src/main/java/io/jenetics/jpx/format/Field.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,20 @@
3434
* elevation.
3535
*
3636
* @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
37-
* @version 3.0
37+
* @version !__version__!
3838
* @since 1.4
3939
*/
40-
abstract class Field implements Format {
40+
abstract sealed class Field
41+
implements Format
42+
permits
43+
Elevation,
44+
LatitudeDegree,
45+
LatitudeMinute,
46+
LatitudeSecond,
47+
LongitudeDegree,
48+
LongitudeMinute,
49+
LongitudeSecond
50+
{
4151

4252
private static final DecimalFormatSymbols SYMBOLS =
4353
DecimalFormatSymbols.getInstance(Locale.US);

jpx/src/main/java/io/jenetics/jpx/format/Format.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,19 @@
2626
* Base interface for formatting and parsing a location.
2727
*
2828
* @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
29-
* @version 2.2
29+
* @version !__version__!
3030
* @since 1.4
3131
*/
32-
interface Format {
32+
sealed interface Format
33+
permits
34+
CompositeFormat,
35+
ConstFormat,
36+
Field,
37+
LatitudeNS,
38+
LongitudeEW,
39+
OptionalFormat,
40+
Plus
41+
{
3342

3443
/**
3544
* Formats the given {@code value} to its string representation. If it is not

jpx/src/main/java/io/jenetics/jpx/format/LocationFormatter.java

Lines changed: 59 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -650,52 +650,67 @@ private void validate(){
650650
Elevation E = null;
651651

652652
for (var format : _formats) {
653-
if (format instanceof LatitudeDegree ld) {
654-
if (D == null) {
655-
D = ld;
656-
} else {
657-
throw iae("Only one 'D' pattern allowed.");
653+
switch (format) {
654+
case LatitudeDegree latd -> {
655+
if (D == null) {
656+
D = latd;
657+
} else {
658+
throw iae("Only one 'D' pattern allowed.");
659+
}
660+
}
661+
case LatitudeMinute latm -> {
662+
if (M == null) {
663+
M = latm;
664+
} else {
665+
throw iae("Only one 'M' pattern allowed.");
666+
}
658667
}
659-
} else if (format instanceof LatitudeMinute lm) {
660-
if (M == null) {
661-
M = lm;
662-
} else {
663-
throw iae("Only one 'M' pattern allowed.");
668+
case LatitudeSecond lats -> {
669+
if (S == null) {
670+
S = lats;
671+
} else {
672+
throw iae("Only one 'S' pattern allowed.");
673+
}
674+
}
675+
case LatitudeNS latns -> {
676+
if (X == null) {
677+
X = (LatitudeNS)format;
678+
}
664679
}
665-
} else if (format instanceof LatitudeSecond ls) {
666-
if (S == null) {
667-
S = ls;
668-
} else {
669-
throw iae("Only one 'S' pattern allowed.");
680+
case LongitudeDegree lond -> {
681+
if (d == null) {
682+
d = lond;
683+
} else {
684+
throw iae("Only one 'd' pattern allowed.");
685+
}
670686
}
671-
} else if (format instanceof LatitudeNS && X==null) {
672-
X = (LatitudeNS)format;
673-
} else if (format instanceof LongitudeDegree ld) {
674-
if (d == null) {
675-
d = ld;
676-
} else {
677-
throw iae("Only one 'd' pattern allowed.");
687+
case LongitudeMinute lonm -> {
688+
if (m == null) {
689+
m = lonm;
690+
} else {
691+
throw iae("Only one 'm' pattern allowed.");
692+
}
678693
}
679-
} else if (format instanceof LongitudeMinute lm) {
680-
if (m == null) {
681-
m = lm;
682-
} else {
683-
throw iae("Only one 'm' pattern allowed.");
694+
case LongitudeSecond lons -> {
695+
if (s == null) {
696+
s = lons;
697+
} else {
698+
throw iae("Only one 's' pattern allowed.");
699+
}
684700
}
685-
} else if (format instanceof LongitudeSecond ls) {
686-
if (s == null) {
687-
s = ls;
688-
} else {
689-
throw iae("Only one 's' pattern allowed.");
701+
case LongitudeEW lonew -> {
702+
if (x == null) {
703+
x = lonew;
704+
}
690705
}
691-
} else if (format instanceof LongitudeEW lew && x == null) {
692-
x = lew;
693-
} else if (format instanceof Elevation ele) {
694-
if (E == null) {
695-
E = ele;
696-
} else {
697-
throw iae("Only one 'E' pattern allowed.");
706+
case Elevation ele -> {
707+
if (E == null) {
708+
E = ele;
709+
} else {
710+
throw iae("Only one 'E' pattern allowed.");
711+
}
698712
}
713+
default -> { }
699714
}
700715
}
701716

@@ -915,7 +930,7 @@ static List<String> tokenize(final String pattern) {
915930
switch (c) {
916931
case '\'':
917932
quote = !quote;
918-
if (token.length() > 0) {
933+
if (!token.isEmpty()) {
919934
tokens.add(token.toString());
920935
token.setLength(0);
921936
}
@@ -925,7 +940,7 @@ static List<String> tokenize(final String pattern) {
925940
if (quote) {
926941
token.append(c);
927942
} else {
928-
if (token.length() > 0) {
943+
if (!token.isEmpty()) {
929944
tokens.add(token.toString());
930945
token.setLength(0);
931946
}
@@ -939,7 +954,7 @@ static List<String> tokenize(final String pattern) {
939954
pc != ',' &&
940955
!quote)
941956
{
942-
if (token.length() > 0) {
957+
if (!token.isEmpty()) {
943958
tokens.add(token.toString());
944959
token.setLength(0);
945960
}
@@ -951,7 +966,7 @@ static List<String> tokenize(final String pattern) {
951966
break;
952967
default:
953968
if (PROTECTED_CHARS.contains(pc) || pc == '\'') {
954-
if (token.length() > 0) {
969+
if (!token.isEmpty()) {
955970
tokens.add(token.toString());
956971
token.setLength(0);
957972
}
@@ -963,7 +978,7 @@ static List<String> tokenize(final String pattern) {
963978
pc = c;
964979
}
965980

966-
if (token.length() > 0) {
981+
if (!token.isEmpty()) {
967982
tokens.add(token.toString());
968983
}
969984

jpx/src/main/java/io/jenetics/jpx/format/LongitudeDegree.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
import io.jenetics.jpx.Longitude;
2424

2525
/**
26-
* This field allows to access the longitude degrees of a given location. If the
26+
* This field allows accessing the longitude degrees of a given location. If the
2727
* pattern has a fractional part, the longitude is rounded to match the pattern.
2828
* If the pattern has no fractional part, the longitude is truncated rather than
2929
* rounded, on the assumption that the fractional part will be represented by
3030
* minutes and seconds.
3131
*
32-
* @version 2.2
32+
* @version !__version__!
3333
* @since 2.2
3434
*/
35-
class LongitudeDegree extends Field {
35+
final class LongitudeDegree extends Field {
3636

3737
LongitudeDegree(final String pattern) {
3838
super(pattern, 'd');

jpx/src/main/java/io/jenetics/jpx/format/OptionalFormat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727

2828
/**
2929
* @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
30-
* @version 2.2
30+
* @version !__version__!
3131
* @since 1.4
3232
*/
33-
class OptionalFormat implements Format {
33+
final class OptionalFormat implements Format {
3434

3535
private final Format _format;
3636

0 commit comments

Comments
 (0)