Skip to content

Commit ed43602

Browse files
authored
Merge pull request #4 from jenetics/r1.0.0
Release 1.0.0
2 parents 5268ee2 + c927261 commit ed43602

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1472
-92
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# JPX - Java GPX library
22

3-
This is a Java library for creating, reading and writing GPS data in [GPX](http://www.topografix.com/GPX) format. It implements version [1.1](http://www.topografix.com/GPX/1/1/) of the GPX format. Javadoc of the library can be [here](https://jenetics.github.io/jpx/javadoc/jpx/index.html).
3+
**JPX** is a Java library for creating, reading and writing [GPS](https://en.wikipedia.org/wiki/Global_Positioning_System) data in [GPX](https://en.wikipedia.org/wiki/GPS_Exchange_Format) format. It is a *full* implementation of version [1.1](http://www.topografix.com/GPX/1/1/) of the GPX format. The data classes are completely immutable and allows a functional programming style. They are working also nicely with the Java 8 [Stream](http://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html) API.
4+
5+
The comprehensive Javadoc of the library can be [here](https://jenetics.github.io/jpx/javadoc/jpx/index.html).
46

57
## Requirements
68

@@ -29,7 +31,7 @@ For building the JPX library you have to check out the master branch from Github
2931

3032
$ ./gradle jar
3133

32-
## Download (soon available)
34+
## Download
3335

3436
* **Github**: <https://github.com/jenetics/jpx/archive/v1.0.0.zip>
3537
* **Maven**: `io.jenetics:jpx:1.0.0` on <a href="http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22jpx%22">Maven Central</a>
@@ -51,15 +53,14 @@ final GPX gpx = GPX.builder()
5153
**Writing GPX object to a file**
5254

5355
```java
54-
// Writing "pretty" GPX file.
55-
GPX.write(gpx, " ", "gpx.xml");
56+
GPX.write(gpx, "gpx.xml");
5657
```
5758

5859
*GPX output*
5960

6061
```xml
6162
<?xml version="1.0" encoding="UTF-8"?>
62-
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="JPX - Java GPX library">
63+
<gpx version="1.1" creator="JPX - Java GPX library" xmlns="http://www.topografix.com/GPX/1/1">
6364
<trk>
6465
<trkseg>
6566
<trkpt lat="48.2081743" lon="16.3738189">
@@ -106,7 +107,7 @@ $ [lat=48.2081743, lon=48.2081743, ele=162]
106107
```java
107108
final Point start = WayPoint.of(47.2692124, 11.4041024);
108109
final Point end = WayPoint.of(47.3502, 11.70584);
109-
final Length distance = Geoid.WGSC_84.distance(start, end);
110+
final Length distance = Geoid.WGSC84.distance(start, end);
110111
System.out.println(distance);
111112
```
112113

@@ -125,7 +126,7 @@ final Length length = gpx.tracks()
125126
.flatMap(Track::segments)
126127
.findFirst()
127128
.map(TrackSegment::points).orElse(Stream.empty())
128-
.collect(Geoid.WGSC_84.toPathLength());
129+
.collect(Geoid.WGSC84.toPathLength());
129130
```
130131

131132

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ ext {
3939

4040
allprojects {
4141
group = 'io.jenetics'
42-
version = '1.0.0-SNAPSHOT'
42+
version = '1.0.0'
4343

4444
repositories {
4545
flatDir(dir: "${rootDir}/buildSrc/lib")

jpx/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ repositories {
3737
}
3838

3939
dependencies {
40-
testCompile 'org.testng:testng:6.9.10'
40+
testCompile 'org.testng:testng:6.10'
4141
}
4242

4343
javadoc {
@@ -62,7 +62,7 @@ javadoc {
6262
doLast {
6363
project.copy {
6464
from('src/main/java') {
65-
include 'org/**/doc-files/*.*'
65+
include 'io/**/doc-files/*.*'
6666
}
6767
includeEmptyDirs = false
6868
into destinationDir.path

jpx/src/main/java/io/jenetics/jpx/DGPSStation.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@
3333
* @version 1.0
3434
* @since 1.0
3535
*/
36-
public final class DGPSStation extends Number implements Serializable {
36+
public final class DGPSStation
37+
extends Number
38+
implements
39+
Comparable<DGPSStation>,
40+
Serializable
41+
{
3742

3843
private static final long serialVersionUID = 1L;
3944

@@ -80,6 +85,11 @@ public float floatValue() {
8085
return (float)_value;
8186
}
8287

88+
@Override
89+
public int compareTo(final DGPSStation other) {
90+
return Integer.compare(_value, other._value);
91+
}
92+
8393
@Override
8494
public int hashCode() {
8595
return Integer.hashCode(_value);

jpx/src/main/java/io/jenetics/jpx/Degrees.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@
3333
* @version 1.0
3434
* @since 1.0
3535
*/
36-
public final class Degrees extends Number implements Serializable {
36+
public final class Degrees
37+
extends Number
38+
implements
39+
Comparable<Degrees>,
40+
Serializable
41+
{
3742

3843
private static final long serialVersionUID = 1L;
3944

@@ -100,6 +105,11 @@ public float floatValue() {
100105
return (float)doubleValue();
101106
}
102107

108+
@Override
109+
public int compareTo(final Degrees other) {
110+
return Double.compare(_value, other._value);
111+
}
112+
103113
@Override
104114
public int hashCode() {
105115
return Double.hashCode(_value);

jpx/src/main/java/io/jenetics/jpx/Email.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @version 1.0
3838
* @since 1.0
3939
*/
40-
public final class Email implements Serializable {
40+
public final class Email implements Comparable<Email>, Serializable {
4141

4242
private static final long serialVersionUID = 1L;
4343

@@ -75,6 +75,25 @@ public String getDomain() {
7575
return _domain;
7676
}
7777

78+
/**
79+
* Return the full EMail address: id + "@" + domain.
80+
*
81+
* @return the full EMail address: id + "@" + domain
82+
*/
83+
public String getAddress() {
84+
return _id + "@" + _domain;
85+
}
86+
87+
@Override
88+
public int compareTo(final Email other) {
89+
int cmp = _domain.compareTo(other._domain);
90+
if (cmp == 0) {
91+
cmp = _id.compareTo(other._id);
92+
}
93+
94+
return cmp;
95+
}
96+
7897
@Override
7998
public int hashCode() {
8099
int hash = 37;
@@ -92,7 +111,7 @@ public boolean equals(final Object obj) {
92111

93112
@Override
94113
public String toString() {
95-
return _id + "@" + _domain;
114+
return getAddress();
96115
}
97116

98117

jpx/src/main/java/io/jenetics/jpx/Length.java

Lines changed: 86 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package io.jenetics.jpx;
2121

2222
import static java.lang.String.format;
23+
import static java.util.Objects.requireNonNull;
2324

2425
import java.io.Serializable;
2526

@@ -32,10 +33,71 @@
3233
* @version 1.0
3334
* @since 1.0
3435
*/
35-
public final class Length extends Number implements Serializable {
36+
public final class Length
37+
extends Number
38+
implements
39+
Comparable<Length>,
40+
Serializable
41+
{
3642

3743
private static final long serialVersionUID = 1L;
3844

45+
/**
46+
* Represents a given length unit.
47+
*/
48+
public static enum Unit {
49+
50+
/**
51+
* Represents a meter.
52+
*/
53+
METER(1.0),
54+
55+
/**
56+
* Represents a kilometer.
57+
*/
58+
KILOMETER(1_000.0),
59+
60+
/**
61+
* Represents an inch.
62+
*/
63+
INCH(127.0/5_000.0),
64+
65+
/**
66+
* Represents a yard.
67+
*/
68+
YARD(1_143.0/1_250.0),
69+
70+
/**
71+
* Represents a mile.
72+
*/
73+
MILE(201_168.0/125.0);
74+
75+
private final double _factor;
76+
77+
private Unit(final double factor) {
78+
_factor = factor;
79+
}
80+
81+
/**
82+
* Convert the given length value of the given {@code sourceUnit} into a
83+
* length value of {@code this} length unit. The given example converts 3
84+
* inches into yards.
85+
*
86+
* <pre>{@code
87+
* final double yards = YARD.convert(3, INCH);
88+
* }</pre>
89+
*
90+
* @param length the length value
91+
* @param sourceUnit the source length unit
92+
* @return the speed value of {@code this} length unit
93+
*/
94+
public double convert(final double length, final Unit sourceUnit) {
95+
requireNonNull(sourceUnit);
96+
final double meters = length*sourceUnit._factor;
97+
return meters/_factor;
98+
}
99+
}
100+
39101
private final double _value;
40102

41103
/**
@@ -58,21 +120,15 @@ public double doubleValue() {
58120
}
59121

60122
/**
61-
* Return the length in meter.
123+
* Return the length in the desired unit.
62124
*
63-
* @return the length in meter
125+
* @param unit the desired length unit
126+
* @return the length in the desired unit
127+
* @throws NullPointerException if the given length {@code unit} is
128+
* {@code null}
64129
*/
65-
public double toMeters() {
66-
return _value;
67-
}
68-
69-
/**
70-
* Return the length in kilometers.
71-
*
72-
* @return the length in kilometers
73-
*/
74-
public double toKilometer() {
75-
return _value/1000.0;
130+
public double to(final Unit unit) {
131+
return unit.convert(_value, Unit.METER);
76132
}
77133

78134
@Override
@@ -90,6 +146,11 @@ public float floatValue() {
90146
return (float)doubleValue();
91147
}
92148

149+
@Override
150+
public int compareTo(final Length other) {
151+
return Double.compare(_value, other._value);
152+
}
153+
93154
@Override
94155
public int hashCode() {
95156
return Double.hashCode(_value);
@@ -112,23 +173,17 @@ public String toString() {
112173
* ************************************************************************/
113174

114175
/**
115-
* Create a new {@code Length} object with the given value in meters.
116-
*
117-
* @param meters the length in meters
118-
* @return a new {@code Length} object with the given value in meters.
119-
*/
120-
public static Length ofMeters(final double meters) {
121-
return new Length(meters);
122-
}
123-
124-
/**
125-
* Create a new {@code Length} object with the given value in km.
176+
* Create a new {@code Length} object with the given length.
126177
*
127-
* @param km the length in kilometers
128-
* @return a new {@code Length} object with the given value in kilometers.
178+
* @param length the length
179+
* @param unit the length unit
180+
* @return a new {@code Length} object with the given length.
181+
* @throws NullPointerException if the given length {@code unit} is
182+
* {@code null}
129183
*/
130-
public static Length ofKilometers(final double km) {
131-
return new Length(km*1000);
184+
public static Length of(final double length, final Unit unit) {
185+
requireNonNull(unit);
186+
return new Length(Unit.METER.convert(length, unit));
132187
}
133188

134189
/**
@@ -141,9 +196,9 @@ static Length parse(final Object object) {
141196
return object instanceof Length
142197
? (Length)object
143198
: object instanceof Number
144-
? ofMeters(((Number) object).doubleValue())
199+
? of(((Number)object).doubleValue(), Unit.METER)
145200
: object != null
146-
? ofMeters(Double.parseDouble(object.toString()))
201+
? of(Double.parseDouble(object.toString()), Unit.METER)
147202
: null;
148203
}
149204

jpx/src/main/java/io/jenetics/jpx/Metadata.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,21 @@ public Optional<Bounds> getBounds() {
178178
return Optional.ofNullable(_bounds);
179179
}
180180

181+
/**
182+
* Return {@code true} if all metadata properties are {@code null} or empty.
183+
*
184+
* @return {@code true} if all metadata properties are {@code null} or empty
185+
*/
186+
public boolean isEmpty() {
187+
return _name == null &&
188+
_description == null &&
189+
_author == null &&
190+
_copyright == null &&
191+
_links.isEmpty() &&
192+
_time == null &&
193+
_keywords == null &&
194+
_bounds == null;
195+
}
181196

182197
@Override
183198
public int hashCode() {

jpx/src/main/java/io/jenetics/jpx/Person.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ public Optional<Link> getLink() {
8282
return Optional.ofNullable(_link);
8383
}
8484

85+
/**
86+
* Return {@code true} if all person properties are {@code null}.
87+
*
88+
* @return {@code true} if all person properties are {@code null}
89+
*/
90+
public boolean isEmpty() {
91+
return _name == null &&
92+
_email == null &&
93+
_link == null;
94+
}
95+
8596
@Override
8697
public int hashCode() {
8798
int hash = 37;

jpx/src/main/java/io/jenetics/jpx/Point.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ public default Optional<ZonedDateTime> getTime() {
6666
}
6767

6868
/**
69-
* Calculate the distance between points on an ellipsoidal earth model.
69+
* Calculate the distance between points on the default ellipsoidal earth
70+
* model
71+
* <a href="https://en.wikipedia.org/wiki/World_Geodetic_System#A_new_World_Geodetic_System:_WGS_84">
72+
* WGS-84</a>.
7073
*
7174
* @see <a href="http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf">DIRECT AND
7275
* INVERSE SOLUTIONS OF GEODESICS 0 THE ELLIPSOID

0 commit comments

Comments
 (0)