├── .editorconfig ├── .github └── workflows │ └── gradle.yml ├── .gitignore ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── RELEASE_NOTES.md ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── lib │ └── java2html.jar ├── resources │ └── javadoc │ │ ├── java.se │ │ └── element-list │ │ └── stylesheet.css └── src │ └── main │ ├── java │ └── io │ │ └── jenetics │ │ └── gradle │ │ ├── Colorizer.java │ │ ├── ColorizerTask.java │ │ └── package-info.java │ └── kotlin │ ├── Env.kt │ └── io │ └── jenetics │ └── gradle │ └── dsl │ └── Extensions.kt ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jpx ├── build.gradle.kts └── src │ ├── main │ └── java │ │ ├── io │ │ └── jenetics │ │ │ └── jpx │ │ │ ├── Bounds.java │ │ │ ├── Copyright.java │ │ │ ├── DGPSStation.java │ │ │ ├── Degrees.java │ │ │ ├── Email.java │ │ │ ├── Filter.java │ │ │ ├── Filters.java │ │ │ ├── Fix.java │ │ │ ├── Format.java │ │ │ ├── GPX.java │ │ │ ├── IO.java │ │ │ ├── IndentingXMLStreamWriter.java │ │ │ ├── Instants.java │ │ │ ├── Latitude.java │ │ │ ├── Length.java │ │ │ ├── Link.java │ │ │ ├── Lists.java │ │ │ ├── Longitude.java │ │ │ ├── Metadata.java │ │ │ ├── NonCloseableInputStream.java │ │ │ ├── NonCloseableOutputStream.java │ │ │ ├── NonNullList.java │ │ │ ├── Person.java │ │ │ ├── Point.java │ │ │ ├── Route.java │ │ │ ├── SerialProxy.java │ │ │ ├── Speed.java │ │ │ ├── Strings.java │ │ │ ├── TimeFormat.java │ │ │ ├── Track.java │ │ │ ├── TrackSegment.java │ │ │ ├── UInt.java │ │ │ ├── WayPoint.java │ │ │ ├── XML.java │ │ │ ├── XMLProvider.java │ │ │ ├── XMLReader.java │ │ │ ├── XMLReaders.java │ │ │ ├── XMLStreamReaderAdapter.java │ │ │ ├── XMLStreamWriterAdapter.java │ │ │ ├── XMLWriter.java │ │ │ ├── XMLWriters.java │ │ │ ├── format │ │ │ ├── CompositeFormat.java │ │ │ ├── ConstFormat.java │ │ │ ├── Elevation.java │ │ │ ├── Field.java │ │ │ ├── Format.java │ │ │ ├── FormatterException.java │ │ │ ├── LatitudeDegree.java │ │ │ ├── LatitudeMinute.java │ │ │ ├── LatitudeNS.java │ │ │ ├── LatitudeSecond.java │ │ │ ├── Location.java │ │ │ ├── LocationBuilder.java │ │ │ ├── LocationFormatter.java │ │ │ ├── LongitudeDegree.java │ │ │ ├── LongitudeEW.java │ │ │ ├── LongitudeMinute.java │ │ │ ├── LongitudeSecond.java │ │ │ ├── OptionalFormat.java │ │ │ ├── ParseException.java │ │ │ ├── Plus.java │ │ │ └── package-info.java │ │ │ ├── geom │ │ │ ├── DoubleAdder.java │ │ │ ├── Ellipsoid.java │ │ │ ├── Geoid.java │ │ │ ├── LengthCollector.java │ │ │ ├── MathUtils.java │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ └── module-info.java │ └── test │ ├── java │ └── io │ │ └── jenetics │ │ └── jpx │ │ ├── BoundsTest.java │ │ ├── CopyrightTest.java │ │ ├── DGPSStationTest.java │ │ ├── DegreesTest.java │ │ ├── EmailTest.java │ │ ├── FiltersTest.java │ │ ├── FixTest.java │ │ ├── Formats.java │ │ ├── GPXTest.java │ │ ├── IOTest.java │ │ ├── LatitudeTest.java │ │ ├── LengthTest.java │ │ ├── LinkTest.java │ │ ├── ListsTest.java │ │ ├── LongitudeTest.java │ │ ├── MetadataTest.java │ │ ├── ObjectTester.java │ │ ├── PersonTest.java │ │ ├── Randoms.java │ │ ├── RouteTest.java │ │ ├── Serialization.java │ │ ├── SpeedTest.java │ │ ├── TimeFormatTest.java │ │ ├── TrackSegmentTest.java │ │ ├── TrackTest.java │ │ ├── UIntTest.java │ │ ├── WayPointTest.java │ │ ├── XMLProviderTest.java │ │ ├── XMLStreamTestBase.java │ │ ├── XMLTest.java │ │ ├── ZonedDateTimesTest.java │ │ ├── format │ │ ├── Fixture.java │ │ ├── FormatTest.java │ │ ├── LocationFormatterTest.java │ │ ├── LocationRandom.java │ │ ├── ParseTest.java │ │ ├── PatternTest.java │ │ └── TokenTest.java │ │ └── geom │ │ ├── GeoidTest.java │ │ └── MathUtilsTest.java │ └── resources │ └── io │ └── jenetics │ └── jpx │ ├── Austria.gpx │ ├── GPX-full.gpx │ ├── GPX_10-1.gpx │ ├── GPX_10-2.gpx │ ├── GPX_10-3.gpx │ ├── GPX_10-4.gpx │ ├── GPX_10-5.gpx │ ├── GPX_10-6.gpx │ ├── GPX_empty_extensions.gpx │ ├── GPX_extensions.gpx │ ├── GPX_invalid_extensions.gpx │ ├── Gpx-full-sample.gpx │ ├── ISSUE-151.gpx │ ├── ISSUE-170.gpx │ ├── ISSUE-186.gpx │ ├── ISSUE-38.gpx.xml │ ├── ISSUE-49.gpx │ ├── ISSUE-51.gpx │ ├── ISSUE-77.gpx │ ├── ISSUE-78.gpx │ ├── ISSUE-82.gpx │ ├── ISSUE-86.gpx │ ├── empty-ele.xml │ ├── empty-gpx.xml │ ├── empty-metadata.xml │ ├── empty-route.xml │ ├── empty-track-segment.xml │ ├── empty-track.xml │ ├── empty-waypoint.xml │ ├── extensions-gpx.gpx │ ├── extensions-metadata.gpx │ ├── extensions-route.gpx │ ├── extensions-track.gpx │ ├── extensions-tracksegment.gpx │ ├── extensions-waypoint.gpx │ ├── extensions.gpx │ ├── invalid-latlon.xml │ ├── io.jenetics.jpx.XMLProvider │ └── serialization │ ├── gpx_0.obj │ ├── gpx_0.xml │ ├── gpx_1.obj │ ├── gpx_1.xml │ ├── gpx_10.obj │ ├── gpx_10.xml │ ├── gpx_11.obj │ ├── gpx_11.xml │ ├── gpx_12.obj │ ├── gpx_12.xml │ ├── gpx_13.obj │ ├── gpx_13.xml │ ├── gpx_14.obj │ ├── gpx_14.xml │ ├── gpx_2.obj │ ├── gpx_2.xml │ ├── gpx_3.obj │ ├── gpx_3.xml │ ├── gpx_4.obj │ ├── gpx_4.xml │ ├── gpx_5.obj │ ├── gpx_5.xml │ ├── gpx_6.obj │ ├── gpx_6.xml │ ├── gpx_7.obj │ ├── gpx_7.xml │ ├── gpx_8.obj │ ├── gpx_8.xml │ ├── gpx_9.obj │ └── gpx_9.xml └── settings.gradle.kts /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = tab 6 | indent_size = 4 7 | tab_width = 4 8 | 9 | [*.{java,gradle,groovy,kt,kts}] 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | name: JPX Build 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - releases/* 8 | - issues/* 9 | pull_request: 10 | branches: 11 | - master 12 | - releases/* 13 | 14 | jobs: 15 | build: 16 | runs-on: ${{ matrix.os }} 17 | strategy: 18 | matrix: 19 | os: [ ubuntu-latest, macos-latest ] 20 | java-version: [ 17, 21, 23 ] 21 | steps: 22 | - uses: actions/checkout@v2 23 | 24 | - name: Set up JDK ${{ matrix.java-version }} on ${{ matrix.os }} 25 | uses: actions/setup-java@v2 26 | with: 27 | java-version: ${{ matrix.java-version }} 28 | distribution: 'zulu' 29 | - name: Build with Gradle 30 | run: ./gradlew build --stacktrace --info -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Java template 3 | *.class 4 | 5 | # BlueJ files 6 | *.ctxt 7 | 8 | # Mobile Tools for Java (J2ME) 9 | .mtj.tmp/ 10 | out/ 11 | 12 | # Package Files # 13 | *.jar 14 | *.war 15 | *.ear 16 | 17 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 18 | hs_err_pid* 19 | ### Gradle template 20 | .gradle 21 | /build/ 22 | 23 | # Ignore Gradle GUI config 24 | gradle-app.setting 25 | 26 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 27 | !gradle-wrapper.jar 28 | 29 | # Cache of project 30 | .gradletasknamecache 31 | 32 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 33 | # gradle/wrapper/gradle-wrapper.properties 34 | 35 | .idea 36 | build 37 | classes 38 | 39 | */srv/var/dbdata 40 | */srv/var/lib-pgadmin 41 | 42 | # NetBeans.gitignore https://github.com/github/gitignore/blob/master/Global/NetBeans.gitignore 43 | **/nbproject/private/ 44 | **/nbproject/Makefile-*.mk 45 | **/nbproject/Package-*.bash 46 | jpx/build/ 47 | jpx/bin/ 48 | jpx/nbbuild/ 49 | jpx/dist/ 50 | jpx/nbdist/ 51 | .nb-gradle/ 52 | .project 53 | .settings/ 54 | .classpath 55 | *.iml -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | JPX: Java GPX Algorithm Library 2 | Copyright (c) 20016-2016 Franz Wilhelmstötter 3 | 4 | =============================================================================== 5 | TestNG (http://testng.org). 6 | 7 | =============================================================================== 8 | 9 | -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget 2 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 3 | 4 | /* 5 | * Java GPX Library (@__identifier__@). 6 | * Copyright (c) @__year__@ Franz Wilhelmstötter 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * Author: 21 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 22 | */ 23 | 24 | /** 25 | * @author Franz Wilhelmstötter 26 | * @since 2.1 27 | * @version 3.2 28 | */ 29 | plugins { 30 | `java-gradle-plugin` 31 | `kotlin-dsl` 32 | } 33 | 34 | repositories { 35 | mavenLocal() 36 | gradlePluginPortal() 37 | } 38 | 39 | tasks.withType { 40 | compilerOptions { 41 | jvmTarget.set(JvmTarget.JVM_17) 42 | } 43 | } 44 | 45 | configure { 46 | sourceCompatibility = JavaVersion.VERSION_17 47 | targetCompatibility = JavaVersion.VERSION_17 48 | } 49 | -------------------------------------------------------------------------------- /buildSrc/lib/java2html.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/buildSrc/lib/java2html.jar -------------------------------------------------------------------------------- /buildSrc/src/main/java/io/jenetics/gradle/ColorizerTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.gradle; 21 | 22 | import java.io.File; 23 | import java.io.IOException; 24 | 25 | import org.gradle.api.DefaultTask; 26 | import org.gradle.api.tasks.InputFile; 27 | import org.gradle.api.tasks.TaskAction; 28 | import org.gradle.api.tasks.TaskExecutionException; 29 | 30 | /** 31 | * @author Franz Wilhelmstötter 32 | * @since 1.4 33 | * @version 6.1 34 | */ 35 | public class ColorizerTask extends DefaultTask { 36 | 37 | private File _directory; 38 | 39 | @InputFile 40 | public File getDirectory() { 41 | return _directory; 42 | } 43 | 44 | public void setDirectory(final File directory) { 45 | _directory = directory; 46 | } 47 | 48 | @TaskAction 49 | public void colorize() { 50 | try { 51 | final Colorizer colorizer = new Colorizer(_directory); 52 | colorizer.colorize(); 53 | 54 | getLogger().lifecycle( 55 | "Colorizer processed {} files and modified {}.", 56 | colorizer.getProcessed(), colorizer.getModified() 57 | ); 58 | } catch (final IOException e) { 59 | throw new TaskExecutionException(this, e); 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /buildSrc/src/main/java/io/jenetics/gradle/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | 21 | /** 22 | * @author Franz Wilhelmstötter 23 | * @since 1.4 24 | * @version 1.4 25 | */ 26 | package io.jenetics.gradle; 27 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/Env.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | 21 | import java.time.Year 22 | import java.time.ZonedDateTime 23 | import java.time.format.DateTimeFormatter 24 | 25 | /** 26 | * Common environment values. 27 | */ 28 | object Env { 29 | private val NOW: ZonedDateTime = ZonedDateTime.now() 30 | 31 | private val YEAR: Year = Year.now(); 32 | 33 | val COPYRIGHT_YEAR = "2016-${YEAR}" 34 | 35 | private val DATE_FORMAT: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm") 36 | 37 | val BUILD_DATE: String = DATE_FORMAT.format(NOW) 38 | 39 | val BUILD_JDK: String = System.getProperty("java.version") 40 | 41 | val BUILD_OS_NAME: String = System.getProperty("os.name") 42 | 43 | val BUILD_OS_ARCH: String = System.getProperty("os.arch") 44 | 45 | val BUILD_OS_VERSION: String = System.getProperty("os.version") 46 | 47 | val BUILD_BY: String = System.getProperty("user.name") 48 | 49 | } 50 | 51 | /** 52 | * Information about the library and author. 53 | */ 54 | object JPX { 55 | const val VERSION = "3.2.1" 56 | const val ID = "jpx" 57 | const val NAME = "jpx" 58 | const val GROUP = "io.jenetics" 59 | const val AUTHOR = "Franz Wilhelmstötter" 60 | const val EMAIL = "franz.wilhelmstoetter@gmail.com" 61 | const val URL = "https://github.com/jenetics/jpx" 62 | } 63 | 64 | /** 65 | * Environment variables for publishing to Maven Central. 66 | */ 67 | object Maven { 68 | const val SNAPSHOT_URL = "https://oss.sonatype.org/content/repositories/snapshots/" 69 | const val RELEASE_URL = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 70 | 71 | const val SCM_URL = "https://github.com/jenetics/jpx" 72 | const val SCM_CONNECTION = "scm:git:https://github.com/jenetics/jpx.git" 73 | const val DEVELOPER_CONNECTION = "scm:git:https://github.com/jenetics/jpx.git" 74 | } 75 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/io/jenetics/gradle/dsl/Extensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | 21 | /** 22 | * @author Franz Wilhelmstötter 23 | * @since 3.2 24 | * @version 3.2 25 | */ 26 | package io.jenetics.gradle.dsl 27 | 28 | import org.gradle.api.Project 29 | import org.gradle.kotlin.dsl.extra 30 | 31 | /** 32 | * Gets the module name of the project, as configured in the build file. 33 | */ 34 | var Project.moduleName: String 35 | get() = if (this.isModule) this.extra.get("moduleName").toString() 36 | else this.name 37 | set(value) = this.extra.set("moduleName", value) 38 | 39 | /** 40 | * Checks if the project is configured as a module. 41 | */ 42 | val Project.isModule: Boolean 43 | get() = this.extra.has("moduleName") 44 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-all.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /jpx/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import io.jenetics.gradle.dsl.moduleName 2 | 3 | /* 4 | * Java GPX Library (@__identifier__@). 5 | * Copyright (c) @__year__@ Franz Wilhelmstötter 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Author: 20 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 21 | */ 22 | 23 | /** 24 | * @author Franz Wilhelmstötter 25 | * @since 1.0 26 | * @version 2.1 27 | */ 28 | plugins { 29 | `java-library` 30 | idea 31 | `maven-publish` 32 | } 33 | 34 | description = "JPX - Java GPX (GPS) Library" 35 | 36 | moduleName = "io.jenetics.jpx" 37 | 38 | dependencies { 39 | testImplementation(libs.assertj) 40 | testImplementation(libs.equalsverifier) 41 | testImplementation(libs.prngine) 42 | testImplementation(libs.testng) 43 | } 44 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/Filter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import java.util.List; 23 | import java.util.function.Function; 24 | import java.util.function.Predicate; 25 | 26 | /** 27 | * Filter interface which contains the {@code filter}, {@code map}, 28 | * {@code flatMap} and {@code listMap} methods for transforming values from 29 | * type {@code T}. 30 | * 31 | * @param the value type for the transformed objects 32 | * @param the result type of the filtered object 33 | * 34 | * @author Franz Wilhelmstötter 35 | * @version 1.1 36 | * @since 1.1 37 | */ 38 | public interface Filter { 39 | 40 | /** 41 | * Return a filter consisting of the elements of this filter that matches 42 | * the given predicate. 43 | * 44 | * @param predicate a non-interfering, stateless predicate to apply to each 45 | * element to determine if it should be included 46 | * @return a new filter 47 | */ 48 | Filter filter(final Predicate predicate); 49 | 50 | /** 51 | * Return a filter with the results of applying the given mapper function. 52 | * 53 | * @param mapper a non-interfering, stateless function to apply to each 54 | * element 55 | * @return a new filter 56 | */ 57 | Filter map(final Function mapper); 58 | 59 | /** 60 | * Return a filter consisting of the results of replacing each element with 61 | * the contents of the mapped elements. 62 | * 63 | * @param mapper a non-interfering, stateless function to apply to each 64 | * element which produces a list of new values 65 | * @return a new filter 66 | */ 67 | Filter flatMap(final Function> mapper); 68 | 69 | /** 70 | * Return a filter with the results of the applying given mapper function. 71 | * 72 | * @param mapper a non-interfering, stateless function to apply to the 73 | * existing elements 74 | * @return a new filter 75 | */ 76 | Filter listMap(final Function, ? extends List> mapper); 77 | 78 | /** 79 | * Return a new object of type {@code R} which contains the elements of the 80 | * applied filter functions. 81 | * 82 | * @return a new object created from the given filter 83 | */ 84 | R build(); 85 | 86 | } 87 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/Fix.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static java.util.Objects.requireNonNull; 23 | 24 | import java.util.Optional; 25 | 26 | /** 27 | * Type of GPS fix. {@code none} means GPS had no fix. To signify "the fix info 28 | * is unknown", leave out {@code Fix} entirely. {@code pps} = military signal 29 | * used. 30 | * 31 | * @author Franz Wilhelmstötter 32 | * @version 1.2 33 | * @since 1.0 34 | */ 35 | public enum Fix { 36 | 37 | NONE("none"), 38 | DIM_2("2d"), 39 | DIM_3("3d"), 40 | DGPS("dgps"), 41 | PPS("pps"); 42 | 43 | private final String _value; 44 | 45 | Fix(final String value) { 46 | _value = requireNonNull(value); 47 | } 48 | 49 | /** 50 | * Return the string representation of the GPS {@code Fix}. {@code none}, 51 | * {@code 2d}. {@code 3d}, {@code dgps} or {@code pps}. 52 | * 53 | * @return the string representation of the GPS {@code Fix} 54 | */ 55 | public String getValue() { 56 | return _value; 57 | } 58 | 59 | /** 60 | * Return the {@code Fix} constant for the given fix {@code value}. 61 | * 62 | * @param name the GPS fix names 63 | * @return the GPS fix for the given value, or {@code Optional.empty()} if 64 | * the given {@code name} is invalid 65 | */ 66 | public static Optional ofName(final String name) { 67 | return switch (name) { 68 | case "none" -> Optional.of(Fix.NONE); 69 | case "2d" -> Optional.of(Fix.DIM_2); 70 | case "3d" -> Optional.of(Fix.DIM_3); 71 | case "dgps" -> Optional.of(Fix.DGPS); 72 | case "pps" -> Optional.of(Fix.PPS); 73 | default -> Optional.empty(); 74 | }; 75 | } 76 | 77 | static String format(final Fix fix) { 78 | return fix != null ? fix._value : null; 79 | } 80 | 81 | static Fix parse(final String value) { 82 | final String fix = Strings.trim(value); 83 | 84 | return fix != null 85 | ? Fix.ofName(fix).orElseThrow(() -> 86 | new IllegalArgumentException(String.format( 87 | "Invalid value for: '%s'.", fix))) 88 | : null; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/Format.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static java.lang.String.format; 23 | 24 | import java.net.URI; 25 | import java.net.URISyntaxException; 26 | import java.time.Duration; 27 | import java.time.Year; 28 | 29 | /** 30 | * Some helper methods for parsing GPS values. 31 | * 32 | * @author Franz Wilhelmstötter 33 | * @version 1.2 34 | * @since 1.0 35 | */ 36 | final class Format { 37 | 38 | private Format() { 39 | } 40 | 41 | static Double parseDouble(final String value) { 42 | final String d = Strings.trim(value); 43 | return d != null ? Double.parseDouble(d) : null; 44 | } 45 | 46 | /** 47 | * Convert the given {@code object} into a duration value. If the 48 | * {@code object} is {@code null}, {@code null} is returned. 49 | * 50 | * @param value the object to convert 51 | * @return the converted object 52 | */ 53 | static Duration parseDuration(final String value) { 54 | final String duration = Strings.trim(value); 55 | return duration != null 56 | ? Duration.ofSeconds(Long.parseLong(duration)) 57 | : null; 58 | } 59 | 60 | static String toDurationString(final Duration duration) { 61 | return duration != null ? Long.toString(duration.getSeconds()) : null; 62 | } 63 | 64 | /** 65 | * Convert the given {@code object} into a year value. If the 66 | * {@code object} is {@code null}, {@code null} is returned. 67 | * 68 | * @param value the string value to parse 69 | * @return the converted object 70 | */ 71 | static Year parseYear(final String value) { 72 | final String year = Strings.trim(value); 73 | return year != null ? Year.of(Integer.parseInt(year)) : null; 74 | } 75 | 76 | static String toYearString(final Year year) { 77 | return year != null ? Integer.toString(year.getValue()) : null; 78 | } 79 | 80 | /** 81 | * Convert the given {@code object} into a URI value. If the 82 | * {@code object} is {@code null}, {@code null} is returned. 83 | * 84 | * @param value the string to convert 85 | * @return the converted object 86 | */ 87 | static URI parseURI(final String value) { 88 | try { 89 | final String uri = Strings.trim(value); 90 | return uri != null ? new URI(uri) : null; 91 | } catch (URISyntaxException e) { 92 | throw new IllegalArgumentException(format( 93 | "Invalid URI value: '%s'.", value 94 | )); 95 | } 96 | } 97 | 98 | static String toUriString(final URI uri) { 99 | return uri != null ? uri.toString() : null; 100 | } 101 | 102 | static String toIntString(final Number number) { 103 | return number != null ? Integer.toString(number.intValue()) : null; 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/Instants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import java.io.DataInput; 23 | import java.io.DataOutput; 24 | import java.io.IOException; 25 | import java.time.Instant; 26 | 27 | /** 28 | * @author Franz Wilhelmstötter 29 | * @version 3.0 30 | * @since 1.2 31 | */ 32 | final class Instants { 33 | 34 | private Instants() { 35 | } 36 | 37 | static void write(final Instant time, final DataOutput out) 38 | throws IOException 39 | { 40 | IO.writeLong(time.getEpochSecond(), out); 41 | IO.writeInt(time.getNano(), out); 42 | } 43 | 44 | static Instant read(final DataInput in) throws IOException { 45 | final var seconds = IO.readLong(in); 46 | final var nanos = IO.readInt(in); 47 | return Instant.ofEpochSecond(seconds, nanos); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/Lists.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static java.util.Objects.requireNonNull; 23 | 24 | import java.util.Collection; 25 | import java.util.HashSet; 26 | import java.util.Iterator; 27 | import java.util.List; 28 | import java.util.Objects; 29 | import java.util.Set; 30 | 31 | /** 32 | * Helper methods for handling lists. All method handles null values correctly. 33 | * 34 | * @author Franz Wilhelmstötter 35 | * @version 2.0 36 | * @since 1.0 37 | */ 38 | final class Lists { 39 | 40 | private Lists() { 41 | } 42 | 43 | static List copyOf(final List list) { 44 | return list == null ? List.of() : List.copyOf(list); 45 | } 46 | 47 | static void copyTo( 48 | final List source, 49 | final List target 50 | ) { 51 | requireNonNull(target); 52 | if (source != null) { 53 | source.forEach(Objects::requireNonNull); 54 | } 55 | 56 | target.clear(); 57 | if (source != null) { 58 | target.addAll(source); 59 | } 60 | } 61 | 62 | static int hashCode(final List list) { 63 | return list != null 64 | ? 17*list.stream().mapToInt(Objects::hashCode).sum() + 31 65 | : 0; 66 | } 67 | 68 | static boolean equals(final List b, final List a) { 69 | boolean result = false; 70 | if (a != null) { 71 | if (b != null) { 72 | result = a.size() == b.size(); 73 | if (result) { 74 | result = a.isEmpty()|| containsAll(a, b); 75 | } 76 | } 77 | } else { 78 | result = b == null; 79 | } 80 | 81 | return result; 82 | } 83 | 84 | private static boolean containsAll(final Collection a, final Collection b) { 85 | final Iterator ita = a.iterator(); 86 | final Set visited = new HashSet<>(); 87 | 88 | for (final Object next : b) { 89 | if (visited.contains(next)) { 90 | continue; 91 | } 92 | 93 | boolean foundCurrentElement = false; 94 | while (ita.hasNext()) { 95 | final Object p = ita.next(); 96 | visited.add(p); 97 | 98 | if (Objects.equals(next, p)) { 99 | foundCurrentElement = true; 100 | break; 101 | } 102 | } 103 | 104 | if (!foundCurrentElement) { 105 | return false; 106 | } 107 | } 108 | 109 | return true; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/NonCloseableInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static java.util.Objects.requireNonNull; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | import java.io.OutputStream; 27 | 28 | /** 29 | * @author Franz Wilhelmstötter 30 | * @version 3.0 31 | * @since 3.0 32 | */ 33 | final class NonCloseableInputStream extends InputStream { 34 | 35 | private final InputStream _input; 36 | 37 | NonCloseableInputStream(final InputStream input) { 38 | _input = requireNonNull(input); 39 | } 40 | 41 | @Override 42 | public int read() throws IOException { 43 | return _input.read(); 44 | } 45 | 46 | @Override 47 | public int read(byte[] b) throws IOException { 48 | return _input.read(b); 49 | } 50 | 51 | @Override 52 | public int read(byte[] b, int off, int len) throws IOException { 53 | return _input.read(b, off, len); 54 | } 55 | 56 | @Override 57 | public byte[] readAllBytes() throws IOException { 58 | return _input.readAllBytes(); 59 | } 60 | 61 | @Override 62 | public byte[] readNBytes(int len) throws IOException { 63 | return _input.readNBytes(len); 64 | } 65 | 66 | @Override 67 | public int readNBytes(byte[] b, int off, int len) throws IOException { 68 | return _input.readNBytes(b, off, len); 69 | } 70 | 71 | @Override 72 | public long skip(long n) throws IOException { 73 | return _input.skip(n); 74 | } 75 | 76 | @Override 77 | public void skipNBytes(long n) throws IOException { 78 | _input.skipNBytes(n); 79 | } 80 | 81 | @Override 82 | public int available() throws IOException { 83 | return _input.available(); 84 | } 85 | 86 | @Override 87 | public void close() { 88 | } 89 | 90 | @Override 91 | public void mark(int readlimit) { 92 | _input.mark(readlimit); 93 | } 94 | 95 | @Override 96 | public void reset() throws IOException { 97 | _input.reset(); 98 | } 99 | 100 | @Override 101 | public boolean markSupported() { 102 | return _input.markSupported(); 103 | } 104 | 105 | @Override 106 | public long transferTo(OutputStream out) throws IOException { 107 | return _input.transferTo(out); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/NonCloseableOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static java.util.Objects.requireNonNull; 23 | 24 | import java.io.IOException; 25 | import java.io.OutputStream; 26 | 27 | /** 28 | * @author Franz Wilhelmstötter 29 | * @version 1.3 30 | * @since 1.3 31 | */ 32 | final class NonCloseableOutputStream extends OutputStream { 33 | 34 | private final OutputStream _output; 35 | 36 | NonCloseableOutputStream(final OutputStream output) { 37 | _output = requireNonNull(output); 38 | } 39 | 40 | @Override 41 | public void write(final int b) throws IOException { 42 | _output.write(b); 43 | } 44 | 45 | @Override 46 | public void write(final byte[] b) throws IOException { 47 | _output.write(b); 48 | } 49 | 50 | @Override 51 | public void write(final byte[] b, final int off, final int len) 52 | throws IOException 53 | { 54 | _output.write(b, off, len); 55 | } 56 | 57 | @Override 58 | public void flush() throws IOException { 59 | _output.flush(); 60 | } 61 | 62 | @Override 63 | public void close() throws IOException { 64 | flush(); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/Point.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import java.time.Instant; 23 | import java.util.Optional; 24 | 25 | import io.jenetics.jpx.geom.Geoid; 26 | 27 | /** 28 | * A geographic point with optional elevation and time. 29 | * 30 | * @author Franz Wilhelmstötter 31 | * @version 3.0 32 | * @since 1.0 33 | */ 34 | public interface Point { 35 | 36 | /** 37 | * The latitude of the point, WGS84 datum. 38 | * 39 | * @return the latitude of the point 40 | */ 41 | Latitude getLatitude(); 42 | 43 | /** 44 | * The longitude of the point, WGS84 datum. 45 | * 46 | * @return the longitude of the point 47 | */ 48 | Longitude getLongitude(); 49 | 50 | /** 51 | * The elevation (in meters) of the point. 52 | * 53 | * @return the elevation (in meters) of the point 54 | */ 55 | default Optional getElevation() { 56 | return Optional.empty(); 57 | } 58 | 59 | /** 60 | * Creation/modification timestamp for the point. 61 | * 62 | * @return creation/modification timestamp for the point 63 | */ 64 | default Optional getTime() { 65 | return Optional.empty(); 66 | } 67 | 68 | /** 69 | * Calculate the distance between points on the default ellipsoidal earth 70 | * model 71 | * 72 | * WGS-84. 73 | * 74 | * @see DIRECT AND 75 | * INVERSE SOLUTIONS OF GEODESICS 0 THE ELLIPSOID 76 | * WITH APPLICATION OF NESTED EQUATIONS 77 | * @see 78 | * Vincenty solutions of geodesics on the ellipsoid 79 | * 80 | * @param end the end point 81 | * @return the distance between {@code this} and {@code end} in meters 82 | * @throws NullPointerException if the {@code end} point is {@code null} 83 | */ 84 | default Length distance(final Point end) { 85 | return Geoid.DEFAULT.distance(this, end); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/Strings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | /** 23 | * Some string helper methods. 24 | * 25 | * @author Franz Wilhelmstötter 26 | * @version 2.0 27 | * @since 1.5.2 28 | */ 29 | final class Strings { 30 | private Strings() { 31 | } 32 | 33 | /** 34 | * Trims the given input string. If the {@code value} is empty or {@code null}, 35 | * {@code null} is returned. 36 | * 37 | * @param value the string value to trim 38 | * @return the trimmed string value 39 | */ 40 | static String trim(final String value) { 41 | return value != null && !value.isBlank() ? value.strip() : null; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/UInt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static java.lang.String.format; 23 | 24 | import java.io.DataInput; 25 | import java.io.DataOutput; 26 | import java.io.IOException; 27 | import java.io.InvalidObjectException; 28 | import java.io.ObjectInputStream; 29 | import java.io.Serial; 30 | import java.io.Serializable; 31 | 32 | /** 33 | * Represents an unsigned integer value. 34 | * 35 | * @see Value object 36 | * 37 | * @author Franz Wilhelmstötter 38 | * @version 1.2 39 | * @since 1.0 40 | */ 41 | public final class UInt 42 | extends Number 43 | implements 44 | Comparable, 45 | Serializable 46 | { 47 | 48 | @Serial 49 | private static final long serialVersionUID = 2L; 50 | 51 | private final int _value; 52 | 53 | /** 54 | * Create a new unsigned integer object with the given value. 55 | * 56 | * @param value the {@code UInt} value 57 | * @throws IllegalArgumentException if the given {@code value} is smaller 58 | * than zero 59 | */ 60 | private UInt(final int value) { 61 | if (value < 0) { 62 | throw new IllegalArgumentException(format("%d is negative.", value)); 63 | } 64 | _value = value; 65 | } 66 | 67 | /** 68 | * Return the unsigned integer value. 69 | * 70 | * @return the unsigned integer value 71 | */ 72 | public int getValue() { 73 | return _value; 74 | } 75 | 76 | @Override 77 | public int intValue() { 78 | return _value; 79 | } 80 | 81 | @Override 82 | public long longValue() { 83 | return _value; 84 | } 85 | 86 | @Override 87 | public float floatValue() { 88 | return _value; 89 | } 90 | 91 | @Override 92 | public double doubleValue() { 93 | return _value; 94 | } 95 | 96 | @Override 97 | public int compareTo(final UInt other) { 98 | return Integer.compare(_value, other._value); 99 | } 100 | 101 | @Override 102 | public int hashCode() { 103 | return Integer.hashCode(_value); 104 | } 105 | 106 | @Override 107 | public boolean equals(final Object obj) { 108 | return obj == this || 109 | obj instanceof UInt uint && 110 | uint._value == _value; 111 | } 112 | 113 | @Override 114 | public String toString() { 115 | return Integer.toString(_value); 116 | } 117 | 118 | 119 | /* ************************************************************************* 120 | * Static object creation methods 121 | * ************************************************************************/ 122 | 123 | /** 124 | * Create a new unsigned integer object with the given value. 125 | * 126 | * @param value the {@code UInt} value 127 | * @return a new unsigned integer object with the given value 128 | * @throws IllegalArgumentException if the given {@code value} is smaller 129 | * than zero 130 | */ 131 | public static UInt of(final int value) { 132 | return new UInt(value); 133 | } 134 | 135 | static UInt parse(final String value) { 136 | final String uint = Strings.trim(value); 137 | 138 | return uint != null 139 | ? UInt.of(Integer.parseInt(uint)) 140 | : null; 141 | } 142 | 143 | /* ************************************************************************* 144 | * Java object serialization 145 | * ************************************************************************/ 146 | 147 | @Serial 148 | private Object writeReplace() { 149 | return new SerialProxy(SerialProxy.UINT, this); 150 | } 151 | 152 | @Serial 153 | private void readObject(final ObjectInputStream stream) 154 | throws InvalidObjectException 155 | { 156 | throw new InvalidObjectException("Serialization proxy required."); 157 | } 158 | 159 | void write(final DataOutput out) throws IOException { 160 | IO.writeInt(_value, out); 161 | } 162 | 163 | static UInt read(final DataInput in) throws IOException { 164 | return new UInt(IO.readInt(in)); 165 | } 166 | 167 | } 168 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/XMLProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | * Antoine Vianey (https://github.com/avianey) 20 | */ 21 | package io.jenetics.jpx; 22 | 23 | import java.util.Iterator; 24 | import java.util.ServiceLoader; 25 | 26 | import javax.xml.parsers.DocumentBuilderFactory; 27 | import javax.xml.stream.XMLInputFactory; 28 | import javax.xml.stream.XMLOutputFactory; 29 | 30 | /** 31 | * A {@link ServiceLoader} for managing XML factories used by the library. 32 | * Custom implementation should be referenced in a 33 | * {@code META-INF/services/io.jenetics.jpx.XMLProvider} file. 34 | * 35 | * @see ServiceLoader 36 | * 37 | * @version 1.7 38 | * @since 1.7 39 | */ 40 | public abstract class XMLProvider { 41 | 42 | private static final Object LOCK = new Object(){}; 43 | 44 | private static volatile XMLProvider INSTANCE; 45 | 46 | protected XMLProvider() { 47 | } 48 | 49 | /** 50 | * Returns {@link XMLInputFactory} to be used for reading files. 51 | * 52 | * @return the XML input factory 53 | */ 54 | public XMLInputFactory xmlInputFactory() { 55 | return XMLInputFactory.newInstance(); 56 | } 57 | 58 | /** 59 | * Returns {@link XMLOutputFactory} to be used for writing files. 60 | * 61 | * @return the XML output factory 62 | */ 63 | public XMLOutputFactory xmlOutputFactory() { 64 | return XMLOutputFactory.newInstance(); 65 | } 66 | 67 | /** 68 | * Returns the {@link DocumentBuilderFactory} used for handling extensions documents 69 | * 70 | * @return the document builder factory 71 | */ 72 | public DocumentBuilderFactory documentBuilderFactory() { 73 | final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 74 | factory.setIgnoringElementContentWhitespace(true); 75 | factory.setNamespaceAware(true); 76 | return factory; 77 | } 78 | 79 | /** 80 | * Return an instance of the current {@code XMLProvider}. 81 | * 82 | * @return an instance of the current {@code XMLProvider} 83 | */ 84 | public static XMLProvider provider() { 85 | if (INSTANCE == null) { 86 | synchronized (LOCK) { 87 | if (INSTANCE == null) { 88 | loadInstance(); 89 | } 90 | } 91 | } 92 | return INSTANCE; 93 | } 94 | 95 | /** 96 | * Clear current spi to allow hot reloading a new one... 97 | */ 98 | protected static void clear() { 99 | if (INSTANCE != null) { 100 | synchronized (LOCK) { 101 | if (INSTANCE != null) { 102 | INSTANCE = null; 103 | } 104 | } 105 | } 106 | } 107 | 108 | private static void loadInstance() { 109 | final ServiceLoader loader = 110 | ServiceLoader.load(XMLProvider.class); 111 | 112 | final Iterator providers = loader.iterator(); 113 | if (providers.hasNext()) { 114 | INSTANCE = providers.next(); 115 | } else { 116 | INSTANCE = new DefaultXMLProvider(); 117 | } 118 | } 119 | 120 | } 121 | 122 | /** 123 | * Default implementation of the {@code XMLProvider} class. Doesn't need any 124 | * additional implementation. 125 | */ 126 | final class DefaultXMLProvider extends XMLProvider { } 127 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/XMLReaders.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static java.util.Objects.requireNonNull; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | import java.util.stream.IntStream; 27 | 28 | import io.jenetics.jpx.GPX.Version; 29 | 30 | /** 31 | * XMLReader collection for different GPX versions. 32 | * 33 | * @author Franz Wilhelmstötter 34 | * @version 1.3 35 | * @since 1.3 36 | */ 37 | final class XMLReaders{ 38 | 39 | private final List _versions = new ArrayList<>(); 40 | private final List> _readers = new ArrayList<>(); 41 | 42 | 43 | XMLReaders v00(final XMLReader reader) { 44 | requireNonNull(reader); 45 | _versions.add(null); 46 | _readers.add(reader); 47 | return this; 48 | } 49 | 50 | XMLReaders v10(final XMLReader reader) { 51 | requireNonNull(reader); 52 | _versions.add(Version.V10); 53 | _readers.add(reader); 54 | return this; 55 | } 56 | 57 | XMLReaders v11(final XMLReader reader) { 58 | requireNonNull(reader); 59 | _versions.add(Version.V11); 60 | _readers.add(reader); 61 | return this; 62 | } 63 | 64 | XMLReader[] readers(final Version version) { 65 | return IntStream.range(0, _versions.size()) 66 | .filter(i -> _versions.get(i) == null || _versions.get(i) == version) 67 | .mapToObj(_readers::get) 68 | .toArray(XMLReader[]::new); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/XMLWriters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static java.util.Objects.requireNonNull; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | import java.util.stream.IntStream; 27 | 28 | import io.jenetics.jpx.GPX.Version; 29 | 30 | /** 31 | * XMLWriter collection for different GPX versions. 32 | * 33 | * @author Franz Wilhelmstötter 34 | * @version 1.3 35 | * @since 1.3 36 | */ 37 | final class XMLWriters { 38 | 39 | private final List _versions = new ArrayList<>(); 40 | private final List> _writers = new ArrayList<>(); 41 | 42 | 43 | XMLWriters v00(final XMLWriter writer) { 44 | requireNonNull(writer); 45 | _versions.add(null); 46 | _writers.add(writer); 47 | return this; 48 | } 49 | 50 | XMLWriters v10(final XMLWriter writer) { 51 | requireNonNull(writer); 52 | _versions.add(Version.V10); 53 | _writers.add(writer); 54 | return this; 55 | } 56 | 57 | XMLWriters v11(final XMLWriter writer) { 58 | requireNonNull(writer); 59 | _versions.add(Version.V11); 60 | _writers.add(writer); 61 | return this; 62 | } 63 | 64 | @SuppressWarnings("unchecked") 65 | XMLWriter[] writers(final Version version) { 66 | return IntStream.range(0, _versions.size()) 67 | .filter(i -> _versions.get(i) == null || _versions.get(i) == version) 68 | .mapToObj(_writers::get) 69 | .toArray(XMLWriter[]::new); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/CompositeFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx.format; 21 | 22 | import java.text.ParsePosition; 23 | import java.util.List; 24 | import java.util.Optional; 25 | import java.util.stream.Collectors; 26 | 27 | /** 28 | * @author Franz Wilhelmstötter 29 | * @version 2.2 30 | * @since 1.4 31 | */ 32 | class CompositeFormat implements Format { 33 | 34 | private final List _formats; 35 | 36 | private CompositeFormat(final List formats) { 37 | _formats = List.copyOf(formats); 38 | } 39 | 40 | @Override 41 | public Optional format(final Location value) { 42 | final List> strings = _formats.stream() 43 | .map(format -> format.format(value)) 44 | .toList(); 45 | 46 | final boolean complete = strings.stream().allMatch(Optional::isPresent); 47 | return complete 48 | ? Optional.of( 49 | strings.stream() 50 | .map(s -> s.orElseThrow(AssertionError::new)) 51 | .collect(Collectors.joining())) 52 | : Optional.empty(); 53 | } 54 | 55 | @Override 56 | public void parse( 57 | final CharSequence in, 58 | final ParsePosition pos, 59 | final LocationBuilder builder 60 | ) { 61 | for(var format : _formats) { 62 | format.parse(in, pos, builder); 63 | } 64 | } 65 | 66 | @Override 67 | public String toPattern() { 68 | return _formats.stream() 69 | .map(Format::toPattern) 70 | .collect(Collectors.joining()); 71 | } 72 | 73 | static CompositeFormat of(final List formats) { 74 | return new CompositeFormat(formats); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/ConstFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx.format; 21 | 22 | import static java.util.Objects.requireNonNull; 23 | import static io.jenetics.jpx.format.LocationFormatter.PROTECTED_CHARS; 24 | 25 | import java.text.ParsePosition; 26 | import java.util.Optional; 27 | 28 | /** 29 | * A format object which returns a constant value. 30 | * 31 | * @author Franz Wilhelmstötter 32 | * @version 2.2 33 | * @since 1.4 34 | */ 35 | final class ConstFormat implements Format { 36 | 37 | private final String _value; 38 | 39 | /** 40 | * Create a new constant location format object. 41 | * 42 | * @param value the constant value, returned by the 43 | * {@link Format#format(Location)} method 44 | */ 45 | private ConstFormat(final String value) { 46 | _value = requireNonNull(value); 47 | } 48 | 49 | @Override 50 | public Optional format(final Location value) { 51 | return Optional.of(_value); 52 | } 53 | 54 | @Override 55 | public void parse( 56 | final CharSequence in, 57 | final ParsePosition pos, 58 | final LocationBuilder builder 59 | ) { 60 | final int start = pos.getIndex(); 61 | final int end = start + _value.length(); 62 | 63 | if (end <= in.length()) { 64 | final var s = in.subSequence(start, end).toString(); 65 | if (s.equals(_value)) { 66 | pos.setIndex(end); 67 | } else { 68 | pos.setErrorIndex(start); 69 | throw new ParseException( 70 | String.format("Not found constant '%s'", _value), 71 | in, 72 | start 73 | ); 74 | } 75 | } 76 | } 77 | 78 | @Override 79 | public String toPattern() { 80 | return escape(_value); 81 | } 82 | 83 | private static String escape(final String value) { 84 | final StringBuilder out = new StringBuilder(); 85 | boolean quoted = false; 86 | for (int i = 0; i < value.length(); ++i) { 87 | final char c = value.charAt(i); 88 | if (PROTECTED_CHARS.contains(c)) { 89 | quoted = true; 90 | } 91 | if (c == '\'') { 92 | out.append(c); 93 | } 94 | out.append(c); 95 | } 96 | 97 | return quoted 98 | ? "'" + out + "'" 99 | : out.toString(); 100 | } 101 | 102 | static ConstFormat of(final String value) { 103 | return new ConstFormat(value); 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/Elevation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.jenetics.jpx.format; 17 | 18 | import static io.jenetics.jpx.Length.Unit.METER; 19 | 20 | import java.text.ParsePosition; 21 | import java.util.Optional; 22 | 23 | /** 24 | * This field allows accessing the elevation (in meter) of a given location. 25 | * 26 | * @version 2.2 27 | * @since 2.2 28 | */ 29 | final class Elevation extends Field { 30 | 31 | Elevation(final String pattern) { 32 | super(pattern, 'E'); 33 | } 34 | 35 | @Override 36 | public void parse( 37 | final CharSequence in, 38 | final ParsePosition pos, 39 | final LocationBuilder builder 40 | ) { 41 | builder.setElevation(parse(in, pos)); 42 | } 43 | 44 | @Override 45 | public Optional format(final Location loc) { 46 | return loc.elevation() 47 | .map(l -> l.to(METER)) 48 | .map(this::format); 49 | } 50 | 51 | @Override 52 | public String toPattern() { 53 | return isPrefixSign() ? "+" + super.toPattern() : super.toPattern(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/Format.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx.format; 21 | 22 | import java.text.ParsePosition; 23 | import java.util.Optional; 24 | 25 | /** 26 | * Base interface for formatting and parsing a location. 27 | * 28 | * @author Franz Wilhelmstötter 29 | * @version 2.2 30 | * @since 1.4 31 | */ 32 | interface Format { 33 | 34 | /** 35 | * Formats the given {@code value} to its string representation. If it is not 36 | * possible to convert the {@code value} to a string, {@link Optional#empty()} 37 | * is returned. 38 | * 39 | * @param value the value which is converted to a string. 40 | * @return the converted value, or {@link Optional#empty()} if the format 41 | * fails 42 | */ 43 | Optional format(final Location value); 44 | 45 | /** 46 | * Parses the given input value, {@code in}. 47 | * 48 | * @param in the input string to parse 49 | * @param pos the current parse position 50 | * @param builder the location builder 51 | * @throws ParseException it the parsing fails 52 | * @throws NullPointerException if one of the given parameters is {@code null} 53 | */ 54 | void parse( 55 | final CharSequence in, 56 | final ParsePosition pos, 57 | final LocationBuilder builder 58 | ); 59 | 60 | /** 61 | * Return a string representation of the format pattern. 62 | * 63 | * @return a string representation of the format pattern 64 | */ 65 | String toPattern(); 66 | 67 | } 68 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/FormatterException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx.format; 21 | 22 | import java.io.Serial; 23 | 24 | /** 25 | * This exception is thrown if formatting or parsing of a location object fails. 26 | * 27 | * @author Franz Wilhelmstötter 28 | * @version 1.4 29 | * @since 1.4 30 | */ 31 | public class FormatterException extends RuntimeException { 32 | 33 | @Serial 34 | private static final long serialVersionUID = 1; 35 | 36 | /** 37 | * Create a new exception with the given detail {@code message}. 38 | * 39 | * @param message the detail message 40 | */ 41 | public FormatterException(final String message) { 42 | super(message); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/LatitudeDegree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.jenetics.jpx.format; 17 | 18 | import static java.lang.Math.abs; 19 | 20 | import java.text.ParsePosition; 21 | import java.util.Optional; 22 | 23 | import io.jenetics.jpx.Latitude; 24 | 25 | /** 26 | * This field allows accessing the latitude degrees of a given location. If the 27 | * pattern has a fractional part, the latitude is rounded to match the pattern. 28 | * If the pattern has no fractional part, the latitude is truncated rather than 29 | * rounded, on the assumption that the fractional part will be represented by 30 | * minutes and seconds. 31 | * 32 | * @version 2.2 33 | * @since 2.2 34 | */ 35 | final class LatitudeDegree extends Field { 36 | 37 | LatitudeDegree(final String pattern) { 38 | super(pattern, 'D'); 39 | } 40 | 41 | @Override 42 | public void parse( 43 | final CharSequence in, 44 | final ParsePosition pos, 45 | final LocationBuilder builder 46 | ) { 47 | double d = parse(in, pos); 48 | builder.addLatitude(d); 49 | } 50 | 51 | @Override 52 | public Optional format(final Location loc) { 53 | return loc.latitude() 54 | .map(Latitude::toDegrees) 55 | .map(d -> isAbsolute() ? abs(d) : d) 56 | .map(this::format); 57 | } 58 | 59 | @Override 60 | public String toPattern() { 61 | return isPrefixSign() ? "+" + super.toPattern() : super.toPattern(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/LatitudeMinute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.jenetics.jpx.format; 17 | 18 | import java.text.ParsePosition; 19 | import java.util.Optional; 20 | 21 | import io.jenetics.jpx.Latitude; 22 | 23 | /** 24 | * This field allows accessing the absolute value of the minute part of the 25 | * latitude of a given location. 26 | * 27 | * @version 2.2 28 | * @since 2.2 29 | */ 30 | final class LatitudeMinute extends Field { 31 | 32 | LatitudeMinute(final String pattern) { 33 | super(pattern, 'M'); 34 | } 35 | 36 | @Override 37 | public void parse( 38 | final CharSequence in, 39 | final ParsePosition pos, 40 | final LocationBuilder builder 41 | ) { 42 | double d = parse(in, pos); 43 | builder.addLatitudeMinute(d); 44 | } 45 | 46 | @Override 47 | public Optional format(final Location loc) { 48 | return loc.latitude() 49 | .map(Latitude::toDegrees) 50 | .map(Field::toMinutes) 51 | .map(this::format); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/LatitudeNS.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx.format; 21 | 22 | import java.text.ParsePosition; 23 | import java.util.Optional; 24 | 25 | import io.jenetics.jpx.Latitude; 26 | 27 | /** 28 | * @author Franz Wilhelmstötter 29 | * 30 | * @version 2.2 31 | * @since 1.4 32 | */ 33 | enum LatitudeNS implements Format { 34 | 35 | INSTANCE; 36 | 37 | @Override 38 | public Optional format(final Location value) { 39 | return value.latitude() 40 | .map(Latitude::toDegrees) 41 | .map(v -> Double.compare(v, 0.0) >= 0 ? "N" : "S"); 42 | } 43 | 44 | @Override 45 | public void parse( 46 | final CharSequence in, 47 | final ParsePosition pos, 48 | final LocationBuilder builder 49 | ) { 50 | final int i = pos.getIndex(); 51 | switch (in.charAt(i)) { 52 | case 'N' -> { 53 | pos.setIndex(i + 1); 54 | builder.setLatitudeSign(+1); 55 | } 56 | case 'S' -> { 57 | pos.setIndex(i + 1); 58 | builder.setLatitudeSign(-1); 59 | } 60 | default -> { 61 | pos.setErrorIndex(i); 62 | throw new ParseException("Not found N/S", in, i); 63 | } 64 | } 65 | } 66 | 67 | @Override 68 | public String toPattern() { 69 | return "X"; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/LatitudeSecond.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.jenetics.jpx.format; 17 | 18 | import java.text.ParsePosition; 19 | import java.util.Optional; 20 | 21 | import io.jenetics.jpx.Latitude; 22 | 23 | /** 24 | * This field allows accessing the absolute value of the second part of the 25 | * latitude of a given location. 26 | * 27 | * @version 2.2 28 | * @since 2.2 29 | */ 30 | final class LatitudeSecond extends Field { 31 | 32 | LatitudeSecond(final String pattern) { 33 | super(pattern, 'S'); 34 | } 35 | 36 | @Override 37 | public void parse( 38 | final CharSequence in, 39 | final ParsePosition pos, 40 | final LocationBuilder builder 41 | ) { 42 | double d = parse(in, pos); 43 | builder.addLatitudeSecond(d); 44 | } 45 | 46 | @Override 47 | public Optional format(final Location loc) { 48 | return loc.latitude() 49 | .map(Latitude::toDegrees) 50 | .map(Field::toSeconds) 51 | .map(this::format); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/LocationBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.jenetics.jpx.format; 17 | 18 | import io.jenetics.jpx.Latitude; 19 | import io.jenetics.jpx.Length; 20 | import io.jenetics.jpx.Longitude; 21 | 22 | /** 23 | * @version 2.2 24 | * @since 2.2 25 | */ 26 | final class LocationBuilder { 27 | 28 | private Double _latitude = null; 29 | private int _latitudeSign = +1; 30 | 31 | private Double _longitude = null; 32 | private int _longitudeSign = +1; 33 | 34 | private Double elevation = null; 35 | 36 | LocationBuilder copy() { 37 | LocationBuilder c = new LocationBuilder(); 38 | c._latitudeSign = _latitudeSign; 39 | c._latitude = _latitude; 40 | c._longitudeSign = _longitudeSign; 41 | c._longitude = _longitude; 42 | c.elevation = elevation; 43 | return c; 44 | } 45 | 46 | void copy(final LocationBuilder from) { 47 | _latitudeSign = from._latitudeSign; 48 | _latitude = from._latitude; 49 | _longitudeSign = from._longitudeSign; 50 | _longitude = from._longitude; 51 | elevation = from.elevation; 52 | } 53 | 54 | void setLatitudeSign(final int sign) { 55 | _latitudeSign = sign; 56 | } 57 | 58 | void addLatitude(final double degrees) { 59 | if (degrees < 0.0) { 60 | _latitudeSign = -1; 61 | } 62 | if (_latitude == null) { 63 | _latitude = 0.0; 64 | } 65 | _latitude += Math.abs(degrees); 66 | } 67 | 68 | void addLatitudeMinute(final double minutes) { 69 | addLatitude(minutes/60.0); 70 | } 71 | 72 | void addLatitudeSecond(final double seconds) { 73 | addLatitude( seconds/3600.0); 74 | } 75 | 76 | void setLongitudeSign(final int sign) { 77 | _longitudeSign = sign; 78 | } 79 | 80 | void addLongitude(final double degrees) { 81 | if (degrees < 0.0) { 82 | _longitudeSign = -1; 83 | } 84 | if (_longitude == null) { 85 | _longitude = 0.0; 86 | } 87 | _longitude += Math.abs(degrees); 88 | } 89 | 90 | void addLongitudeMinute(final double minutes) { 91 | addLongitude(minutes/60.0); 92 | } 93 | 94 | void addLongitudeSecond(final double seconds) { 95 | addLongitude(seconds/3600.0); 96 | } 97 | 98 | void setElevation(final double meters) { 99 | elevation = meters; 100 | } 101 | 102 | Location build() { 103 | final var lat = _latitude == null 104 | ? null 105 | : Latitude.ofDegrees(_latitudeSign*_latitude); 106 | final var lon = _longitude == null 107 | ? null 108 | : Longitude.ofDegrees(_longitudeSign*_longitude); 109 | final var ele = elevation == null 110 | ? null 111 | : Length.of(elevation, Length.Unit.METER); 112 | 113 | return Location.of(lat, lon, ele); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/LongitudeDegree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.jenetics.jpx.format; 17 | 18 | import static java.lang.Math.abs; 19 | 20 | import java.text.ParsePosition; 21 | import java.util.Optional; 22 | 23 | import io.jenetics.jpx.Longitude; 24 | 25 | /** 26 | * This field allows accessing the longitude degrees of a given location. If the 27 | * pattern has a fractional part, the longitude is rounded to match the pattern. 28 | * If the pattern has no fractional part, the longitude is truncated rather than 29 | * rounded, on the assumption that the fractional part will be represented by 30 | * minutes and seconds. 31 | * 32 | * @version 2.2 33 | * @since 2.2 34 | */ 35 | class LongitudeDegree extends Field { 36 | 37 | LongitudeDegree(final String pattern) { 38 | super(pattern, 'd'); 39 | } 40 | 41 | @Override 42 | public void parse( 43 | final CharSequence in, 44 | final ParsePosition pos, 45 | final LocationBuilder builder 46 | ) { 47 | double d = parse(in, pos); 48 | builder.addLongitude(d); 49 | } 50 | 51 | @Override 52 | public Optional format(final Location loc) { 53 | return loc.longitude() 54 | .map(Longitude::toDegrees) 55 | .map(d -> isAbsolute() ? abs(d) : d) 56 | .map(this::format); 57 | } 58 | 59 | @Override 60 | public String toPattern() { 61 | return isPrefixSign() ? "+" + super.toPattern() : super.toPattern(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/LongitudeEW.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx.format; 21 | 22 | import java.text.ParsePosition; 23 | import java.util.Optional; 24 | 25 | import io.jenetics.jpx.Longitude; 26 | 27 | /** 28 | * @author Franz Wilhelmstötter 29 | * @version 2.2 30 | * @since 1.4 31 | */ 32 | enum LongitudeEW implements Format { 33 | 34 | INSTANCE; 35 | 36 | @Override 37 | public Optional format(final Location value) { 38 | return value.longitude() 39 | .map(Longitude::toDegrees) 40 | .map(v -> Double.compare(v, 0.0) >= 0 ? "E" : "W"); 41 | } 42 | 43 | @Override 44 | public void parse( 45 | final CharSequence in, 46 | final ParsePosition pos, 47 | final LocationBuilder builder 48 | ) { 49 | final int i = pos.getIndex(); 50 | switch (in.charAt(i)) { 51 | case 'E' -> { 52 | pos.setIndex(i + 1); 53 | builder.setLongitudeSign(+1); 54 | } 55 | case 'W' -> { 56 | pos.setIndex(i + 1); 57 | builder.setLongitudeSign(-1); 58 | } 59 | default -> { 60 | pos.setErrorIndex(i); 61 | throw new ParseException("Not found E/W", in, i); 62 | } 63 | } 64 | } 65 | 66 | @Override 67 | public String toPattern() { 68 | return "x"; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/LongitudeMinute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.jenetics.jpx.format; 17 | 18 | import java.text.ParsePosition; 19 | import java.util.Optional; 20 | 21 | import io.jenetics.jpx.Longitude; 22 | 23 | /** 24 | * This field allows accessing the absolute value of the minute part of the 25 | * longitude of a given location. 26 | * 27 | * @version 2.2 28 | * @since 2.2 29 | */ 30 | final class LongitudeMinute extends Field { 31 | 32 | LongitudeMinute(final String pattern) { 33 | super(pattern, 'm'); 34 | } 35 | 36 | @Override 37 | public void parse( 38 | final CharSequence in, 39 | final ParsePosition pos, 40 | final LocationBuilder builder 41 | ) { 42 | final double d = parse(in, pos); 43 | builder.addLongitudeMinute(d); 44 | } 45 | 46 | @Override 47 | public Optional format(final Location loc) { 48 | return loc.longitude() 49 | .map(Longitude::toDegrees) 50 | .map(Field::toMinutes) 51 | .map(this::format); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/LongitudeSecond.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.jenetics.jpx.format; 17 | 18 | import java.text.ParsePosition; 19 | import java.util.Optional; 20 | 21 | import io.jenetics.jpx.Longitude; 22 | 23 | /** 24 | * This field allows accessing the absolute value of the second part of the 25 | * longitude of a given location. 26 | * 27 | * @version 2.2 28 | * @since 2.2 29 | */ 30 | final class LongitudeSecond extends Field { 31 | 32 | LongitudeSecond(final String pattern) { 33 | super(pattern, 's'); 34 | } 35 | 36 | @Override 37 | public void parse( 38 | final CharSequence in, 39 | final ParsePosition pos, 40 | final LocationBuilder builder 41 | ) { 42 | double d = parse(in, pos); 43 | builder.addLongitudeSecond(d); 44 | } 45 | 46 | @Override 47 | public Optional format(final Location loc) { 48 | return loc.longitude() 49 | .map(Longitude::toDegrees) 50 | .map(Field::toSeconds) 51 | .map(this::format); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/OptionalFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx.format; 21 | 22 | import static java.util.Objects.requireNonNull; 23 | 24 | import java.text.ParsePosition; 25 | import java.util.List; 26 | import java.util.Optional; 27 | 28 | /** 29 | * @author Franz Wilhelmstötter 30 | * @version 2.2 31 | * @since 1.4 32 | */ 33 | class OptionalFormat implements Format { 34 | 35 | private final Format _format; 36 | 37 | private OptionalFormat(final Format format) { 38 | _format = requireNonNull(format); 39 | } 40 | 41 | @Override 42 | public Optional format(final Location value) { 43 | return Optional.of(_format.format(value).orElse("")); 44 | } 45 | 46 | @Override 47 | public void parse( 48 | final CharSequence in, 49 | final ParsePosition pos, 50 | final LocationBuilder builder 51 | ) { 52 | int index = pos.getIndex(); 53 | int errorIndex = pos.getErrorIndex(); 54 | LocationBuilder before = builder.copy(); 55 | 56 | try { 57 | _format.parse(in, pos, builder); 58 | } catch (ParseException e){ 59 | builder.copy(before); 60 | pos.setIndex(index); 61 | pos.setErrorIndex(errorIndex); 62 | } 63 | } 64 | 65 | @Override 66 | public String toPattern() { 67 | return String.format("[%s]", _format.toPattern()); 68 | } 69 | 70 | static OptionalFormat of(final List formats) { 71 | return new OptionalFormat(CompositeFormat.of(formats)); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/ParseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.jenetics.jpx.format; 17 | 18 | import static java.lang.String.format; 19 | 20 | import java.io.Serial; 21 | 22 | /** 23 | * This exception is thrown when the parsing of a location pattern string fails. 24 | * 25 | * @see LocationFormatter 26 | * 27 | * @version 2.2 28 | * @since 2.2 29 | */ 30 | public class ParseException extends FormatterException { 31 | 32 | @Serial 33 | private static final long serialVersionUID = 1; 34 | 35 | /** 36 | * Create a new parse exception with the given parameters. 37 | * 38 | * @param message the error message 39 | * @param in the erroneous location string 40 | * @param position the error position 41 | */ 42 | ParseException( 43 | final String message, 44 | final CharSequence in, 45 | final int position 46 | ) { 47 | super(format("%s at position %d in '%s'.", message, position, in)); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/Plus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.jenetics.jpx.format; 17 | 18 | import java.text.ParsePosition; 19 | import java.util.Optional; 20 | 21 | /** 22 | * Just a '+' that is not participating in a field. 23 | * 24 | * @version 2.2 25 | * @since 2.2 26 | */ 27 | enum Plus implements Format { 28 | 29 | INSTANCE; 30 | 31 | @Override 32 | public Optional format(final Location value) { 33 | return Optional.of("+"); 34 | } 35 | 36 | @Override 37 | public void parse( 38 | final CharSequence in, 39 | final ParsePosition pos, 40 | final LocationBuilder builder 41 | ) { 42 | int i = pos.getIndex(); 43 | if (in.length() <= i){ 44 | pos.setErrorIndex(i); 45 | throw new ParseException("Cannot parse +", in, i); 46 | } 47 | char c = in.charAt(i); 48 | if (c != '+'){ 49 | pos.setErrorIndex(i); 50 | throw new ParseException("Wanted +, found " + c, in, i); 51 | } 52 | pos.setIndex(i + 1); 53 | } 54 | 55 | @Override 56 | public String toPattern() { 57 | return "+"; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/format/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package contains classes for formatting and parsing coordinates to and 19 | * from a ISO 6709 location 20 | * string. 21 | * 22 | * @version 2.2 23 | * @since 1.0 24 | */ 25 | package io.jenetics.jpx.format; 26 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/geom/LengthCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx.geom; 21 | 22 | import static java.util.Objects.requireNonNull; 23 | 24 | import io.jenetics.jpx.Length; 25 | import io.jenetics.jpx.Length.Unit; 26 | import io.jenetics.jpx.Point; 27 | 28 | /** 29 | * Helper class for collecting a stream of points to its length. 30 | * 31 | * @author Franz Wilhelmstötter 32 | * @version 1.0 33 | * @since 1.0 34 | */ 35 | final class LengthCollector { 36 | 37 | private final Geoid _geoid; 38 | private final DoubleAdder _length = new DoubleAdder(); 39 | 40 | private Point _first; 41 | private Point _start; 42 | 43 | LengthCollector(final Geoid geoid) { 44 | _geoid = requireNonNull(geoid); 45 | } 46 | 47 | LengthCollector combine(final LengthCollector other) { 48 | throw new UnsupportedOperationException(); 49 | } 50 | 51 | void add(final Point point) { 52 | requireNonNull(point); 53 | 54 | if (_first == null) { 55 | _first = point; 56 | } 57 | 58 | final Point end = _start; 59 | _start = point; 60 | 61 | if (end != null) { 62 | _length.add(_geoid.distance(end, _start).doubleValue()); 63 | } 64 | } 65 | 66 | Length pathLength() { 67 | return Length.of(_length.doubleValue(), Unit.METER); 68 | } 69 | 70 | Length tourLength() { 71 | if (_start != null && _first != null) { 72 | _length.add(_geoid.distance(_start, _first).doubleValue()); 73 | } 74 | return pathLength(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/geom/MathUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx.geom; 21 | 22 | import static java.lang.Double.doubleToRawLongBits; 23 | 24 | /** 25 | * Mathematical helper functions. 26 | * 27 | * @author Franz Wilhelmstötter 28 | * @version 2.1 29 | * @since 2.1 30 | */ 31 | final class MathUtils { 32 | 33 | private static final long POSITIVE_ZERO_BITS = doubleToRawLongBits(+0.0); 34 | private static final long NEGATIVE_ZERO_BITS = doubleToRawLongBits(-0.0); 35 | 36 | private MathUtils() { 37 | } 38 | 39 | /** 40 | * Returns {@code true} if the given {@code double} values are equal within 41 | * the range of allowed ULP error (inclusive). The values are considered 42 | * equal if there are maximal {@code (ulps - 1)} {@code double} values 43 | * between them. 44 | * 45 | * @param x first value to compare 46 | * @param y second value to compare 47 | * @param ulps the maximal ULP distance (epsilon) 48 | * @return {@code true} if there are fewer than {@code ulps}values between 49 | * {@code x} and {@code y}, {@code false} otherwise 50 | */ 51 | static boolean equal(final double x, final double y, final int ulps) { 52 | long a = doubleToRawLongBits(x); 53 | long b = doubleToRawLongBits(y); 54 | if (a < b) { 55 | final long t = a; a = b; b = t; 56 | } 57 | 58 | final boolean equal; 59 | if ((a ^ b) < 0) { // a and b have opposite sign. 60 | final long diffPositive = a - POSITIVE_ZERO_BITS; 61 | final long diffNegative = b - NEGATIVE_ZERO_BITS; 62 | equal = diffPositive <= ulps && diffNegative <= (ulps - diffPositive); 63 | } else { // a and b have the same sign. 64 | equal = a - b <= ulps; 65 | } 66 | 67 | return equal && !Double.isNaN(x) && !Double.isNaN(y); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/geom/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | 21 | /** 22 | * This package contains classes for calculating the distance between two 23 | * way-points. 24 | * 25 | * @author Franz Wilhelmstötter 26 | * @version 2.2 27 | * @since 1.0 28 | */ 29 | package io.jenetics.jpx.geom; 30 | -------------------------------------------------------------------------------- /jpx/src/main/java/io/jenetics/jpx/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | 21 | /** 22 | * This is the base package of the 23 | * JPX library. It contains the domain objects which are needed 24 | * for fully modeling of the 25 | * GPX standard 1.1 and 26 | * 1.0. 27 | * 28 | * @author Franz Wilhelmstötter 29 | * @version 2.2 30 | * @since 1.0 31 | */ 32 | package io.jenetics.jpx; 33 | 34 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/BoundsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import nl.jqno.equalsverifier.EqualsVerifier; 23 | 24 | import java.util.Random; 25 | import java.util.function.Supplier; 26 | import java.util.stream.Stream; 27 | 28 | import org.testng.Assert; 29 | import org.testng.annotations.Test; 30 | 31 | import io.jenetics.jpx.GPX.Version; 32 | 33 | /** 34 | * @author Franz Wilhelmstötter 35 | */ 36 | @Test 37 | public class BoundsTest extends XMLStreamTestBase { 38 | 39 | @Override 40 | public Supplier factory(Random random) { 41 | return () -> nextBounds(random); 42 | } 43 | 44 | @Override 45 | protected Params params(final Version version, final Random random) { 46 | return new Params<>( 47 | () -> nextBounds(random), 48 | Bounds.READER, 49 | Bounds.writer(Formats::format) 50 | ); 51 | } 52 | 53 | public static Bounds nextBounds(final Random random) { 54 | return Bounds.of( 55 | Latitude.ofDegrees(random.nextInt(90)), 56 | Longitude.ofDegrees(random.nextInt(90)), 57 | Latitude.ofDegrees(random.nextInt(90)), 58 | Longitude.ofDegrees(random.nextInt(90)) 59 | ); 60 | } 61 | 62 | @Test 63 | public void equalsVerifier() { 64 | EqualsVerifier.forClass(Bounds.class).verify(); 65 | } 66 | 67 | @Test 68 | public void toBounds() { 69 | final Stream points = Stream.of( 70 | WayPoint.of(50, 100), 71 | WayPoint.of(51, 101), 72 | WayPoint.of(52, 102), 73 | WayPoint.of(53, 103), 74 | WayPoint.of(54, 104), 75 | WayPoint.of(55, 105) 76 | ); 77 | 78 | final Bounds bounds = points.collect(Bounds.toBounds()); 79 | Assert.assertEquals( 80 | bounds, 81 | Bounds.of( 82 | Latitude.ofDegrees(50), Longitude.ofDegrees(100), 83 | Latitude.ofDegrees(55), Longitude.ofDegrees(105) 84 | ) 85 | ); 86 | } 87 | 88 | // https://github.com/jenetics/jpx/issues/110 89 | @Test 90 | public void toBoundsNegativeValues() { 91 | final Stream points = Stream.of( 92 | WayPoint.of(-50, -100), 93 | WayPoint.of(-51, -101), 94 | WayPoint.of(-52, -102), 95 | WayPoint.of(-53, -103), 96 | WayPoint.of(-54, -104), 97 | WayPoint.of(-55, -105) 98 | ); 99 | 100 | final Bounds bounds = points.collect(Bounds.toBounds()); 101 | Assert.assertEquals( 102 | bounds, 103 | Bounds.of( 104 | Latitude.ofDegrees(-55), Longitude.ofDegrees(-105), 105 | Latitude.ofDegrees(-50), Longitude.ofDegrees(-100) 106 | ) 107 | ); 108 | } 109 | 110 | @Test 111 | public void toBoundsForOnePoints() { 112 | final Stream points = Stream.of( 113 | WayPoint.of(50, 100) 114 | ); 115 | 116 | final Bounds bounds = points.collect(Bounds.toBounds()); 117 | System.out.println(bounds); 118 | Assert.assertEquals( 119 | bounds, 120 | Bounds.of( 121 | Latitude.ofDegrees(50), Longitude.ofDegrees(100), 122 | Latitude.ofDegrees(50), Longitude.ofDegrees(100) 123 | ) 124 | ); 125 | } 126 | 127 | @Test 128 | public void toBoundsForZeroPoints() { 129 | final Stream points = Stream.empty(); 130 | final Bounds bounds = points.collect(Bounds.toBounds()); 131 | Assert.assertNull(bounds); 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/CopyrightTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static java.lang.String.format; 23 | import static io.jenetics.jpx.Format.parseURI; 24 | 25 | import nl.jqno.equalsverifier.EqualsVerifier; 26 | 27 | import java.net.URI; 28 | import java.time.Year; 29 | import java.util.Random; 30 | import java.util.function.Supplier; 31 | 32 | import org.testng.annotations.Test; 33 | 34 | import io.jenetics.jpx.GPX.Version; 35 | 36 | /** 37 | * @author Franz Wilhelmstötter 38 | */ 39 | @Test 40 | public class CopyrightTest extends XMLStreamTestBase { 41 | 42 | @Override 43 | public Supplier factory(Random random) { 44 | return () -> nextCopyright(random); 45 | } 46 | 47 | @Override 48 | protected Params params(final Version version, final Random random) { 49 | return new Params<>( 50 | () -> nextCopyright(random), 51 | Copyright.READER, 52 | Copyright.WRITER 53 | ); 54 | } 55 | 56 | private static URI uri(final Random random) { 57 | return parseURI(format("http://uri.com/%s", random.nextInt(100))); 58 | } 59 | 60 | public static Copyright nextCopyright(final Random random) { 61 | return Copyright.of( 62 | format("author_%s", random.nextInt(100)), 63 | random.nextBoolean() 64 | ? Year.of(random.nextInt(1000)) 65 | : null, 66 | random.nextBoolean() 67 | ? uri(random) 68 | : null 69 | ); 70 | } 71 | 72 | @Test 73 | public void nullURIString() { 74 | Copyright.of("author", 23, (String)null); 75 | } 76 | 77 | @Test 78 | public void equalsVerifier() { 79 | EqualsVerifier.forClass(Copyright.class).verify(); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/DGPSStationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import nl.jqno.equalsverifier.EqualsVerifier; 23 | 24 | import java.util.Random; 25 | import java.util.function.Supplier; 26 | 27 | import org.testng.annotations.Test; 28 | 29 | /** 30 | * @author Franz Wilhelmstötter 31 | */ 32 | @Test 33 | public class DGPSStationTest extends ObjectTester { 34 | 35 | @Override 36 | Supplier factory(final Random random) { 37 | return () -> DGPSStation.of(random.nextInt(1023)); 38 | } 39 | 40 | @Test 41 | public void equalsVerifier() { 42 | EqualsVerifier.forClass(DGPSStation.class).verify(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/DegreesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import nl.jqno.equalsverifier.EqualsVerifier; 23 | 24 | import java.util.Random; 25 | import java.util.function.Supplier; 26 | 27 | import org.testng.Assert; 28 | import org.testng.annotations.Test; 29 | 30 | /** 31 | * @author Franz Wilhelmstötter 32 | */ 33 | @Test 34 | public class DegreesTest extends ObjectTester { 35 | 36 | private static final double EPSILON = 0.000000000000001; 37 | 38 | @Override 39 | Supplier factory(final Random random) { 40 | return () -> Degrees.ofDegrees(random.nextDouble()); 41 | } 42 | 43 | @Test 44 | public void ofRadians() { 45 | Assert.assertEquals( 46 | Degrees.ofRadians(3), 47 | Degrees.ofDegrees(Math.toDegrees(3)) 48 | ); 49 | 50 | Assert.assertEquals( 51 | Degrees.ofRadians(3).toRadians(), 52 | Degrees.ofDegrees(Math.toDegrees(3)).toRadians() 53 | ); 54 | } 55 | 56 | @Test 57 | public void ofDegrees() { 58 | Assert.assertEquals( 59 | Degrees.ofDegrees(3).doubleValue(), 60 | Degrees.ofRadians(Math.toRadians(3)).doubleValue(), 61 | EPSILON 62 | ); 63 | 64 | Assert.assertEquals( 65 | Degrees.ofDegrees(3).toDegrees(), 66 | Degrees.ofRadians(Math.toRadians(3)).toDegrees(), 67 | EPSILON 68 | ); 69 | } 70 | 71 | @Test 72 | public void equalsVerifier() { 73 | EqualsVerifier.forClass(Degrees.class).verify(); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/EmailTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static java.lang.String.format; 23 | 24 | import nl.jqno.equalsverifier.EqualsVerifier; 25 | 26 | import java.util.Random; 27 | import java.util.function.Supplier; 28 | 29 | import org.testng.Assert; 30 | import org.testng.annotations.Test; 31 | 32 | import io.jenetics.jpx.GPX.Version; 33 | 34 | /** 35 | * @author Franz Wilhelmstötter 36 | */ 37 | @Test 38 | public class EmailTest extends XMLStreamTestBase { 39 | 40 | @Override 41 | public Supplier factory(Random random) { 42 | return () -> nextEmail(random); 43 | } 44 | 45 | @Override 46 | protected Params params(final Version version, final Random random) { 47 | return new Params<>( 48 | () -> nextEmail(random), 49 | Email.READER, 50 | Email.WRITER 51 | ); 52 | } 53 | 54 | public static Email nextEmail(final Random random) { 55 | return Email.of( 56 | format("id_%s", random.nextInt(100)), 57 | format("domain_%s", random.nextInt(100)) 58 | ); 59 | } 60 | 61 | @Test(expectedExceptions = IllegalArgumentException.class) 62 | public void fromEmptyAddress() { 63 | Email.of(""); 64 | } 65 | 66 | @Test(expectedExceptions = IllegalArgumentException.class) 67 | public void fromShortAddress1() { 68 | Email.of("@"); 69 | } 70 | 71 | @Test(expectedExceptions = IllegalArgumentException.class) 72 | public void fromShortAddress2() { 73 | Email.of("a@"); 74 | } 75 | 76 | @Test(expectedExceptions = IllegalArgumentException.class) 77 | public void fromShortAddress3() { 78 | Email.of("@b"); 79 | } 80 | 81 | @Test 82 | public void fromAddress() { 83 | Assert.assertEquals( 84 | Email.of("a@b"), 85 | Email.of("a", "b") 86 | ); 87 | } 88 | 89 | @Test 90 | public void equalsVerifier() { 91 | EqualsVerifier.forClass(Email.class).verify(); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/FiltersTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static io.jenetics.jpx.GPXTest.nextGPX; 23 | import static io.jenetics.jpx.TrackTest.nextTrack; 24 | 25 | import java.io.ByteArrayInputStream; 26 | import java.io.IOException; 27 | import java.util.Random; 28 | 29 | import org.testng.Assert; 30 | import org.testng.annotations.Test; 31 | 32 | /** 33 | * @author Franz Wilhelmstötter 34 | */ 35 | public class FiltersTest { 36 | 37 | @Test 38 | public void mergeSegments() { 39 | final GPX gpx = nextGPX(new Random(1)); 40 | 41 | final GPX merged = gpx.toBuilder() 42 | .trackFilter() 43 | .map(track -> track.toBuilder() 44 | .listMap(Filters::mergeSegments) 45 | .filter(TrackSegment::nonEmpty) 46 | .build()) 47 | .build() 48 | .build(); 49 | 50 | for (Track track : merged.getTracks()) { 51 | Assert.assertEquals(track.getSegments().size(), 1); 52 | } 53 | } 54 | 55 | @Test 56 | public void mergeTracks() { 57 | final GPX gpx = nextGPX(new Random(1)).toBuilder() 58 | .addTrack(nextTrack(new Random(2))) 59 | .addTrack(nextTrack(new Random(3))) 60 | .addTrack(nextTrack(new Random(4))) 61 | .build(); 62 | 63 | final GPX merged = gpx.toBuilder() 64 | .trackFilter() 65 | .listMap(Filters::mergeTracks) 66 | .filter(Track::nonEmpty) 67 | .build() 68 | .build(); 69 | 70 | Assert.assertEquals(merged.getTracks().size(), 1); 71 | 72 | final int segments = merged.getTracks().stream() 73 | .mapToInt(t -> t.getSegments().size()) 74 | .sum(); 75 | 76 | Assert.assertEquals(segments, 38); 77 | } 78 | 79 | @Test 80 | public void fullyMergeTracks() { 81 | final GPX gpx = nextGPX(new Random(1)).toBuilder() 82 | .addTrack(nextTrack(new Random(2))) 83 | .addTrack(nextTrack(new Random(3))) 84 | .addTrack(nextTrack(new Random(4))) 85 | .build(); 86 | 87 | final GPX merged = gpx.toBuilder() 88 | .trackFilter() 89 | .listMap(Filters::fullyMergeTracks) 90 | .filter(Track::nonEmpty) 91 | .build() 92 | .build(); 93 | 94 | Assert.assertEquals(merged.getTracks().size(), 1); 95 | 96 | final int segments = merged.getTracks().stream() 97 | .mapToInt(t -> t.getSegments().size()) 98 | .sum(); 99 | 100 | Assert.assertEquals(segments, 1); 101 | } 102 | 103 | @Test 104 | public void nonEmptyFilter() throws IOException { 105 | final GPX gpx = GPX.Reader.DEFAULT.read(new ByteArrayInputStream((""" 106 | 107 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 12.0 118 | 119 | 120 | 121 | 122 | """).getBytes())); 123 | 124 | final GPX nonEmpty = Filters.nonEmptyGPX(gpx); 125 | 126 | final GPX expected = GPX.builder() 127 | .addTrack(track -> track 128 | .addSegment(segment -> segment 129 | .addPoint(wp -> wp.lat(21.0).lon(23.0).ele(12.0)))) 130 | .build(); 131 | 132 | Assert.assertEquals(nonEmpty, expected); 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/FixTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import nl.jqno.equalsverifier.EqualsVerifier; 23 | 24 | import java.util.Random; 25 | import java.util.function.Supplier; 26 | 27 | import org.testng.annotations.Test; 28 | 29 | /** 30 | * @author Franz Wilhelmstötter 31 | */ 32 | @Test 33 | public class FixTest extends ObjectTester { 34 | 35 | @Override 36 | Supplier factory(final Random random) { 37 | return () -> Fix.values()[random.nextInt(Fix.values().length)]; 38 | } 39 | 40 | @Test 41 | public void equalsVerifier() { 42 | EqualsVerifier.forClass(Fix.class).verify(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/Formats.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import java.text.NumberFormat; 23 | import java.util.Locale; 24 | 25 | /** 26 | * @author Franz Wilhelmstötter 27 | */ 28 | final class Formats { 29 | 30 | private static final NumberFormat FORMAT = 31 | NumberFormat.getNumberInstance(Locale.ENGLISH); 32 | static { 33 | FORMAT.setMaximumFractionDigits(20); 34 | } 35 | 36 | private Formats() { 37 | } 38 | 39 | static String format(final Number value) { 40 | return value != null ? FORMAT.format(value) : null; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/IOTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import java.io.ByteArrayInputStream; 23 | import java.io.ByteArrayOutputStream; 24 | import java.io.DataInputStream; 25 | import java.io.DataOutputStream; 26 | import java.io.IOException; 27 | import java.util.Random; 28 | 29 | import org.testng.Assert; 30 | import org.testng.annotations.Test; 31 | import org.w3c.dom.Document; 32 | 33 | /** 34 | * @author Franz Wilhelmstötter 35 | */ 36 | public class IOTest { 37 | 38 | @Test 39 | public void readWriteInt() throws IOException { 40 | final Random random = new Random(); 41 | for (int i = 0; i < 1000; ++i) { 42 | final int value = random.nextInt(); 43 | 44 | final ByteArrayOutputStream bout = new ByteArrayOutputStream(5); 45 | final DataOutputStream dout = new DataOutputStream(bout); 46 | IO.writeInt(value, dout); 47 | dout.flush(); 48 | 49 | final ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); 50 | final DataInputStream din = new DataInputStream(bin); 51 | final int read = IO.readInt(din); 52 | 53 | Assert.assertEquals(read, value); 54 | } 55 | } 56 | 57 | @Test 58 | public void readWriteLong() throws IOException { 59 | final Random random = new Random(); 60 | for (int i = 0; i < 1000; ++i) { 61 | final long value = random.nextLong(); 62 | 63 | final ByteArrayOutputStream bout = new ByteArrayOutputStream(9); 64 | final DataOutputStream dout = new DataOutputStream(bout); 65 | IO.writeLong(value, dout); 66 | dout.flush(); 67 | 68 | final ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); 69 | final DataInputStream din = new DataInputStream(bin); 70 | final long read = IO.readLong(din); 71 | 72 | Assert.assertEquals(read, value); 73 | } 74 | } 75 | 76 | @Test 77 | public void readWriteDoc() throws IOException { 78 | final Document value = GPXTest.doc(); 79 | 80 | final ByteArrayOutputStream bout = new ByteArrayOutputStream(9); 81 | final DataOutputStream dout = new DataOutputStream(bout); 82 | IO.write(value, dout); 83 | dout.flush(); 84 | 85 | final ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); 86 | final DataInputStream din = new DataInputStream(bin); 87 | final Document read = IO.readDoc(din); 88 | 89 | Assert.assertTrue(XML.equals(value, read)); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/LatitudeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import nl.jqno.equalsverifier.EqualsVerifier; 23 | 24 | import java.util.Random; 25 | import java.util.function.Supplier; 26 | 27 | import org.testng.Assert; 28 | import org.testng.annotations.Test; 29 | 30 | /** 31 | * @author Franz Wilhelmstötter 32 | */ 33 | @Test 34 | public class LatitudeTest extends ObjectTester { 35 | 36 | @Override 37 | Supplier factory(final Random random) { 38 | return () -> Latitude.ofRadians(random.nextDouble()); 39 | } 40 | 41 | @Test 42 | public void ofRadians() { 43 | Assert.assertEquals( 44 | Latitude.ofRadians(1), 45 | Latitude.ofDegrees(Math.toDegrees(1)) 46 | ); 47 | 48 | Assert.assertEquals( 49 | Latitude.ofRadians(1).toRadians(), 50 | Latitude.ofDegrees(Math.toDegrees(1)).toRadians() 51 | ); 52 | } 53 | 54 | @Test 55 | public void ofDegrees() { 56 | Assert.assertEquals( 57 | Latitude.ofDegrees(1), 58 | Latitude.ofRadians(Math.toRadians(1)) 59 | ); 60 | 61 | Assert.assertEquals( 62 | Latitude.ofDegrees(1).toDegrees(), 63 | Latitude.ofRadians(Math.toRadians(1)).toDegrees() 64 | ); 65 | } 66 | 67 | @Test 68 | public void equalsVerifier() { 69 | EqualsVerifier.forClass(Latitude.class).verify(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/LengthTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import nl.jqno.equalsverifier.EqualsVerifier; 23 | 24 | import java.util.Random; 25 | import java.util.function.Supplier; 26 | 27 | import org.testng.Assert; 28 | import org.testng.annotations.DataProvider; 29 | import org.testng.annotations.Test; 30 | 31 | import io.jenetics.jpx.Length.Unit; 32 | 33 | /** 34 | * @author Franz Wilhelmstötter 35 | */ 36 | @Test 37 | public class LengthTest extends ObjectTester { 38 | 39 | @Override 40 | Supplier factory(final Random random) { 41 | return () -> Length.of(random.nextInt(12)*random.nextDouble(),Unit.METER); 42 | } 43 | 44 | @Test 45 | public void ofMeters() { 46 | Assert.assertEquals( 47 | Length.of(123, Unit.METER), 48 | Length.of(0.123, Unit.KILOMETER) 49 | ); 50 | 51 | Assert.assertEquals( 52 | Length.of(123, Unit.METER).to(Unit.METER), 53 | Length.of(0.123, Unit.KILOMETER).to(Unit.METER) 54 | ); 55 | } 56 | 57 | @Test 58 | public void ofKiloMeters() { 59 | Assert.assertEquals( 60 | Length.of(0.123, Unit.KILOMETER), 61 | Length.of(123, Unit.METER) 62 | ); 63 | 64 | Assert.assertEquals( 65 | Length.of(0.123, Unit.KILOMETER).to(Unit.KILOMETER), 66 | Length.of(123, Unit.METER).to(Unit.KILOMETER) 67 | ); 68 | } 69 | 70 | @Test(dataProvider = "toConversions") 71 | public void toMeter(final Unit unit, final double value) { 72 | final Length length = Length.of(1, unit); 73 | Assert.assertEquals(value, length.to(Unit.METER)); 74 | } 75 | 76 | @DataProvider(name = "toConversions") 77 | public Object[][] toConversions() { 78 | return new Object[][] { 79 | {Unit.METER, 1}, 80 | {Unit.KILOMETER, 1000}, 81 | {Unit.INCH, 0.0254}, 82 | {Unit.MILE, 1_609.344}, 83 | {Unit.YARD, 0.9144} 84 | }; 85 | } 86 | 87 | @Test 88 | public void equalsVerifier() { 89 | EqualsVerifier.forClass(Length.class).verify(); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/LinkTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static java.lang.String.format; 23 | 24 | import nl.jqno.equalsverifier.EqualsVerifier; 25 | 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | import java.util.Random; 29 | import java.util.function.Supplier; 30 | 31 | import org.testng.annotations.Test; 32 | 33 | import io.jenetics.jpx.GPX.Version; 34 | 35 | /** 36 | * @author Franz Wilhelmstötter 37 | */ 38 | @Test 39 | public class LinkTest extends XMLStreamTestBase { 40 | 41 | @Override 42 | public Supplier factory(Random random) { 43 | return () -> nextLink(random); 44 | } 45 | 46 | @Override 47 | protected Params params(final Version version, final Random random) { 48 | return new Params<>( 49 | () -> nextLink(random), 50 | Link.READER, 51 | Link.WRITER 52 | ); 53 | } 54 | 55 | public static Link nextLink(final Random random) { 56 | return Link.of( 57 | format("http://link_%d", random.nextInt(100)), 58 | random.nextBoolean() 59 | ? format("text_%s", random.nextInt(100)) 60 | : null, 61 | random.nextBoolean() 62 | ? format("type_%s", random.nextInt(100)) 63 | : null 64 | ); 65 | } 66 | 67 | public static List nextLinks(final Random random) { 68 | final List links = new ArrayList<>(); 69 | for (int i = 0, n = random.nextInt(20); i < n; ++i) { 70 | links.add(LinkTest.nextLink(random)); 71 | } 72 | 73 | return links; 74 | } 75 | 76 | @Test 77 | public void equalsVerifier() { 78 | EqualsVerifier.forClass(Link.class).verify(); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/ListsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | /** 26 | * @author Franz Wilhelmstötter 27 | */ 28 | public class ListsTest { 29 | 30 | static List revert(final List list) { 31 | final List result = new ArrayList(list.size()); 32 | for (int i = 0, n = list.size(); i < n; ++i) { 33 | result.add(list.get(n - i - 1)); 34 | } 35 | return result; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/LongitudeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static java.lang.Double.doubleToLongBits; 23 | import static java.lang.Double.longBitsToDouble; 24 | 25 | import nl.jqno.equalsverifier.EqualsVerifier; 26 | 27 | import java.util.Random; 28 | import java.util.function.Supplier; 29 | 30 | import org.testng.Assert; 31 | import org.testng.annotations.Test; 32 | 33 | /** 34 | * @author Franz Wilhelmstötter 35 | */ 36 | @Test 37 | public class LongitudeTest extends ObjectTester { 38 | 39 | @Override 40 | Supplier factory(final Random random) { 41 | return () -> Longitude.ofRadians(random.nextDouble()); 42 | } 43 | 44 | @Test 45 | public void ofRadians() { 46 | Assert.assertEquals( 47 | Longitude.ofRadians(1), 48 | Longitude.ofDegrees(Math.toDegrees(1)) 49 | ); 50 | 51 | Assert.assertEquals( 52 | Longitude.ofRadians(1).toRadians(), 53 | Longitude.ofDegrees(Math.toDegrees(1)).toRadians() 54 | ); 55 | 56 | Assert.assertEquals( 57 | Longitude.ofRadians(excl(Math.PI)).toRadians(), 58 | Longitude.ofDegrees(Math.toDegrees(excl(Math.PI))).toRadians() 59 | ); 60 | } 61 | 62 | static double excl(final double value) { 63 | return longBitsToDouble(doubleToLongBits(value) - 1); 64 | } 65 | 66 | @Test 67 | public void ofDegrees() { 68 | Assert.assertEquals( 69 | Longitude.ofDegrees(1), 70 | Longitude.ofRadians(Math.toRadians(1)) 71 | ); 72 | 73 | Assert.assertEquals( 74 | Longitude.ofDegrees(1).toDegrees(), 75 | Longitude.ofRadians(Math.toRadians(1)).toDegrees() 76 | ); 77 | } 78 | 79 | @Test 80 | public void equalsVerifier() { 81 | EqualsVerifier.forClass(Longitude.class).verify(); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/MetadataTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static java.lang.String.format; 23 | import static io.jenetics.jpx.ZonedDateTimesTest.nextZonedDataTime; 24 | 25 | import nl.jqno.equalsverifier.EqualsVerifier; 26 | 27 | import java.io.IOException; 28 | import java.io.InputStream; 29 | import java.util.Random; 30 | import java.util.function.Supplier; 31 | 32 | import org.testng.Assert; 33 | import org.testng.annotations.Test; 34 | 35 | import io.jenetics.jpx.GPX.Version; 36 | 37 | /** 38 | * @author Franz Wilhelmstötter 39 | */ 40 | @Test 41 | public class MetadataTest extends XMLStreamTestBase { 42 | 43 | @Override 44 | public Supplier factory(Random random) { 45 | return () -> nextMetadata(random); 46 | } 47 | 48 | @Override 49 | protected Params params(final Version version, final Random random) { 50 | return new Params<>( 51 | () -> nextMetadata(random), 52 | Metadata.READER, 53 | Metadata.writer(Formats::format) 54 | ); 55 | } 56 | 57 | public static Metadata nextMetadata(final Random random) { 58 | return Metadata.of( 59 | random.nextBoolean() 60 | ? format("name_%s", random.nextInt(100)) 61 | : null, 62 | random.nextBoolean() 63 | ? format("description_%s", random.nextInt(100)) 64 | : null, 65 | random.nextBoolean() 66 | ? PersonTest.nextPerson(random) 67 | : null, 68 | random.nextBoolean() 69 | ? CopyrightTest.nextCopyright(random) 70 | : null, 71 | LinkTest.nextLinks(random), 72 | random.nextBoolean() 73 | ? nextZonedDataTime(random) 74 | : null, 75 | random.nextBoolean() 76 | ? format("keywords_%s", random.nextInt(100)) 77 | : null, 78 | random.nextBoolean() 79 | ? BoundsTest.nextBounds(random) 80 | : null 81 | ); 82 | } 83 | 84 | @Test 85 | public void builder() { 86 | final Metadata metadata = Metadata.builder() 87 | .author("Franz Wilhelmstötter") 88 | .addLink(Link.of("http://jenetics.io/jpx")) 89 | .build(); 90 | 91 | Assert.assertNotNull(metadata); 92 | } 93 | 94 | @Test 95 | public void toBuilder() { 96 | final Metadata metadata = Metadata.builder() 97 | .author("Franz Wilhelmstötter") 98 | .addLink(Link.of("http://jenetics.io/jpx")) 99 | .build(); 100 | 101 | Assert.assertEquals( 102 | metadata.toBuilder().build(), 103 | metadata 104 | ); 105 | Assert.assertNotEquals( 106 | System.identityHashCode(metadata.toBuilder().build()), 107 | System.identityHashCode(metadata) 108 | ); 109 | } 110 | 111 | @Test 112 | public void withExtensions() throws IOException { 113 | final String resource = "/io/jenetics/jpx/extensions-metadata.gpx"; 114 | 115 | final GPX gpx; 116 | try (InputStream in = getClass().getResourceAsStream(resource)) { 117 | gpx = GPX.Reader.DEFAULT.read(in); 118 | } 119 | 120 | final Metadata md = gpx.getMetadata().get(); 121 | Assert.assertEquals( 122 | md, 123 | Metadata.builder() 124 | .name("Name of GPX") 125 | .author( 126 | Person.of( 127 | "Name of Author/Person", 128 | null, 129 | Link.of( 130 | "http://author.net", 131 | "Link of Author/Person", 132 | null))) 133 | .addLink(Link.of( 134 | "http://company.net", 135 | "Link of GPX", 136 | null)) 137 | .build() 138 | ); 139 | 140 | Assert.assertTrue(XML.equals( 141 | md.getExtensions().get(), 142 | XML.parse("asdfasdf") 143 | )); 144 | } 145 | 146 | @Test 147 | public void equalsVerifier() { 148 | EqualsVerifier.forClass(Metadata.class) 149 | .withIgnoredFields("_extensions") 150 | .verify(); 151 | } 152 | 153 | @Test(invocationCount = 10) 154 | public void serialize() throws IOException, ClassNotFoundException { 155 | final Object object = nextMetadata(new Random()); 156 | Serialization.test(object); 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/PersonTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static java.lang.String.format; 23 | 24 | import nl.jqno.equalsverifier.EqualsVerifier; 25 | 26 | import java.util.Random; 27 | import java.util.function.Supplier; 28 | 29 | import org.testng.annotations.Test; 30 | 31 | import io.jenetics.jpx.GPX.Version; 32 | 33 | /** 34 | * @author Franz Wilhelmstötter 35 | */ 36 | @Test 37 | public class PersonTest extends XMLStreamTestBase { 38 | 39 | @Override 40 | public Supplier factory(Random random) { 41 | return () -> nextPerson(random); 42 | } 43 | 44 | @Override 45 | protected Params params(final Version version, final Random random) { 46 | return new Params<>( 47 | () -> nextPerson(random), 48 | Person.reader("author"), 49 | Person.writer("author") 50 | ); 51 | } 52 | 53 | public static Person nextPerson(final Random random) { 54 | return Person.of( 55 | random.nextBoolean() 56 | ? format("name_%s", random.nextInt(100)) 57 | : null, 58 | random.nextBoolean() 59 | ? EmailTest.nextEmail(random) 60 | : null, 61 | random.nextBoolean() 62 | ? LinkTest.nextLink(random) 63 | : null 64 | ); 65 | } 66 | 67 | @Test 68 | public void equalsVerifier() { 69 | EqualsVerifier.forClass(Person.class).verify(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/Serialization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import java.io.ByteArrayInputStream; 23 | import java.io.ByteArrayOutputStream; 24 | import java.io.IOException; 25 | import java.io.ObjectInputStream; 26 | import java.io.ObjectOutputStream; 27 | 28 | import org.testng.Assert; 29 | 30 | /** 31 | * @author Franz Wilhelmstötter 32 | */ 33 | public class Serialization { 34 | 35 | private Serialization() { 36 | } 37 | 38 | public static void test(final Object object) 39 | throws IOException, ClassNotFoundException 40 | { 41 | final ByteArrayOutputStream bout = new ByteArrayOutputStream(); 42 | try (ObjectOutputStream oout = new ObjectOutputStream(bout)) { 43 | oout.writeObject(object); 44 | } 45 | 46 | final byte[] data = bout.toByteArray(); 47 | //System.out.println("Length: " + data.length); 48 | final ByteArrayInputStream bin = new ByteArrayInputStream(data); 49 | try (ObjectInputStream oin = new ObjectInputStream(bin)) { 50 | final Object obj = oin.readObject(); 51 | Assert.assertEquals(obj, object); 52 | } 53 | } 54 | 55 | static byte[] toBytes(final Object... objects) throws IOException { 56 | int existing = 0; 57 | for (int i = 0; i < objects.length; ++i) { 58 | if (objects[i] != null) { 59 | existing |= 1 << i; 60 | } 61 | } 62 | 63 | final ByteArrayOutputStream bout = new ByteArrayOutputStream(); 64 | try (ObjectOutputStream oout = new ObjectOutputStream(bout)) { 65 | oout.writeInt(objects.length); 66 | oout.writeInt(existing); 67 | for (Object object : objects) { 68 | if (object != null) { 69 | oout.writeObject(object); 70 | } 71 | } 72 | } 73 | 74 | return bout.toByteArray(); 75 | } 76 | 77 | static Object[] fromBytes(final byte[] data) throws IOException, ClassNotFoundException { 78 | final ByteArrayInputStream bin = new ByteArrayInputStream(data); 79 | try (ObjectInputStream oin = new ObjectInputStream(bin)) { 80 | final int length = oin.readInt(); 81 | final int existing = oin.readInt(); 82 | 83 | final Object[] objects = new Object[length]; 84 | for (int i = 0; i < length; ++i) { 85 | final boolean exists = (existing & 1 << i) != 0; 86 | if (exists) { 87 | objects[i] = oin.readObject(); 88 | } 89 | } 90 | 91 | return objects; 92 | } 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/SpeedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import nl.jqno.equalsverifier.EqualsVerifier; 23 | 24 | import java.util.Random; 25 | import java.util.function.Supplier; 26 | 27 | import org.testng.Assert; 28 | import org.testng.annotations.DataProvider; 29 | import org.testng.annotations.Test; 30 | 31 | import io.jenetics.jpx.Speed.Unit; 32 | 33 | /** 34 | * @author Franz Wilhelmstötter 35 | */ 36 | @Test 37 | public class SpeedTest extends ObjectTester { 38 | 39 | @Override 40 | Supplier factory(final Random random) { 41 | return () -> Speed.of(random.nextDouble(), Unit.METERS_PER_SECOND); 42 | } 43 | 44 | @Test 45 | public void units() { 46 | Assert.assertEquals( 47 | 0.2777777777777778, 48 | Unit.METERS_PER_SECOND.convert(1, Unit.KILOMETERS_PER_HOUR) 49 | ); 50 | 51 | Assert.assertEquals( 52 | 0.5144444444444445, 53 | Unit.METERS_PER_SECOND.convert(1, Unit.KNOTS) 54 | ); 55 | 56 | Assert.assertEquals( 57 | 331.3, 58 | Unit.METERS_PER_SECOND.convert(1, Unit.MACH) 59 | ); 60 | 61 | Assert.assertEquals( 62 | 0.44704, 63 | Unit.METERS_PER_SECOND.convert(1, Unit.MILES_PER_HOUR) 64 | ); 65 | } 66 | 67 | @Test(dataProvider = "toConversions") 68 | public void toMetersPerSecond(final Speed.Unit unit, final double value) { 69 | final Speed speed = Speed.of(1, unit); 70 | Assert.assertEquals(value, speed.to(Unit.METERS_PER_SECOND)); 71 | } 72 | 73 | @DataProvider(name = "toConversions") 74 | public Object[][] toConversions() { 75 | return new Object[][] { 76 | {Unit.METERS_PER_SECOND, 1}, 77 | {Unit.KILOMETERS_PER_HOUR, 0.2777777777777778}, 78 | {Unit.KNOTS, 0.5144444444444445}, 79 | {Unit.MILES_PER_HOUR, 0.44704}, 80 | {Unit.MACH, 331.3} 81 | }; 82 | } 83 | 84 | @Test 85 | public void equalsVerifier() { 86 | EqualsVerifier.forClass(Speed.class).verify(); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/TimeFormatTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import static org.assertj.core.api.Assertions.assertThat; 23 | 24 | import java.time.Instant; 25 | 26 | import org.testng.Assert; 27 | import org.testng.annotations.DataProvider; 28 | import org.testng.annotations.Test; 29 | 30 | /** 31 | * @author Franz Wilhelmstötter 32 | */ 33 | public class TimeFormatTest { 34 | 35 | @Test(dataProvider = "validExamples") 36 | public void parseExample(final String example) { 37 | final TimeFormat format = TimeFormat 38 | .findFormat(example); 39 | 40 | assertThat(format).isNotNull(); 41 | 42 | final Instant zdt = format.formatParse(example); 43 | final String zdts = TimeFormat.format(zdt); 44 | Assert.assertEquals( 45 | TimeFormat 46 | .parseOptional(zdts) 47 | .orElse(Instant.MIN), 48 | zdt 49 | ); 50 | } 51 | 52 | @DataProvider(name = "validExamples") 53 | public Object[][] validExamples() { 54 | return new Object[][] { 55 | {"2001-10-26T21:32:52"}, 56 | {"2001-10-26T21:32:52.1"}, 57 | {"2001-10-26T21:32:52.12"}, 58 | {"2001-10-26T21:32:52.123"}, 59 | {"2001-10-26T21:32:52.1234"}, 60 | {"2001-10-26T21:32:52.12345"}, 61 | {"2001-10-26T21:32:52.1234567"}, 62 | {"2001-10-26T21:32:52.12345678"}, 63 | {"2001-10-26T21:32:52.123456789"}, 64 | 65 | {"2001-10-26T21:32:52Z"}, 66 | {"2001-10-26T21:32:52.1Z"}, 67 | {"2001-10-26T21:32:52.12Z"}, 68 | {"2001-10-26T21:32:52.123Z"}, 69 | {"2001-10-26T21:32:52.1234Z"}, 70 | {"2001-10-26T21:32:52.12345Z"}, 71 | {"2001-10-26T21:32:52.1234567Z"}, 72 | {"2001-10-26T21:32:52.12345678Z"}, 73 | {"2001-10-26T21:32:52.123456789Z"}, 74 | 75 | {"2001-10-26T19:32:52-01:00"}, 76 | {"2001-10-26T19:32:52.1-01:00"}, 77 | {"2001-10-26T19:32:52.12-01:00"}, 78 | {"2001-10-26T19:32:52.123-01:00"}, 79 | {"2001-10-26T19:32:52.1234-01:00"}, 80 | {"2001-10-26T19:32:52.12345-01:00"}, 81 | {"2001-10-26T19:32:52.123456-01:00"}, 82 | {"2001-10-26T19:32:52.1234567-01:00"}, 83 | {"2001-10-26T19:32:52.12345678-01:00"}, 84 | {"2001-10-26T19:32:52.123456789-01:00"}, 85 | 86 | {"2001-10-26T19:32:52+00:00"}, 87 | {"2001-10-26T19:32:52.1+00:00"}, 88 | {"2001-10-26T19:32:52.12+00:00"}, 89 | {"2001-10-26T19:32:52.123+00:00"}, 90 | {"2001-10-26T19:32:52.1234+00:00"}, 91 | {"2001-10-26T19:32:52.12345+00:00"}, 92 | {"2001-10-26T19:32:52.123456+00:00"}, 93 | {"2001-10-26T19:32:52.1234567+00:00"}, 94 | {"2001-10-26T19:32:52.12345678+00:00"}, 95 | {"2001-10-26T19:32:52.123456789+00:00"}, 96 | 97 | {"2001-10-26T19:32:52+05:00"}, 98 | {"2001-10-26T19:32:52.1+05:00"}, 99 | {"2001-10-26T19:32:52.12+05:00"}, 100 | {"2001-10-26T19:32:52.123+05:00"}, 101 | {"2001-10-26T19:32:52.1234+05:00"}, 102 | {"2001-10-26T19:32:52.12345+05:00"}, 103 | {"2001-10-26T19:32:52.123456+05:00"}, 104 | {"2001-10-26T19:32:52.1234567+05:00"}, 105 | {"2001-10-26T19:32:52.12345678+05:00"}, 106 | {"2001-10-26T19:32:52.123456789+05:00"} 107 | }; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/UIntTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import nl.jqno.equalsverifier.EqualsVerifier; 23 | 24 | import java.util.Random; 25 | import java.util.function.Supplier; 26 | 27 | import org.testng.annotations.Test; 28 | 29 | /** 30 | * @author Franz Wilhelmstötter 31 | */ 32 | @Test 33 | public class UIntTest extends ObjectTester { 34 | 35 | @Override 36 | Supplier factory(final Random random) { 37 | return () -> UInt.of(Math.abs(random.nextInt())); 38 | } 39 | 40 | @Test 41 | public void equalsVerifier() { 42 | EqualsVerifier.forClass(UInt.class).verify(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/XMLProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Antoine Vianey (github.com/avianey) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import java.io.File; 23 | import java.io.IOException; 24 | import java.net.URL; 25 | import java.util.Enumeration; 26 | 27 | import javax.xml.parsers.DocumentBuilderFactory; 28 | 29 | import org.testng.annotations.Test; 30 | 31 | public class XMLProviderTest { 32 | 33 | public static final String MESSAGE = "provider does not support documentBuilderFactory"; 34 | 35 | public static class TestXMLProvider extends XMLProvider { 36 | public DocumentBuilderFactory documentBuilderFactory() { 37 | throw new UnsupportedOperationException(MESSAGE); 38 | } 39 | } 40 | 41 | @Test( 42 | expectedExceptions = UnsupportedOperationException.class, 43 | expectedExceptionsMessageRegExp = MESSAGE, 44 | singleThreaded = true) 45 | public void checkXMLProviderSpiLoading() { 46 | final ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader(); 47 | ClassLoader cl = new ClassLoader(threadClassLoader) { 48 | @Override 49 | public Enumeration getResources(final String name) throws IOException { 50 | if ("META-INF/services/io.jenetics.jpx.XMLProvider".equals(name)) { 51 | return new Enumeration() { 52 | 53 | private URL serviceFile = 54 | new File("src/test/resources/io/jenetics/jpx/io.jenetics.jpx.XMLProvider") 55 | .toURI().toURL(); 56 | 57 | @Override 58 | public boolean hasMoreElements() { 59 | return serviceFile != null; 60 | } 61 | 62 | @Override 63 | public URL nextElement() { 64 | final URL url = serviceFile; 65 | serviceFile = null; 66 | return url; 67 | } 68 | 69 | }; 70 | } else { 71 | return super.getResources(name); 72 | } 73 | } 74 | }; 75 | XMLProvider.clear(); 76 | Thread.currentThread().setContextClassLoader(cl); 77 | try { 78 | XMLProvider provider = XMLProvider.provider(); 79 | provider.documentBuilderFactory(); 80 | } finally { 81 | XMLProvider.clear(); 82 | Thread.currentThread().setContextClassLoader(threadClassLoader); 83 | } 84 | } 85 | 86 | 87 | } 88 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/XMLTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import javax.xml.parsers.DocumentBuilder; 23 | import javax.xml.parsers.DocumentBuilderFactory; 24 | import javax.xml.parsers.ParserConfigurationException; 25 | 26 | import org.testng.Assert; 27 | import org.testng.annotations.Test; 28 | import org.w3c.dom.Document; 29 | import org.w3c.dom.Element; 30 | 31 | /** 32 | * @author Franz Wilhelmstötter 33 | */ 34 | public class XMLTest { 35 | 36 | @Test 37 | public void checkExtensionsNull() { 38 | Assert.assertNull(XML.checkExtensions(null)); 39 | } 40 | 41 | @Test(expectedExceptions = IllegalArgumentException.class) 42 | public void checkExtensionsMissingRootElement() throws ParserConfigurationException { 43 | final DocumentBuilderFactory dbf = XMLProvider.provider().documentBuilderFactory(); 44 | final DocumentBuilder db = dbf.newDocumentBuilder(); 45 | final Document doc = db.newDocument(); 46 | 47 | XML.checkExtensions(doc); 48 | } 49 | 50 | @Test(expectedExceptions = IllegalArgumentException.class) 51 | public void checkExtensionsWrongRootElement() throws ParserConfigurationException { 52 | final DocumentBuilderFactory dbf = XMLProvider.provider().documentBuilderFactory(); 53 | final DocumentBuilder db = dbf.newDocumentBuilder(); 54 | final Document doc = db.newDocument(); 55 | final Element root = doc.createElement("ext"); 56 | doc.appendChild(root); 57 | 58 | XML.checkExtensions(doc); 59 | } 60 | 61 | @Test(expectedExceptions = IllegalArgumentException.class) 62 | public void checkExtensionsWrongRootElementNS() throws ParserConfigurationException { 63 | final DocumentBuilderFactory dbf = XMLProvider.provider().documentBuilderFactory(); 64 | final DocumentBuilder db = dbf.newDocumentBuilder(); 65 | final Document doc = db.newDocument(); 66 | final Element root = doc.createElementNS( 67 | "http://www.topografix.com/GPX/1/f1", 68 | "extensions" 69 | ); 70 | doc.appendChild(root); 71 | 72 | XML.checkExtensions(doc); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/ZonedDateTimesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx; 21 | 22 | import java.io.ByteArrayInputStream; 23 | import java.io.ByteArrayOutputStream; 24 | import java.io.DataInputStream; 25 | import java.io.DataOutputStream; 26 | import java.io.IOException; 27 | import java.time.Instant; 28 | import java.util.Random; 29 | 30 | import org.testng.Assert; 31 | import org.testng.annotations.Test; 32 | 33 | /** 34 | * @author Franz Wilhelmstötter 35 | */ 36 | public class ZonedDateTimesTest { 37 | 38 | public static Instant nextZonedDataTime(final Random random) { 39 | final long millis = Math.abs(random.nextInt()); 40 | 41 | return Instant.ofEpochMilli(millis); 42 | } 43 | 44 | @Test 45 | public void readWriteZonedDateTime() throws IOException { 46 | final Random random = new Random(); 47 | 48 | for (int i = 0; i < 1000; ++i) { 49 | final Instant instant = nextZonedDataTime(random); 50 | 51 | final ByteArrayOutputStream bout = new ByteArrayOutputStream(); 52 | final DataOutputStream dout = new DataOutputStream(bout); 53 | 54 | Instants.write(instant, dout); 55 | 56 | final ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); 57 | final DataInputStream din = new DataInputStream(bin); 58 | final Instant read = Instants.read(din); 59 | Assert.assertEquals(read, instant); 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/format/Fixture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.jenetics.jpx.format; 17 | 18 | import static io.jenetics.jpx.Length.Unit.METER; 19 | 20 | import io.jenetics.jpx.Latitude; 21 | import io.jenetics.jpx.Length; 22 | import io.jenetics.jpx.Longitude; 23 | 24 | abstract class Fixture { 25 | 26 | protected LocationFormatter _formatter; 27 | 28 | protected Location latitude(final double d) { 29 | return Location.of(Latitude.ofDegrees(d)); 30 | } 31 | 32 | protected Location latitude(final double d, final double m) { 33 | final var sign = d >= 0.0 ? 1 : -1; 34 | return latitude((Math.abs(d) + m/60.0)*sign); 35 | } 36 | 37 | protected Location latitude(final double d, final double m, final double s) { 38 | final var sign = d >= 0.0 ? 1 : -1; 39 | return latitude((Math.abs(d) + m/60.0 + s/3600.0)*sign); 40 | } 41 | 42 | protected Location longitude(final double d) { 43 | return Location.of(Longitude.ofDegrees(d)); 44 | } 45 | 46 | protected Location longitude(final double d, final double m) { 47 | final var sign = d >= 0.0 ? 1 : -1; 48 | return longitude((Math.abs(d) + m/60.0*sign)); 49 | } 50 | 51 | protected Location longitude(final double d, final double m, final double s) { 52 | final var sign = d >= 0.0 ? 1 : -1; 53 | return longitude((Math.abs(d) + m/60.0 + s/3600.0)*sign); 54 | } 55 | 56 | protected Location elevation(final double e) { 57 | return Location.of(Length.of(e, METER)); 58 | } 59 | 60 | protected Location location(final double lat, final double lon, final double ele) { 61 | return Location.of( 62 | Latitude.ofDegrees(lat), 63 | Longitude.ofDegrees(lon), 64 | Length.of(ele, METER) 65 | ); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/format/LocationRandom.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx.format; 21 | 22 | import java.util.Random; 23 | 24 | import io.jenetics.jpx.Latitude; 25 | import io.jenetics.jpx.Length; 26 | import io.jenetics.jpx.Longitude; 27 | import io.jenetics.jpx.Randoms; 28 | 29 | /** 30 | * @author Franz Wilhelmstötter 31 | */ 32 | public final class LocationRandom { 33 | private LocationRandom() { 34 | } 35 | 36 | public static Latitude nextLatitude(final Random random) { 37 | final double degrees = Randoms.nextInt( 38 | ((int)Latitude.MIN_VALUE.toDegrees())*10, 39 | ((int)Latitude.MAX_VALUE.toDegrees())*10, 40 | random 41 | ); 42 | 43 | return Latitude.ofDegrees(degrees/10); 44 | } 45 | 46 | public static Longitude nextLongitude(final Random random) { 47 | final double degrees = Randoms.nextInt( 48 | ((int)Longitude.MIN_VALUE.toDegrees())*10, 49 | ((int)Longitude.MAX_VALUE.toDegrees())*10, 50 | random 51 | ); 52 | 53 | return Longitude.ofDegrees(degrees/10); 54 | } 55 | 56 | public static Length nextElevation(final Random random) { 57 | return Length.of( 58 | random.nextInt(10000), 59 | Length.Unit.METER 60 | ); 61 | } 62 | 63 | public static Location nextLocation(final Random random) { 64 | return Location.of( 65 | nextLatitude(random), 66 | nextLongitude(random), 67 | nextElevation(random) 68 | ); 69 | } 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/format/PatternTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.jenetics.jpx.format; 17 | 18 | import static org.testng.AssertJUnit.assertEquals; 19 | import static io.jenetics.jpx.format.LocationFormatter.ISO_ELE_LONG; 20 | import static io.jenetics.jpx.format.LocationFormatter.ISO_ELE_MEDIUM; 21 | import static io.jenetics.jpx.format.LocationFormatter.ISO_ELE_SHORT; 22 | import static io.jenetics.jpx.format.LocationFormatter.ISO_HUMAN_ELE_LONG; 23 | import static io.jenetics.jpx.format.LocationFormatter.ISO_HUMAN_LAT_LONG; 24 | import static io.jenetics.jpx.format.LocationFormatter.ISO_HUMAN_LONG; 25 | import static io.jenetics.jpx.format.LocationFormatter.ISO_HUMAN_LON_LONG; 26 | import static io.jenetics.jpx.format.LocationFormatter.ISO_LAT_LONG; 27 | import static io.jenetics.jpx.format.LocationFormatter.ISO_LAT_MEDIUM; 28 | import static io.jenetics.jpx.format.LocationFormatter.ISO_LAT_SHORT; 29 | import static io.jenetics.jpx.format.LocationFormatter.ISO_LONG; 30 | import static io.jenetics.jpx.format.LocationFormatter.ISO_LON_LONG; 31 | import static io.jenetics.jpx.format.LocationFormatter.ISO_LON_MEDIUM; 32 | import static io.jenetics.jpx.format.LocationFormatter.ISO_LON_SHORT; 33 | import static io.jenetics.jpx.format.LocationFormatter.ISO_MEDIUM; 34 | import static io.jenetics.jpx.format.LocationFormatter.ISO_SHORT; 35 | import static io.jenetics.jpx.format.LocationFormatter.ofPattern; 36 | 37 | import java.util.List; 38 | 39 | import org.testng.annotations.DataProvider; 40 | import org.testng.annotations.Test; 41 | 42 | /** 43 | * Tests about patterns: validations, deprecations, ... 44 | */ 45 | public class PatternTest extends Fixture { 46 | 47 | @DataProvider 48 | public Object[] illegalPatterns() { 49 | return new String[]{ 50 | "D D", "M M", "S S", "d d", "m m", "s s", "E E", // repetitions 51 | "+DX", "+dx", // double sign 52 | "D.D M", "D.D M S", "d.d m", "d.d m s", // fractional degrees 53 | "M", "M S", "S", "m", "m s", "s", // missing larger field 54 | "D M.MM S", "d m.mm s" // fractional minutes 55 | }; 56 | } 57 | 58 | @Test(dataProvider = "illegalPatterns", expectedExceptions = {IllegalArgumentException.class}) 59 | public void testIllegalPatterns(String pattern) { 60 | _formatter = ofPattern(pattern); 61 | } 62 | 63 | @Test 64 | public void deprecatedL() { 65 | _formatter = ofPattern("+LL.LLL"); 66 | assertEquals("+DD.DDD", _formatter.toPattern()); 67 | } 68 | 69 | @Test 70 | public void deprecatedl() { 71 | _formatter = ofPattern("+ll.lll"); 72 | assertEquals("+dd.ddd", _formatter.toPattern()); 73 | } 74 | 75 | @Test 76 | public void deprecatedH() { 77 | _formatter = ofPattern("+H.HH"); 78 | assertEquals("+E.EE", _formatter.toPattern()); 79 | } 80 | 81 | @Test(dataProvider = "patterns") 82 | public void parse(final String pattern) { 83 | _formatter = ofPattern(pattern); 84 | String actual = _formatter.toPattern(); 85 | assertEquals(pattern, actual); 86 | } 87 | 88 | @DataProvider 89 | public Object[][] patterns() { 90 | final List patterns = List.of( 91 | ISO_ELE_LONG.toPattern(), 92 | ISO_ELE_MEDIUM.toPattern(), 93 | ISO_ELE_SHORT.toPattern(), 94 | ISO_HUMAN_ELE_LONG.toPattern(), 95 | ISO_HUMAN_LAT_LONG.toPattern(), 96 | ISO_HUMAN_LONG.toPattern(), 97 | ISO_HUMAN_LON_LONG.toPattern(), 98 | ISO_LAT_LONG.toPattern(), 99 | ISO_LAT_MEDIUM.toPattern(), 100 | ISO_LAT_SHORT.toPattern(), 101 | ISO_LONG.toPattern(), 102 | ISO_LON_LONG.toPattern(), 103 | ISO_LON_MEDIUM.toPattern(), 104 | ISO_LON_SHORT.toPattern(), 105 | ISO_MEDIUM.toPattern(), 106 | ISO_SHORT.toPattern(), 107 | ".DDf", 108 | "DD[gg]", 109 | "DD[g''g]" 110 | ); 111 | 112 | return patterns.stream() 113 | .map(f -> new Object[]{f}) 114 | .toArray(Object[][]::new); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/format/TokenTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.jenetics.jpx.format; 17 | 18 | import static org.testng.Assert.assertEquals; 19 | 20 | import java.util.List; 21 | 22 | import org.testng.annotations.DataProvider; 23 | import org.testng.annotations.Test; 24 | 25 | public class TokenTest { 26 | 27 | @Test(dataProvider = "tokens") 28 | public void tokenize(final String pattern, final List tokens) { 29 | final List t = LocationFormatter.Builder.tokenize(pattern); 30 | assertEquals(t, tokens, String.format("%s != %s", t, tokens)); 31 | } 32 | 33 | @DataProvider 34 | public Object[][] tokens() { 35 | return new Object[][] { 36 | {"LL", List.of("LL")}, 37 | {".LL", List.of(".LL")}, 38 | {"LL''", List.of("LL", "'", "'")}, 39 | {"LL'''", List.of("LL", "'", "'", "'")}, 40 | {"LL.LLL", List.of("LL.LLL")}, 41 | {"+++LL[g''g]", List.of("+", "+", "+", "LL", "[", "g", "'", "'", "g", "]")}, 42 | {"LL,LLL", List.of("LL,LLL")}, 43 | {"LLDD", List.of("LL", "DD")}, 44 | {"LL.LDD", List.of("LL.L", "DD")}, 45 | {"LL.LDD.DDD", List.of("LL.L", "DD.DDD")}, 46 | {"LL.L123DD.DDD", List.of("LL.L", "123", "DD.DDD")}, 47 | {"LL.L123DD.DDD4567", List.of("LL.L", "123", "DD.DDD", "4567")}, 48 | {"+LL.LDD.DDD", List.of("+", "LL.L", "DD.DDD")}, 49 | {"+LL.LDD.DDDx", List.of("+", "LL.L", "DD.DDD", "x")}, 50 | {"+LL.LDD.DDD''x", List.of("+", "LL.L", "DD.DDD", "'", "'", "x")}, 51 | {"+LL.LDD.DDD'x'", List.of("+", "LL.L", "DD.DDD", "'", "x", "'")}, 52 | {"+LL.LDD.DDD[x]ss", List.of("+", "LL.L", "DD.DDD", "[", "x", "]", "ss")}, 53 | {"+LL.LDD.DDD[x]'ss", List.of("+", "LL.L", "DD.DDD", "[", "x", "]", "'", "ss")}, 54 | {"+DD.DD[SSS]'XXX'sss.smm", List.of("+", "DD.DD", "[", "SSS", "]", "'", "XXX", "'", "sss.s", "mm")}, 55 | {"+DD.DD[SSS]'XXXsss.smm", List.of("+", "DD.DD", "[", "SSS", "]", "'", "XXXsss.smm")} 56 | }; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/geom/GeoidTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx.geom; 21 | 22 | import java.util.List; 23 | import java.util.Random; 24 | import java.util.stream.Stream; 25 | 26 | import org.testng.Assert; 27 | import org.testng.annotations.DataProvider; 28 | import org.testng.annotations.Test; 29 | 30 | import io.jenetics.jpx.Length; 31 | import io.jenetics.jpx.Point; 32 | import io.jenetics.jpx.WayPoint; 33 | import io.jenetics.jpx.WayPointTest; 34 | 35 | /** 36 | * @author Franz Wilhelmstötter 37 | */ 38 | public class GeoidTest { 39 | 40 | private static final double EPSILON = 0.000000001; 41 | 42 | private final static Geoid GEOID = Geoid.DEFAULT; 43 | 44 | @Test 45 | public void distance() { 46 | final Point start = WayPoint.of(47.2692124, 11.4041024); 47 | final Point end = WayPoint.of(47.3502, 11.70584); 48 | 49 | Assert.assertEquals( 50 | GEOID.distance(start, end).doubleValue(), 51 | 24528.356073554987, 52 | EPSILON 53 | ); 54 | Assert.assertEquals( 55 | GEOID.distance(end, start).doubleValue(), 56 | 24528.356073555155, 57 | EPSILON 58 | ); 59 | Assert.assertEquals( 60 | GEOID.distance(end, end).doubleValue(), 61 | 0.0, 62 | EPSILON 63 | ); 64 | } 65 | 66 | @Test(dataProvider = "pointSizes") 67 | public void collectPathLength(final int size) { 68 | final Random random = new Random(123); 69 | final List points = Stream 70 | .generate(() -> WayPointTest.nextWayPoint(random)) 71 | .limit(size) 72 | .toList(); 73 | 74 | Assert.assertEquals( 75 | pathLength(points), 76 | points.stream() 77 | .collect(GEOID.toPathLength()) 78 | .doubleValue() 79 | ); 80 | } 81 | 82 | private static double pathLength(final List points) { 83 | final DoubleAdder length = new DoubleAdder(); 84 | for (int i = 1; i < points.size(); ++i) { 85 | length.add(GEOID.distance( 86 | points.get(i - 1), 87 | points.get(i)).doubleValue() 88 | ); 89 | } 90 | 91 | return length.doubleValue(); 92 | } 93 | 94 | @Test(dataProvider = "pointSizes") 95 | public void collectTourLength(final int size) { 96 | final Random random = new Random(123); 97 | final List points = Stream 98 | .generate(() -> WayPointTest.nextWayPoint(random)) 99 | .limit(size) 100 | .toList(); 101 | 102 | Assert.assertEquals( 103 | tourLength(points), 104 | points.stream() 105 | .collect(GEOID.toTourLength()) 106 | .doubleValue() 107 | ); 108 | } 109 | 110 | private static double tourLength(final List points) { 111 | final DoubleAdder length = new DoubleAdder(); 112 | for (int i = 0; i < points.size(); ++i) { 113 | length.add(GEOID.distance( 114 | points.get(i), 115 | points.get((i + 1)%points.size())).doubleValue() 116 | ); 117 | } 118 | 119 | return length.doubleValue(); 120 | } 121 | 122 | @DataProvider(name = "pointSizes") 123 | public Object[][] pointSizes() { 124 | return new Object[][] { 125 | {0}, {1}, {2}, {3}, {11}, {27}, {100}, {1000} 126 | }; 127 | } 128 | 129 | @Test(expectedExceptions = UnsupportedOperationException.class) 130 | public void parallelPointStream() { 131 | Length length = Stream.generate(() -> WayPointTest.nextWayPoint(new Random())) 132 | .limit(1000) 133 | .parallel() 134 | .collect(GEOID.toPathLength()); 135 | 136 | Assert.assertNotNull(length); 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /jpx/src/test/java/io/jenetics/jpx/geom/MathUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | package io.jenetics.jpx.geom; 21 | 22 | import static java.lang.Math.nextDown; 23 | import static java.lang.Math.nextUp; 24 | 25 | import org.testng.Assert; 26 | import org.testng.annotations.DataProvider; 27 | import org.testng.annotations.Test; 28 | 29 | /** 30 | * @author Franz Wilhelmstötter 31 | */ 32 | public class MathUtilsTest { 33 | 34 | @Test(dataProvider = "equalValues") 35 | public void equals( 36 | final double x, 37 | final double y, 38 | final int ulps, 39 | final boolean expected 40 | ) { 41 | Assert.assertEquals(MathUtils.equal(x, y, ulps), expected); 42 | } 43 | 44 | @DataProvider 45 | public Object[][] equalValues() { 46 | return new Object[][] { 47 | {123.123, 123.123, 1, true}, 48 | {123.123, nextUp(123.123), 1, true}, 49 | {123.123, nextUp(nextUp(123.123)), 1, false}, 50 | {123.123, nextDown(123.123), 1, true}, 51 | {123.123, nextDown(nextDown(123.123)), 1, false}, 52 | 53 | {-123.123, -123.123, 1, true}, 54 | {-123.123, nextUp(-123.123), 1, true}, 55 | {-123.123, nextUp(nextUp(-123.123)), 1, false}, 56 | {-123.123, nextDown(-123.123), 1, true}, 57 | {-123.123, nextDown(nextDown(-123.123)), 1, false}, 58 | 59 | {0.0, 0.0, 1, true}, 60 | {0.0, nextUp(0.0), 1, true}, 61 | {0.0, nextUp(nextUp(0.0)), 1, false}, 62 | {0.0, nextDown(0.0), 1, true}, 63 | {0.0, nextDown(nextDown(0.0)), 1, false}, 64 | 65 | {1.0, 1.0, 1, true}, 66 | {1.0, nextUp(1.0), 1, true}, 67 | {1.0, nextUp(nextUp(1.0)), 1, false}, 68 | {1.0, nextDown(1.0), 1, true}, 69 | {1.0, nextDown(nextDown(1.0)), 1, false}, 70 | 71 | {1.0, -1.0, 1, false}, 72 | }; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/GPX-full.gpx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | name_56 5 | description_8 6 | 7 | name_24 8 | 9 | 10 | text_16 11 | type_74 12 | 13 | 14 | 15 | 856 16 | http://uri.com/5 17 | 18 | 19 | text_14 20 | type_67 21 | 22 | 23 | keywords_32 24 | 25 | 26 | 27 | 533.0 28 | 94.75368382667327 29 | 30 | 6.741529644762463 31 | 499.0 32 | name_53 33 | comment_78 34 | description_56 35 | source_42 36 | 37 | text_28 38 | type_43 39 | 40 | symbol_89 41 | type_57 42 | 2d 43 | 42 44 | 2.777716680429299 45 | 2.1230395800515214 46 | 2.902715486434789 47 | 608 48 | 87 49 | 50 | 51 | name_52 52 | comment_65 53 | description_23 54 | source_30 55 | 56 | text_80 57 | type_25 58 | 59 | 9 60 | type_72 61 | 62 | 958.0 63 | 96.53259833976092 64 | 65 | 7.744558879076466 66 | 648.0 67 | name_48 68 | comment_82 69 | description_59 70 | source_28 71 | 72 | text_53 73 | type_71 74 | 75 | symbol_21 76 | type_86 77 | 2d 78 | 67 79 | 2.1003894834241827 80 | 2.6562100889037796 81 | 2.931248039161473 82 | 369 83 | 76 84 | 85 | 86 | 87 | name_43 88 | comment_10 89 | description_50 90 | source_62 91 | 92 | text_67 93 | type_57 94 | 95 | 52 96 | type_23 97 | 98 | 99 | 1.0 100 | 8.281567600967666 101 | 102 | 9.284696616811988 103 | 69.0 104 | name_46 105 | comment_9 106 | description_72 107 | source_18 108 | 109 | text_79 110 | type_55 111 | 112 | symbol_35 113 | type_81 114 | pps 115 | 93 116 | 2.375846322376357 117 | 2.1255903247050654 118 | 2.4347694054721187 119 | 336 120 | 60 121 | 122 | 123 | 124 | 125 | 126 | 1 127 | 128 | 129 | 2009-06-19T10:13:04Z 130 | 4.6700000 131 | 1 132 | 0.5881348 133 | 163 134 | 135 | active 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/GPX_10-1.gpx: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | Five Hikes in the White Mountains 8 | Five Hikes in the White Mountains!! 9 | Franz Wilhelmstötter 10 | franz.wilhelmstoetter@gmail.com 11 | https://github.com/jenetics/jpx 12 | Visit my New Hampshire hiking website! 13 | 14 | Hiking, NH, Presidential Range 15 | 16 | 17 | 18 | 19 | 20 | khm 21 | network 22 | 23 | 24 | 25 | 26 | 212.0 27 | 28 | 341.6 29 | 0.67052215 30 | gps 31 | 14 32 | 33 | 34 | 212.0 35 | 36 | 298.6 37 | 0.7424285 38 | 43.0 39 | gps 40 | 2 41 | 0.7 42 | 0.8 43 | 1.1 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/GPX_10-2.gpx: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | Five Hikes in the White Mountains!! 8 | Franz Wilhelmstötter 9 | franz.wilhelmstoetter@gmail.com 10 | https://github.com/jenetics/jpx 11 | Visit my New Hampshire hiking website! 12 | 13 | Hiking, NH, Presidential Range 14 | 15 | 16 | 17 | 18 | 19 | khm 20 | network 21 | 22 | 23 | 24 | 25 | 212.0 26 | 27 | 341.6 28 | 0.67052215 29 | gps 30 | 14 31 | 32 | 33 | 212.0 34 | 35 | 298.6 36 | 0.7424285 37 | 43.0 38 | gps 39 | 2 40 | 0.7 41 | 0.8 42 | 1.1 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/GPX_10-3.gpx: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | Franz Wilhelmstötter 8 | franz.wilhelmstoetter@gmail.com 9 | https://github.com/jenetics/jpx 10 | Visit my New Hampshire hiking website! 11 | 12 | Hiking, NH, Presidential Range 13 | 14 | 15 | 16 | 17 | 18 | khm 19 | network 20 | 21 | 22 | 23 | 24 | 212.0 25 | 26 | 341.6 27 | 0.67052215 28 | gps 29 | 14 30 | 31 | 32 | 212.0 33 | 34 | 298.6 35 | 0.7424285 36 | 43.0 37 | gps 38 | 2 39 | 0.7 40 | 0.8 41 | 1.1 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/GPX_10-4.gpx: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | franz.wilhelmstoetter@gmail.com 8 | https://github.com/jenetics/jpx 9 | Visit my New Hampshire hiking website! 10 | 11 | Hiking, NH, Presidential Range 12 | 13 | 14 | 15 | 16 | 17 | khm 18 | network 19 | 20 | 21 | 22 | 23 | 212.0 24 | 25 | 341.6 26 | 0.67052215 27 | gps 28 | 14 29 | 30 | 31 | 212.0 32 | 33 | 298.6 34 | 0.7424285 35 | 43.0 36 | gps 37 | 2 38 | 0.7 39 | 0.8 40 | 1.1 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/GPX_10-5.gpx: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | https://github.com/jenetics/jpx 8 | Visit my New Hampshire hiking website! 9 | 10 | Hiking, NH, Presidential Range 11 | 12 | 13 | 14 | 15 | 16 | khm 17 | network 18 | 19 | 20 | 21 | 22 | 212.0 23 | 24 | 341.6 25 | 0.67052215 26 | gps 27 | 14 28 | 29 | 30 | 212.0 31 | 32 | 298.6 33 | 0.7424285 34 | 43.0 35 | gps 36 | 2 37 | 0.7 38 | 0.8 39 | 1.1 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/GPX_10-6.gpx: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | khm 13 | network 14 | 15 | 16 | 17 | 18 | 212.0 19 | 20 | 341.6 21 | 0.67052215 22 | gps 23 | 14 24 | 25 | 26 | 212.0 27 | 28 | 298.6 29 | 0.7424285 30 | 43.0 31 | gps 32 | 2 33 | 0.7 34 | 0.8 35 | 1.1 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/GPX_empty_extensions.gpx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | khm 7 | network 8 | 9 | 10 | 11 | 12 | 212.0 13 | 14 | 0.67052215 15 | gps 16 | 14 17 | 18 | 19 | 212.0 20 | 21 | 0.7424285 22 | 43.0 23 | gps 24 | 2 25 | 0.7 26 | 0.8 27 | 1.1 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | khm 40 | network 41 | 42 | 43 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/GPX_extensions.gpx: -------------------------------------------------------------------------------- 1 | 4 | 5 | Run 2009-06-19 6 | 7 | 8 | 9 | 10 | 11 | 12 | 52.048584 13 | 14 | 15 | 164 16 | 99 17 | 18 | 19 | 20 | 52.529175 21 | 22 | 23 | 161 24 | 95 25 | 26 | 27 | 28 | 52.048584 29 | 30 | 31 | 164 32 | 99 33 | 34 | 35 | 36 | 52.529175 37 | 38 | 39 | 161 40 | 96 41 | 42 | 43 | 44 | 45 | 46 | 47 | 1 48 | 49 | 50 | 2009-06-19T10:13:04Z 51 | 4.6700000 52 | 1 53 | 0.5881348 54 | 163 55 | 56 | active 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/GPX_invalid_extensions.gpx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | khm 7 | network 8 | 9 | 10 | 11 | 12 | 212.0 13 | 14 | 0.67052215 15 | gps 16 | 14 17 | 18 | 19 | 212.0 20 | 21 | 0.7424285 22 | 43.0 23 | gps 24 | 2 25 | 0.7 26 | 0.8 27 | 1.1 28 | 29 | 30 | 31 | 32 | 33 | 212.0 34 | 35 | 341.6 36 | 0.67052215 37 | gps 38 | 14 39 | 40 | 41 | 42 | 43 | khm 44 | network 45 | 46 | 47 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/ISSUE-170.gpx: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 42.05 12 | 13 | 14 | 15 | 2.3255813 16 | 0.0 17 | 72 18 | 19 | 20 | 21 | 22 | 42.05 23 | 24 | 25 | 26 | 2.3255813 27 | 0.0 28 | 72 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/ISSUE-186.gpx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 1411.7906106047938 6 | 1392.486126435269 7 | 1395.0386210201773 8 | 1399.1852111777555 9 | 1400.9042412783833 10 | 1404.8712068295272 11 | 1406.7036626781644 12 | 1408.6363346678631 13 | 1410.9618086711207 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/ISSUE-38.gpx.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Name of GPX 4 | 5 | Name of Author/Person 6 | 7 | Link of Author/Person 8 | 9 | 10 | 11 | Link of GPX 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/ISSUE-49.gpx: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 1 12 | 2 13 | 3 14 | 4 15 | 16 | d 17 | d 18 | d 19 | 20 | 21 | 22 | 23 | START 24 | 25 | 26 | 27 | Achterbroek naar De Maatjes 13 km TR 28 | 29 | 30 | 1 31 | 32 | 33 | 2 34 | 35 | 36 | 3 37 | 38 | 39 | 4 40 | 41 | 42 | 5 43 | 44 | 45 | 6 46 | 47 | 48 | 7 49 | 50 | 51 | 8 52 | 53 | 54 | 9 55 | 56 | 57 | 10 58 | 59 | 60 | 11 61 | 62 | 63 | 12 64 | 65 | 66 | 13 67 | 68 | 69 | 14 70 | 71 | 72 | 15 73 | 74 | 75 | 16 76 | 77 | 78 | 17 79 | 80 | 81 | 18 82 | 83 | 84 | 19 85 | 86 | 87 | 20 88 | 89 | 90 | 21 91 | 92 | 93 | 22 94 | 95 | 96 | 23 97 | 98 | 99 | 24 100 | 101 | 102 | 25 103 | 104 | 105 | 26 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/ISSUE-51.gpx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | Name of Author/Person 9 | 10 | Link of Author/Person 11 | 12 | 13 | 16 | 17 | 18 | 287.0 19 | Amstetten 20 | 21 | 22 | 229.0 23 | Baden 24 | 25 | 34 | 35 | 164.0 36 | Gänserndorf 37 | 38 | 39 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/ISSUE-77.gpx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 09-OKT-18 15:12:08 11 | 12 | 13 | 14 | 15 | 374.6 16 | 17 | Position 1 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/ISSUE-78.gpx: -------------------------------------------------------------------------------- 1 | Wien171.0asdfasdf 2 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/empty-ele.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/empty-gpx.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/empty-metadata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/empty-route.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/empty-track-segment.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/empty-track.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/empty-waypoint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/extensions-gpx.gpx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 171.0 5 | Wien 6 | 7 | 8 | asdf 9 | asdf 10 | asdf 11 | 15 | 16 | 17 | 269.0 18 | Eferding 19 | 20 | 21 | 547.0 22 | Freistadt 23 | 24 | 25 | 434.0 26 | Gmunden 27 | 28 | 29 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/extensions-metadata.gpx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Name of GPX 5 | 6 | Name of Author/Person 7 | 8 | Link of Author/Person 9 | 10 | 11 | 12 | asdf 13 | asdf 14 | 18 | 19 | 20 | Link of GPX 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/extensions-route.gpx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | name_97 5 | 6 | asdf 7 | asdf 8 | 12 | 13 | comment_69 14 | 15 | 16 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/extensions-track.gpx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | name_97 5 | 6 | asdf 7 | asdf 8 | 12 | 13 | comment_69 14 | 15 | 16 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/extensions-tracksegment.gpx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | asdf 7 | asdf 8 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/extensions-waypoint.gpx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 171.0 5 | 6 | asdf 7 | asdf 8 | 12 | 13 | Wien 14 | 15 | 16 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/invalid-latlon.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | track-1 9 | Log every 3 sec, 0 m 10 | 11 | 12 | 13 | 14 | 15 | 4325376.000000 16 | 17 | 2.650000 18 | TP000001 19 | 20 | 21 | 147573952589676412928.000000 22 | 23 | 464.010010 24 | TP000002 25 | 26 | 27 | 0.000000 28 | 29 | 56528.671875 30 | TP000003 31 | 32 | 33 | -0.005729 34 | 35 | -11576279.000000 36 | TP000004 37 | 38 | 39 | 138.542969 40 | 41 | 1.070000 42 | TP000005 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/io.jenetics.jpx.XMLProvider: -------------------------------------------------------------------------------- 1 | io.jenetics.jpx.XMLProviderTest$TestXMLProvider -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_0.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_0.obj -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_1.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_1.obj -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 1 6 | 7 | 8 | 2009-06-19T10:13:04Z 9 | 4.6700000 10 | 1 11 | 0.5881348 12 | 163 13 | 14 | active 15 | 16 | 17 | -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_10.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_10.obj -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_11.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_11.obj -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_12.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_12.obj -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_13.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_13.obj -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_14.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_14.obj -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_2.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_2.obj -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_3.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_3.obj -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_4.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_4.obj -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_5.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_5.obj -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_6.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_6.obj -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_7.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_7.obj -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_8.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_8.obj -------------------------------------------------------------------------------- /jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_9.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenetics/jpx/d14c86706f43695354097e36baf7d89590443cdc/jpx/src/test/resources/io/jenetics/jpx/serialization/gpx_9.obj -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Java GPX Library (@__identifier__@). 3 | * Copyright (c) @__year__@ Franz Wilhelmstötter 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * Author: 18 | * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 19 | */ 20 | 21 | /** 22 | * @author Franz Wilhelmstötter 23 | * @since 1.0 24 | * @version 2.1 25 | */ 26 | pluginManagement { 27 | repositories { 28 | mavenLocal() 29 | gradlePluginPortal() 30 | } 31 | } 32 | 33 | dependencyResolutionManagement { 34 | versionCatalogs { 35 | create("libs") { 36 | library("assertj", "org.assertj:assertj-core:3.26.3") 37 | library("commons-math", "org.apache.commons:commons-math3:3.6.1") 38 | library("equalsverifier", "nl.jqno.equalsverifier:equalsverifier:3.17.1") 39 | library("guava", "com.google.guava:guava:33.3.1-jre") 40 | library("prngine", "io.jenetics:prngine:2.0.0") 41 | library("rxjava", "io.reactivex.rxjava2:rxjava:2.2.21") 42 | library("testng", "org.testng:testng:7.10.2") 43 | } 44 | } 45 | } 46 | 47 | rootProject.name = "jpx" 48 | 49 | // The JPX projects. 50 | include("jpx") 51 | --------------------------------------------------------------------------------