diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 182ca1cf..e0eede83 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,11 +1,10 @@ -name: Development Build - Linux +name: build env: BRANCH_NAME: ${{ github.head_ref || github.ref_name }} on: workflow_dispatch: pull_request: - types: [opened, reopened, edited] push: paths-ignore: - "README.md" @@ -16,9 +15,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - with: - ref: ${{ env.BRANCH_NAME }} - fetch-depth: '0' - name: Gradle Build and Test run: | diff --git a/build.gradle b/build.gradle index 7f140d0b..3e9034fd 100644 --- a/build.gradle +++ b/build.gradle @@ -1,36 +1,27 @@ -apply plugin: 'io.github.gradle-nexus.publish-plugin' -apply from: file("${rootDir}/gradle/artifact-settings.gradle") - buildscript { - apply from: "${rootDir}/gradle/dependencies.gradle" - repositories { maven { url 'https://plugins.gradle.org/m2' } google() mavenCentral() - jcenter() } +} - dependencies { - // Adding CheckStyle dependency without having to declare specific version explicitly here. - dependencies.create(pluginDependencies.checkstyle) { - transitive = false - } - - classpath pluginDependencies.jacoco - classpath pluginDependencies.gradleNexus - } +plugins { + alias libs.plugins.gradle.nexus } +apply from: file("${rootDir}/gradle/artifact-settings.gradle") + + tasks.withType(JavaCompile) { options.encoding = 'UTF-8' options.compilerArgs += ['-Xlint:all', '-Xlint:unchecked'] } subprojects { - apply from: "${rootDir}/gradle/dependencies.gradle" apply plugin: 'java' apply plugin: 'idea' + apply from: "${rootDir}/gradle/checkstyle.gradle" // Fixes issue with test resources not being found inside Intellij idea { @@ -45,14 +36,13 @@ subprojects { repositories { google() mavenCentral() - jcenter() } dependencies { // Test Dependencies - testImplementation dependenciesList.junit - testImplementation dependenciesList.hamcrestJunit - testImplementation dependenciesList.mockito + testImplementation libs.junit + testImplementation libs.hamcrestJunit + testImplementation libs.mockito } } diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 3d3b151e..e611a7ae 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -4,10 +4,17 @@ "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> + + + + + + - + @@ -134,7 +141,7 @@ --> - + @@ -190,10 +197,10 @@ imports. Within these groups (separated by an empty line), imports should be lexicographially sorted with no further subcategorization required. --> - - - - + + + + @@ -351,13 +358,6 @@ --> - - - - - - @@ -384,16 +384,15 @@ + + + + - - - - - @@ -406,8 +405,6 @@ descriptions. --> - - @@ -522,7 +519,6 @@ - diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml index 39638662..2172f2bb 100644 --- a/config/checkstyle/suppressions.xml +++ b/config/checkstyle/suppressions.xml @@ -11,4 +11,11 @@ + + + + + + + diff --git a/gradle/artifact-settings.gradle b/gradle/artifact-settings.gradle index af802bdd..b44f4a88 100644 --- a/gradle/artifact-settings.gradle +++ b/gradle/artifact-settings.gradle @@ -31,7 +31,11 @@ def isSnapshot() { } private static def getReleaseVersion(String version) { - return version.substring(1) + if (version && version.length() > 1) { + return version.substring(1) + } else { + return "Unknown" + } } private static def getSnapshotVersion(String version) { diff --git a/gradle/checkstyle.gradle b/gradle/checkstyle.gradle index b0bb0c6c..eb4c91ab 100644 --- a/gradle/checkstyle.gradle +++ b/gradle/checkstyle.gradle @@ -1,6 +1,6 @@ apply plugin: 'checkstyle' -checkstyle.toolVersion = '7.8.2' +checkstyle.toolVersion = '10.15.0' checkstyle.configFile = rootProject.file('config/checkstyle/checkstyle.xml') checkstyleMain.exclude '**/BuildConfig.java' diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle deleted file mode 100644 index 53622c8e..00000000 --- a/gradle/dependencies.gradle +++ /dev/null @@ -1,36 +0,0 @@ -ext { - - version = [ - junit : '4.12', - annotation : '1.0.0', - gson : '2.8.6', - okhttp3 : '3.12.7', - mockito : '2.28.2', - hamcrestJunit : '2.0.0.0' - ] - - pluginVersion = [ - checkstyle : '8.11.0', - spotbugs : '1.3', - dependencyGraph: '0.4.0', - jacoco : '0.8.6', - gradleNexus: "1.1.0" - ] - - dependenciesList = [ - junit : "junit:junit:${version.junit}", - supportAnnotation : "androidx.annotation:annotation:${version.annotation}", - gson : "com.google.code.gson:gson:${version.gson}", - okhttp3Mockwebserver: "com.squareup.okhttp3:mockwebserver:${version.okhttp3}", - mockito : "org.mockito:mockito-core:${version.mockito}", - hamcrestJunit : "org.hamcrest:hamcrest-junit:${version.hamcrestJunit}" - ] - - pluginDependencies = [ - checkstyle : "com.puppycrawl.tools:checkstyle:${pluginVersion.checkstyle}", - spotbugs : "gradle.plugin.com.github.spotbugs:gradlePlugin:${pluginVersion.spotbugs}", - dependencyGraph: "com.vanniktech:gradle-dependency-graph-generator-plugin:${pluginVersion.dependencyGraph}", - jacoco : "org.jacoco:org.jacoco.core:${pluginVersion.jacoco}", - gradleNexus: "io.github.gradle-nexus:publish-plugin:${pluginVersion.gradleNexus}" - ] -} diff --git a/gradle/jacoco.gradle b/gradle/jacoco.gradle index 83722a2f..ea3ec791 100644 --- a/gradle/jacoco.gradle +++ b/gradle/jacoco.gradle @@ -1,7 +1,6 @@ apply plugin: 'jacoco' jacoco { - toolVersion = pluginVersion.jacoco } jacocoTestReport{ @@ -10,7 +9,7 @@ jacocoTestReport{ description = 'Generates a test coverage report for a project' reports { - xml.enabled = true - html.enabled = true + xml.required = true + html.required = true } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 00000000..8fff058c --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,20 @@ +[versions] +junit = "4.12" +hamcrestJunit = "2.0.0.0" +mockito = "2.28.2" +supportAnnotation = "1.0.0" +okhttp3Mockwebserver = "3.12.7" +gson = "2.8.6" + +gradleNexus = "1.1.0" + +[libraries] +junit = { group = "junit", name = "junit", version.ref = "junit" } +hamcrestJunit = { group = "org.hamcrest", name = "hamcrest-junit", version.ref = "hamcrestJunit" } +mockito = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" } +supportAnnotation = { group = "androidx.annotation", name = "annotation", version.ref = "supportAnnotation" } +okhttp3Mockwebserver = { group = "com.squareup.okhttp3", name = "mockwebserver", version.ref = "okhttp3Mockwebserver" } +gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" } + +[plugins] +gradle-nexus = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "gradleNexus" } diff --git a/gradle/publish.gradle b/gradle/publish.gradle index 834dcfe9..2c041636 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -19,11 +19,11 @@ afterEvaluate { project.logger.info("Publishing project with version: ${versionName}") artifact sourcesJar { - classifier "sources" + archiveClassifier.set("sources") } artifact javadocJar { - classifier "javadoc" + archiveClassifier.set("javadoc") } pom { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 62d4c053..249e5832 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661e..48c0a02c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index fbd7c515..a69d9cb6 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,101 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -106,80 +140,101 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index a9f778a7..53a6b238 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -54,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -64,21 +64,6 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line @@ -86,17 +71,19 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/services-geojson/build.gradle b/services-geojson/build.gradle index 4ff3f486..7afd56dd 100644 --- a/services-geojson/build.gradle +++ b/services-geojson/build.gradle @@ -1,14 +1,12 @@ apply plugin: 'java-library' -apply from: "../gradle/dependencies.gradle" - dependencies { // Gson - api dependenciesList.gson + api libs.gson // Annotations - compileOnly dependenciesList.supportAnnotation + compileOnly libs.supportAnnotation // Test Dependencies - testImplementation dependenciesList.okhttp3Mockwebserver + testImplementation libs.okhttp3Mockwebserver } diff --git a/services-geojson/src/main/java/com/mapbox/geojson/Feature.java b/services-geojson/src/main/java/com/mapbox/geojson/Feature.java index 2e095f0a..a30e9355 100644 --- a/services-geojson/src/main/java/com/mapbox/geojson/Feature.java +++ b/services-geojson/src/main/java/com/mapbox/geojson/Feature.java @@ -52,603 +52,602 @@ @Keep public final class Feature implements GeoJson { - private static final String TYPE = "Feature"; - - private final String type; - - @JsonAdapter(BoundingBoxTypeAdapter.class) - private final BoundingBox bbox; - - private final String id; - - private final Geometry geometry; - - private final JsonObject properties; - - /** - * Create a new instance of this class by passing in a formatted valid JSON String. If you are - * creating a Feature object from scratch it is better to use one of the other provided static - * factory methods such as {@link #fromGeometry(Geometry)}. - * - * @param json a formatted valid JSON string defining a GeoJson Feature - * @return a new instance of this class defined by the values passed inside this static factory - * method - * @since 1.0.0 - */ - public static Feature fromJson(@NonNull String json) { - - GsonBuilder gson = new GsonBuilder(); - gson.registerTypeAdapterFactory(GeoJsonAdapterFactory.create()); - gson.registerTypeAdapterFactory(GeometryAdapterFactory.create()); - - Feature feature = gson.create().fromJson(json, Feature.class); - - // Even thought properties are Nullable, - // Feature object will be created with properties set to an empty object, - // so that addProperties() would work - if (feature.properties != null) { - return feature; - } - return new Feature(TYPE, feature.bbox(), - feature.id(), feature.geometry(), new JsonObject()); - } - - /** - * Create a new instance of this class by giving the feature a {@link Geometry}. - * - * @param geometry a single geometry which makes up this feature object - * @return a new instance of this class defined by the values passed inside this static factory - * method - * @since 1.0.0 - */ - public static Feature fromGeometry(@Nullable Geometry geometry) { - return new Feature(TYPE, null, null, geometry, new JsonObject()); - } - - /** - * Create a new instance of this class by giving the feature a {@link Geometry}. You can also pass - * in a double array defining a bounding box. - * - * @param geometry a single geometry which makes up this feature object - * @param bbox optionally include a bbox definition as a double array - * @return a new instance of this class defined by the values passed inside this static factory - * method - * @since 1.0.0 - */ - public static Feature fromGeometry(@Nullable Geometry geometry, @Nullable BoundingBox bbox) { - return new Feature(TYPE, bbox, null, geometry, new JsonObject()); - } - - /** - * Create a new instance of this class by giving the feature a {@link Geometry} and optionally a - * set of properties. - * - * @param geometry a single geometry which makes up this feature object - * @param properties a {@link JsonObject} containing the feature properties - * @return a new instance of this class defined by the values passed inside this static factory - * method - * @since 1.0.0 - */ - public static Feature fromGeometry(@Nullable Geometry geometry, @Nullable JsonObject properties) { - return new Feature(TYPE, null, null, geometry, - properties == null ? new JsonObject() : properties); - } - - /** - * Create a new instance of this class by giving the feature a {@link Geometry}, optionally a - * set of properties, and optionally pass in a bbox. - * - * @param geometry a single geometry which makes up this feature object - * @param bbox optionally include a bbox definition as a double array - * @param properties a {@link JsonObject} containing the feature properties - * @return a new instance of this class defined by the values passed inside this static factory - * method - * @since 1.0.0 - */ - public static Feature fromGeometry(@Nullable Geometry geometry, @Nullable JsonObject properties, - @Nullable BoundingBox bbox) { - return new Feature(TYPE, bbox, null, geometry, - properties == null ? new JsonObject() : properties); - } - - /** - * Create a new instance of this class by giving the feature a {@link Geometry}, optionally a - * set of properties, and a String which represents the objects id. - * - * @param geometry a single geometry which makes up this feature object - * @param properties a {@link JsonObject} containing the feature properties - * @param id common identifier of this feature - * @return {@link Feature} - * @since 1.0.0 - */ - public static Feature fromGeometry(@Nullable Geometry geometry, @Nullable JsonObject properties, - @Nullable String id) { - return new Feature(TYPE, null, id, geometry, - properties == null ? new JsonObject() : properties); - } - - /** - * Create a new instance of this class by giving the feature a {@link Geometry}, optionally a - * set of properties, and a String which represents the objects id. - * - * @param geometry a single geometry which makes up this feature object - * @param properties a {@link JsonObject} containing the feature properties - * @param bbox optionally include a bbox definition as a double array - * @param id common identifier of this feature - * @return {@link Feature} - * @since 1.0.0 - */ - public static Feature fromGeometry(@Nullable Geometry geometry, @Nullable JsonObject properties, - @Nullable String id, @Nullable BoundingBox bbox) { - return new Feature(TYPE, bbox, id, geometry, - properties == null ? new JsonObject() : properties); - } - - Feature(String type, @Nullable BoundingBox bbox, @Nullable String id, - @Nullable Geometry geometry, @Nullable JsonObject properties) { - if (type == null) { - throw new NullPointerException("Null type"); - } - this.type = type; - this.bbox = bbox; - this.id = id; - this.geometry = geometry; - this.properties = properties; + private static final String TYPE = "Feature"; + + private final String type; + + @JsonAdapter(BoundingBoxTypeAdapter.class) + private final BoundingBox bbox; + + private final String id; + + private final Geometry geometry; + + private final JsonObject properties; + + /** + * Create a new instance of this class by passing in a formatted valid JSON String. If you are + * creating a Feature object from scratch it is better to use one of the other provided static + * factory methods such as {@link #fromGeometry(Geometry)}. + * + * @param json a formatted valid JSON string defining a GeoJson Feature + * @return a new instance of this class defined by the values passed inside this static factory + * method + * @since 1.0.0 + */ + public static Feature fromJson(@NonNull String json) { + + GsonBuilder gson = new GsonBuilder(); + gson.registerTypeAdapterFactory(GeoJsonAdapterFactory.create()); + gson.registerTypeAdapterFactory(GeometryAdapterFactory.create()); + + Feature feature = gson.create().fromJson(json, Feature.class); + + // Even thought properties are Nullable, + // Feature object will be created with properties set to an empty object, + // so that addProperties() would work + if (feature.properties != null) { + return feature; + } + return new Feature(TYPE, feature.bbox(), + feature.id(), feature.geometry(), new JsonObject()); + } + + /** + * Create a new instance of this class by giving the feature a {@link Geometry}. + * + * @param geometry a single geometry which makes up this feature object + * @return a new instance of this class defined by the values passed inside this static factory + * method + * @since 1.0.0 + */ + public static Feature fromGeometry(@Nullable Geometry geometry) { + return new Feature(TYPE, null, null, geometry, new JsonObject()); + } + + /** + * Create a new instance of this class by giving the feature a {@link Geometry}. You can also pass + * in a double array defining a bounding box. + * + * @param geometry a single geometry which makes up this feature object + * @param bbox optionally include a bbox definition as a double array + * @return a new instance of this class defined by the values passed inside this static factory + * method + * @since 1.0.0 + */ + public static Feature fromGeometry(@Nullable Geometry geometry, @Nullable BoundingBox bbox) { + return new Feature(TYPE, bbox, null, geometry, new JsonObject()); + } + + /** + * Create a new instance of this class by giving the feature a {@link Geometry} and optionally a + * set of properties. + * + * @param geometry a single geometry which makes up this feature object + * @param properties a {@link JsonObject} containing the feature properties + * @return a new instance of this class defined by the values passed inside this static factory + * method + * @since 1.0.0 + */ + public static Feature fromGeometry(@Nullable Geometry geometry, @Nullable JsonObject properties) { + return new Feature(TYPE, null, null, geometry, + properties == null ? new JsonObject() : properties); + } + + /** + * Create a new instance of this class by giving the feature a {@link Geometry}, optionally a + * set of properties, and optionally pass in a bbox. + * + * @param geometry a single geometry which makes up this feature object + * @param bbox optionally include a bbox definition as a double array + * @param properties a {@link JsonObject} containing the feature properties + * @return a new instance of this class defined by the values passed inside this static factory + * method + * @since 1.0.0 + */ + public static Feature fromGeometry(@Nullable Geometry geometry, @Nullable JsonObject properties, + @Nullable BoundingBox bbox) { + return new Feature(TYPE, bbox, null, geometry, + properties == null ? new JsonObject() : properties); + } + + /** + * Create a new instance of this class by giving the feature a {@link Geometry}, optionally a + * set of properties, and a String which represents the objects id. + * + * @param geometry a single geometry which makes up this feature object + * @param properties a {@link JsonObject} containing the feature properties + * @param id common identifier of this feature + * @return {@link Feature} + * @since 1.0.0 + */ + public static Feature fromGeometry(@Nullable Geometry geometry, @Nullable JsonObject properties, + @Nullable String id) { + return new Feature(TYPE, null, id, geometry, + properties == null ? new JsonObject() : properties); + } + + /** + * Create a new instance of this class by giving the feature a {@link Geometry}, optionally a + * set of properties, and a String which represents the objects id. + * + * @param geometry a single geometry which makes up this feature object + * @param properties a {@link JsonObject} containing the feature properties + * @param bbox optionally include a bbox definition as a double array + * @param id common identifier of this feature + * @return {@link Feature} + * @since 1.0.0 + */ + public static Feature fromGeometry(@Nullable Geometry geometry, @Nullable JsonObject properties, + @Nullable String id, @Nullable BoundingBox bbox) { + return new Feature(TYPE, bbox, id, geometry, + properties == null ? new JsonObject() : properties); + } + + Feature(String type, @Nullable BoundingBox bbox, @Nullable String id, + @Nullable Geometry geometry, @Nullable JsonObject properties) { + if (type == null) { + throw new NullPointerException("Null type"); + } + this.type = type; + this.bbox = bbox; + this.id = id; + this.geometry = geometry; + this.properties = properties; + } + + /** + * This describes the TYPE of GeoJson geometry this object is, thus this will always return + * {@link Feature}. + * + * @return a String which describes the TYPE of geometry, for this object it will always return + * {@code Feature} + * @since 1.0.0 + */ + @NonNull + @Override + public String type() { + return type; + } + + /** + * A Feature Collection might have a member named {@code bbox} to include information on the + * coordinate range for it's {@link Feature}s. The value of the bbox member MUST be a list of + * size 2*n where n is the number of dimensions represented in the contained feature geometries, + * with all axes of the most southwesterly point followed by all axes of the more northeasterly + * point. The axes order of a bbox follows the axes order of geometries. + * + * @return a list of double coordinate values describing a bounding box + * @since 3.0.0 + */ + @Nullable + @Override + public BoundingBox bbox() { + return bbox; + } + + /** + * A feature may have a commonly used identifier which is either a unique String or number. + * + * @return a String containing this features unique identification or null if one wasn't given + * during creation. + * @since 1.0.0 + */ + @Nullable + public String id() { + return id; + } + + /** + * The geometry which makes up this feature. A Geometry object represents points, curves, and + * surfaces in coordinate space. One of the seven geometries provided inside this library can be + * passed in through one of the static factory methods. + * + * @return a single defined {@link Geometry} which makes this feature spatially aware + * @since 1.0.0 + */ + @Nullable + public Geometry geometry() { + return geometry; + } + + /** + * This contains the JSON object which holds the feature properties. The value of the properties + * member is a {@link JsonObject} and might be empty if no properties are provided. + * + * @return a {@link JsonObject} which holds this features current properties + * @since 1.0.0 + */ + @NonNull + public JsonObject properties() { + if (properties == null) { + throw new IllegalStateException("Properties should not be null"); + } + return properties; + } + + /** + * This takes the currently defined values found inside this instance and converts it to a GeoJson + * string. + * + * @return a JSON string which represents this Feature + * @since 1.0.0 + */ + @Override + public String toJson() { + + Gson gson = new GsonBuilder() + .registerTypeAdapterFactory(GeoJsonAdapterFactory.create()) + .registerTypeAdapterFactory(GeometryAdapterFactory.create()) + .create(); + + + // Empty properties -> should not appear in json string + Feature feature = this; + if (properties().size() == 0) { + feature = new Feature(TYPE, bbox(), id(), geometry(), null); + } + + return gson.toJson(feature); + } + + /** + * Gson TYPE adapter for parsing Gson to this class. + * + * @param gson the built {@link Gson} object + * @return the TYPE adapter for this class + * @since 3.0.0 + */ + public static TypeAdapter typeAdapter(Gson gson) { + return new Feature.GsonTypeAdapter(gson); + } + + /** + * Convenience method to add a String member. + * + * @param key name of the member + * @param value the String value associated with the member + * @since 1.0.0 + */ + public void addStringProperty(String key, String value) { + properties().addProperty(key, value); + } + + /** + * Convenience method to add a Number member. + * + * @param key name of the member + * @param value the Number value associated with the member + * @since 1.0.0 + */ + public void addNumberProperty(String key, Number value) { + properties().addProperty(key, value); + } + + /** + * Convenience method to add a Boolean member. + * + * @param key name of the member + * @param value the Boolean value associated with the member + * @since 1.0.0 + */ + public void addBooleanProperty(String key, Boolean value) { + properties().addProperty(key, value); + } + + /** + * Convenience method to add a Character member. + * + * @param key name of the member + * @param value the Character value associated with the member + * @since 1.0.0 + */ + public void addCharacterProperty(String key, Character value) { + properties().addProperty(key, value); + } + + /** + * Convenience method to add a JsonElement member. + * + * @param key name of the member + * @param value the JsonElement value associated with the member + * @since 1.0.0 + */ + public void addProperty(String key, JsonElement value) { + properties().add(key, value); + } + + /** + * Convenience method to get a String member. + * + * @param key name of the member + * @return the value of the member, null if it doesn't exist + * @since 1.0.0 + */ + public String getStringProperty(String key) { + JsonElement propertyKey = properties().get(key); + return propertyKey == null ? null : propertyKey.getAsString(); + } + + /** + * Convenience method to get a Number member. + * + * @param key name of the member + * @return the value of the member, null if it doesn't exist + * @since 1.0.0 + */ + public Number getNumberProperty(String key) { + JsonElement propertyKey = properties().get(key); + return propertyKey == null ? null : propertyKey.getAsNumber(); + } + + /** + * Convenience method to get a Boolean member. + * + * @param key name of the member + * @return the value of the member, null if it doesn't exist + * @since 1.0.0 + */ + public Boolean getBooleanProperty(String key) { + JsonElement propertyKey = properties().get(key); + return propertyKey == null ? null : propertyKey.getAsBoolean(); + } + + /** + * Convenience method to get a Character member. + * + * @param key name of the member + * @return the value of the member, null if it doesn't exist + * @since 1.0.0 + * @deprecated This method was passing the call to JsonElement::getAsCharacter() + * which is in turn deprecated because of misleading nature, as it + * does not get this element as a char but rather as a string's first character. + */ + @Deprecated + @Nullable + public Character getCharacterProperty(String key) { + JsonElement propertyKey = properties().get(key); + //noinspection deprecation + return propertyKey == null ? null : propertyKey.getAsCharacter(); + } + + /** + * Convenience method to get a JsonElement member. + * + * @param key name of the member + * @return the value of the member, null if it doesn't exist + * @since 1.0.0 + */ + public JsonElement getProperty(String key) { + return properties().get(key); + } + + /** + * Removes the property from the object properties. + * + * @param key name of the member + * @return Removed {@code property} from the key string passed in through the parameter. + * @since 1.0.0 + */ + public JsonElement removeProperty(String key) { + return properties().remove(key); + } + + /** + * Convenience method to check if a member with the specified name is present in this object. + * + * @param key name of the member + * @return true if there is the member has the specified name, false otherwise. + * @since 1.0.0 + */ + public boolean hasProperty(String key) { + return properties().has(key); + } + + /** + * Convenience method to check for a member by name as well as non-null value. + * + * @param key name of the member + * @return true if member is present with non-null value, false otherwise. + * @since 1.3.0 + */ + public boolean hasNonNullValueForProperty(String key) { + return hasProperty(key) && !getProperty(key).isJsonNull(); + } + + @Override + public String toString() { + return "Feature{" + + "type=" + type + ", " + + "bbox=" + bbox + ", " + + "id=" + id + ", " + + "geometry=" + geometry + ", " + + "properties=" + properties + + "}"; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj instanceof Feature) { + Feature that = (Feature) obj; + return (this.type.equals(that.type())) + && ((this.bbox == null) ? (that.bbox() == null) : this.bbox.equals(that.bbox())) + && ((this.id == null) ? (that.id() == null) : this.id.equals(that.id())) + && ((this.geometry == null) + ? (that.geometry() == null) : this.geometry.equals(that.geometry())) + && ((this.properties == null) + ? (that.properties == null) : this.properties.equals(that.properties())); + } + return false; + } + + @Override + public int hashCode() { + int hashCode = 1; + hashCode *= 1000003; + hashCode ^= type.hashCode(); + hashCode *= 1000003; + hashCode ^= (bbox == null) ? 0 : bbox.hashCode(); + hashCode *= 1000003; + hashCode ^= (id == null) ? 0 : id.hashCode(); + hashCode *= 1000003; + hashCode ^= (geometry == null) ? 0 : geometry.hashCode(); + hashCode *= 1000003; + hashCode ^= (properties == null) ? 0 : properties.hashCode(); + return hashCode; + } + + /** + * TypeAdapter to serialize/deserialize Feature objects. + * + * @since 4.6.0 + */ + static final class GsonTypeAdapter extends TypeAdapter { + private volatile TypeAdapter stringTypeAdapter; + private volatile TypeAdapter boundingBoxTypeAdapter; + private volatile TypeAdapter geometryTypeAdapter; + private volatile TypeAdapter jsonObjectTypeAdapter; + private final Gson gson; + + GsonTypeAdapter(Gson gson) { + this.gson = gson; } - /** - * This describes the TYPE of GeoJson geometry this object is, thus this will always return - * {@link Feature}. - * - * @return a String which describes the TYPE of geometry, for this object it will always return - * {@code Feature} - * @since 1.0.0 - */ - @NonNull @Override - public String type() { - return type; - } - - /** - * A Feature Collection might have a member named {@code bbox} to include information on the - * coordinate range for it's {@link Feature}s. The value of the bbox member MUST be a list of - * size 2*n where n is the number of dimensions represented in the contained feature geometries, - * with all axes of the most southwesterly point followed by all axes of the more northeasterly - * point. The axes order of a bbox follows the axes order of geometries. - * - * @return a list of double coordinate values describing a bounding box - * @since 3.0.0 - */ - @Nullable - @Override - public BoundingBox bbox() { - return bbox; - } - - /** - * A feature may have a commonly used identifier which is either a unique String or number. - * - * @return a String containing this features unique identification or null if one wasn't given - * during creation. - * @since 1.0.0 - */ - @Nullable - public String id() { - return id; - } - - /** - * The geometry which makes up this feature. A Geometry object represents points, curves, and - * surfaces in coordinate space. One of the seven geometries provided inside this library can be - * passed in through one of the static factory methods. - * - * @return a single defined {@link Geometry} which makes this feature spatially aware - * @since 1.0.0 - */ - @Nullable - public Geometry geometry() { - return geometry; - } - - /** - * This contains the JSON object which holds the feature properties. The value of the properties - * member is a {@link JsonObject} and might be empty if no properties are provided. - * - * @return a {@link JsonObject} which holds this features current properties - * @since 1.0.0 - */ - @NonNull - public JsonObject properties() { - if(properties == null) { - throw new IllegalStateException("Properties should not be null"); + public void write(JsonWriter jsonWriter, Feature object) throws IOException { + if (object == null) { + jsonWriter.nullValue(); + return; + } + jsonWriter.beginObject(); + jsonWriter.name("type"); + TypeAdapter stringTypeAdapter = this.stringTypeAdapter; + if (stringTypeAdapter == null) { + stringTypeAdapter = gson.getAdapter(String.class); + this.stringTypeAdapter = stringTypeAdapter; + } + stringTypeAdapter.write(jsonWriter, object.type()); + jsonWriter.name("bbox"); + if (object.bbox() == null) { + jsonWriter.nullValue(); + } else { + TypeAdapter boundingBoxTypeAdapter = this.boundingBoxTypeAdapter; + if (boundingBoxTypeAdapter == null) { + boundingBoxTypeAdapter = gson.getAdapter(BoundingBox.class); + this.boundingBoxTypeAdapter = boundingBoxTypeAdapter; } - return properties; - } - - /** - * This takes the currently defined values found inside this instance and converts it to a GeoJson - * string. - * - * @return a JSON string which represents this Feature - * @since 1.0.0 - */ - @Override - public String toJson() { - - Gson gson = new GsonBuilder() - .registerTypeAdapterFactory(GeoJsonAdapterFactory.create()) - .registerTypeAdapterFactory(GeometryAdapterFactory.create()) - .create(); - - - // Empty properties -> should not appear in json string - Feature feature = this; - if (properties().size() == 0) { - feature = new Feature(TYPE, bbox(), id(), geometry(), null); + boundingBoxTypeAdapter.write(jsonWriter, object.bbox()); + } + jsonWriter.name("id"); + if (object.id() == null) { + jsonWriter.nullValue(); + } else { + stringTypeAdapter = this.stringTypeAdapter; + if (stringTypeAdapter == null) { + stringTypeAdapter = gson.getAdapter(String.class); + this.stringTypeAdapter = stringTypeAdapter; } - - return gson.toJson(feature); - } - - /** - * Gson TYPE adapter for parsing Gson to this class. - * - * @param gson the built {@link Gson} object - * @return the TYPE adapter for this class - * @since 3.0.0 - */ - public static TypeAdapter typeAdapter(Gson gson) { - return new Feature.GsonTypeAdapter(gson); - } - - /** - * Convenience method to add a String member. - * - * @param key name of the member - * @param value the String value associated with the member - * @since 1.0.0 - */ - public void addStringProperty(String key, String value) { - properties().addProperty(key, value); - } - - /** - * Convenience method to add a Number member. - * - * @param key name of the member - * @param value the Number value associated with the member - * @since 1.0.0 - */ - public void addNumberProperty(String key, Number value) { - properties().addProperty(key, value); - } - - /** - * Convenience method to add a Boolean member. - * - * @param key name of the member - * @param value the Boolean value associated with the member - * @since 1.0.0 - */ - public void addBooleanProperty(String key, Boolean value) { - properties().addProperty(key, value); - } - - /** - * Convenience method to add a Character member. - * - * @param key name of the member - * @param value the Character value associated with the member - * @since 1.0.0 - */ - public void addCharacterProperty(String key, Character value) { - properties().addProperty(key, value); - } - - /** - * Convenience method to add a JsonElement member. - * - * @param key name of the member - * @param value the JsonElement value associated with the member - * @since 1.0.0 - */ - public void addProperty(String key, JsonElement value) { - properties().add(key, value); - } - - /** - * Convenience method to get a String member. - * - * @param key name of the member - * @return the value of the member, null if it doesn't exist - * @since 1.0.0 - */ - public String getStringProperty(String key) { - JsonElement propertyKey = properties().get(key); - return propertyKey == null ? null : propertyKey.getAsString(); - } - - /** - * Convenience method to get a Number member. - * - * @param key name of the member - * @return the value of the member, null if it doesn't exist - * @since 1.0.0 - */ - public Number getNumberProperty(String key) { - JsonElement propertyKey = properties().get(key); - return propertyKey == null ? null : propertyKey.getAsNumber(); - } - - /** - * Convenience method to get a Boolean member. - * - * @param key name of the member - * @return the value of the member, null if it doesn't exist - * @since 1.0.0 - */ - public Boolean getBooleanProperty(String key) { - JsonElement propertyKey = properties().get(key); - return propertyKey == null ? null : propertyKey.getAsBoolean(); - } - - /** - * Convenience method to get a Character member. - * - * @param key name of the member - * @return the value of the member, null if it doesn't exist - * @since 1.0.0 - * @deprecated - * This method was passing the call to JsonElement::getAsCharacter() - * which is in turn deprecated because of misleading nature, as it - * does not get this element as a char but rather as a string's first character. - */ - @Deprecated - @Nullable - public Character getCharacterProperty(String key) { - JsonElement propertyKey = properties().get(key); - //noinspection deprecation - return propertyKey == null ? null : propertyKey.getAsCharacter(); - } - - /** - * Convenience method to get a JsonElement member. - * - * @param key name of the member - * @return the value of the member, null if it doesn't exist - * @since 1.0.0 - */ - public JsonElement getProperty(String key) { - return properties().get(key); - } - - /** - * Removes the property from the object properties. - * - * @param key name of the member - * @return Removed {@code property} from the key string passed in through the parameter. - * @since 1.0.0 - */ - public JsonElement removeProperty(String key) { - return properties().remove(key); - } - - /** - * Convenience method to check if a member with the specified name is present in this object. - * - * @param key name of the member - * @return true if there is the member has the specified name, false otherwise. - * @since 1.0.0 - */ - public boolean hasProperty(String key) { - return properties().has(key); - } - - /** - * Convenience method to check for a member by name as well as non-null value. - * - * @param key name of the member - * @return true if member is present with non-null value, false otherwise. - * @since 1.3.0 - */ - public boolean hasNonNullValueForProperty(String key) { - return hasProperty(key) && !getProperty(key).isJsonNull(); - } - - @Override - public String toString() { - return "Feature{" - + "type=" + type + ", " - + "bbox=" + bbox + ", " - + "id=" + id + ", " - + "geometry=" + geometry + ", " - + "properties=" + properties - + "}"; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; + stringTypeAdapter.write(jsonWriter, object.id()); + } + jsonWriter.name("geometry"); + if (object.geometry() == null) { + jsonWriter.nullValue(); + } else { + TypeAdapter geometryTypeAdapter = this.geometryTypeAdapter; + if (geometryTypeAdapter == null) { + geometryTypeAdapter = gson.getAdapter(Geometry.class); + this.geometryTypeAdapter = geometryTypeAdapter; } - if (obj instanceof Feature) { - Feature that = (Feature) obj; - return (this.type.equals(that.type())) - && ((this.bbox == null) ? (that.bbox() == null) : this.bbox.equals(that.bbox())) - && ((this.id == null) ? (that.id() == null) : this.id.equals(that.id())) - && ((this.geometry == null) - ? (that.geometry() == null) : this.geometry.equals(that.geometry())) - && ((this.properties == null) - ? (that.properties == null) : this.properties.equals(that.properties())); + geometryTypeAdapter.write(jsonWriter, object.geometry()); + } + jsonWriter.name("properties"); + if (object.properties == null) { + jsonWriter.nullValue(); + } else { + TypeAdapter jsonObjectTypeAdapter = this.jsonObjectTypeAdapter; + if (jsonObjectTypeAdapter == null) { + jsonObjectTypeAdapter = gson.getAdapter(JsonObject.class); + this.jsonObjectTypeAdapter = jsonObjectTypeAdapter; } - return false; + jsonObjectTypeAdapter.write(jsonWriter, object.properties()); + } + jsonWriter.endObject(); } @Override - public int hashCode() { - int hashCode = 1; - hashCode *= 1000003; - hashCode ^= type.hashCode(); - hashCode *= 1000003; - hashCode ^= (bbox == null) ? 0 : bbox.hashCode(); - hashCode *= 1000003; - hashCode ^= (id == null) ? 0 : id.hashCode(); - hashCode *= 1000003; - hashCode ^= (geometry == null) ? 0 : geometry.hashCode(); - hashCode *= 1000003; - hashCode ^= (properties == null) ? 0 : properties.hashCode(); - return hashCode; - } - - /** - * TypeAdapter to serialize/deserialize Feature objects. - * - * @since 4.6.0 - */ - static final class GsonTypeAdapter extends TypeAdapter { - private volatile TypeAdapter stringTypeAdapter; - private volatile TypeAdapter boundingBoxTypeAdapter; - private volatile TypeAdapter geometryTypeAdapter; - private volatile TypeAdapter jsonObjectTypeAdapter; - private final Gson gson; - - GsonTypeAdapter(Gson gson) { - this.gson = gson; + public Feature read(JsonReader jsonReader) throws IOException { + if (jsonReader.peek() == JsonToken.NULL) { + jsonReader.nextNull(); + return null; + } + jsonReader.beginObject(); + String type = null; + BoundingBox bbox = null; + String id = null; + Geometry geometry = null; + JsonObject properties = null; + while (jsonReader.hasNext()) { + String name = jsonReader.nextName(); + if (jsonReader.peek() == JsonToken.NULL) { + jsonReader.nextNull(); + continue; } - - @Override - public void write(JsonWriter jsonWriter, Feature object) throws IOException { - if (object == null) { - jsonWriter.nullValue(); - return; + switch (name) { + case "type": + TypeAdapter strTypeAdapter = this.stringTypeAdapter; + if (strTypeAdapter == null) { + strTypeAdapter = gson.getAdapter(String.class); + this.stringTypeAdapter = strTypeAdapter; } - jsonWriter.beginObject(); - jsonWriter.name("type"); - TypeAdapter stringTypeAdapter = this.stringTypeAdapter; - if (stringTypeAdapter == null) { - stringTypeAdapter = gson.getAdapter(String.class); - this.stringTypeAdapter = stringTypeAdapter; + type = strTypeAdapter.read(jsonReader); + break; + + case "bbox": + TypeAdapter boundingBoxTypeAdapter = this.boundingBoxTypeAdapter; + if (boundingBoxTypeAdapter == null) { + boundingBoxTypeAdapter = gson.getAdapter(BoundingBox.class); + this.boundingBoxTypeAdapter = boundingBoxTypeAdapter; } - stringTypeAdapter.write(jsonWriter, object.type()); - jsonWriter.name("bbox"); - if (object.bbox() == null) { - jsonWriter.nullValue(); - } else { - TypeAdapter boundingBoxTypeAdapter = this.boundingBoxTypeAdapter; - if (boundingBoxTypeAdapter == null) { - boundingBoxTypeAdapter = gson.getAdapter(BoundingBox.class); - this.boundingBoxTypeAdapter = boundingBoxTypeAdapter; - } - boundingBoxTypeAdapter.write(jsonWriter, object.bbox()); + bbox = boundingBoxTypeAdapter.read(jsonReader); + break; + + case "id": + strTypeAdapter = this.stringTypeAdapter; + if (strTypeAdapter == null) { + strTypeAdapter = gson.getAdapter(String.class); + this.stringTypeAdapter = strTypeAdapter; } - jsonWriter.name("id"); - if (object.id() == null) { - jsonWriter.nullValue(); - } else { - stringTypeAdapter = this.stringTypeAdapter; - if (stringTypeAdapter == null) { - stringTypeAdapter = gson.getAdapter(String.class); - this.stringTypeAdapter = stringTypeAdapter; - } - stringTypeAdapter.write(jsonWriter, object.id()); + id = strTypeAdapter.read(jsonReader); + break; + + case "geometry": + TypeAdapter geometryTypeAdapter = this.geometryTypeAdapter; + if (geometryTypeAdapter == null) { + geometryTypeAdapter = gson.getAdapter(Geometry.class); + this.geometryTypeAdapter = geometryTypeAdapter; } - jsonWriter.name("geometry"); - if (object.geometry() == null) { - jsonWriter.nullValue(); - } else { - TypeAdapter geometryTypeAdapter = this.geometryTypeAdapter; - if (geometryTypeAdapter == null) { - geometryTypeAdapter = gson.getAdapter(Geometry.class); - this.geometryTypeAdapter = geometryTypeAdapter; - } - geometryTypeAdapter.write(jsonWriter, object.geometry()); + geometry = geometryTypeAdapter.read(jsonReader); + break; + + case "properties": + TypeAdapter jsonObjectTypeAdapter = this.jsonObjectTypeAdapter; + if (jsonObjectTypeAdapter == null) { + jsonObjectTypeAdapter = gson.getAdapter(JsonObject.class); + this.jsonObjectTypeAdapter = jsonObjectTypeAdapter; } - jsonWriter.name("properties"); - if (object.properties == null) { - jsonWriter.nullValue(); - } else { - TypeAdapter jsonObjectTypeAdapter = this.jsonObjectTypeAdapter; - if (jsonObjectTypeAdapter == null) { - jsonObjectTypeAdapter = gson.getAdapter(JsonObject.class); - this.jsonObjectTypeAdapter = jsonObjectTypeAdapter; - } - jsonObjectTypeAdapter.write(jsonWriter, object.properties()); - } - jsonWriter.endObject(); - } + properties = jsonObjectTypeAdapter.read(jsonReader); + break; + + default: + jsonReader.skipValue(); - @Override - public Feature read(JsonReader jsonReader) throws IOException { - if (jsonReader.peek() == JsonToken.NULL) { - jsonReader.nextNull(); - return null; - } - jsonReader.beginObject(); - String type = null; - BoundingBox bbox = null; - String id = null; - Geometry geometry = null; - JsonObject properties = null; - while (jsonReader.hasNext()) { - String name = jsonReader.nextName(); - if (jsonReader.peek() == JsonToken.NULL) { - jsonReader.nextNull(); - continue; - } - switch (name) { - case "type": - TypeAdapter strTypeAdapter = this.stringTypeAdapter; - if (strTypeAdapter == null) { - strTypeAdapter = gson.getAdapter(String.class); - this.stringTypeAdapter = strTypeAdapter; - } - type = strTypeAdapter.read(jsonReader); - break; - - case "bbox": - TypeAdapter boundingBoxTypeAdapter = this.boundingBoxTypeAdapter; - if (boundingBoxTypeAdapter == null) { - boundingBoxTypeAdapter = gson.getAdapter(BoundingBox.class); - this.boundingBoxTypeAdapter = boundingBoxTypeAdapter; - } - bbox = boundingBoxTypeAdapter.read(jsonReader); - break; - - case "id": - strTypeAdapter = this.stringTypeAdapter; - if (strTypeAdapter == null) { - strTypeAdapter = gson.getAdapter(String.class); - this.stringTypeAdapter = strTypeAdapter; - } - id = strTypeAdapter.read(jsonReader); - break; - - case "geometry": - TypeAdapter geometryTypeAdapter = this.geometryTypeAdapter; - if (geometryTypeAdapter == null) { - geometryTypeAdapter = gson.getAdapter(Geometry.class); - this.geometryTypeAdapter = geometryTypeAdapter; - } - geometry = geometryTypeAdapter.read(jsonReader); - break; - - case "properties": - TypeAdapter jsonObjectTypeAdapter = this.jsonObjectTypeAdapter; - if (jsonObjectTypeAdapter == null) { - jsonObjectTypeAdapter = gson.getAdapter(JsonObject.class); - this.jsonObjectTypeAdapter = jsonObjectTypeAdapter; - } - properties = jsonObjectTypeAdapter.read(jsonReader); - break; - - default: - jsonReader.skipValue(); - - } - } - jsonReader.endObject(); - return new Feature(type, bbox, id, geometry, properties); } + } + jsonReader.endObject(); + return new Feature(type, bbox, id, geometry, properties); } + } } diff --git a/services-geojson/src/main/java/com/mapbox/geojson/GeometryCollection.java b/services-geojson/src/main/java/com/mapbox/geojson/GeometryCollection.java index 3b437837..4fba6307 100644 --- a/services-geojson/src/main/java/com/mapbox/geojson/GeometryCollection.java +++ b/services-geojson/src/main/java/com/mapbox/geojson/GeometryCollection.java @@ -146,6 +146,7 @@ public static GeometryCollection fromGeometry(@NonNull Geometry geometry, * Create a new instance of this class by giving the collection a list of {@link Geometry} and * bounding box. * + * @param type type * @param geometries a non-null list of geometry which makes up this collection * @param bbox optionally include a bbox definition as a double array * @since 4.6.0 @@ -167,7 +168,7 @@ public static GeometryCollection fromGeometry(@NonNull Geometry geometry, * {@link GeometryCollection}. * * @return a String which describes the TYPE of geometry, for this object it will always return - * {@code GeometryCollection} + * {@code GeometryCollection} * @since 1.0.0 */ @NonNull diff --git a/services-geojson/src/main/java/com/mapbox/geojson/internal/typeadapters/RuntimeTypeAdapterFactory.java b/services-geojson/src/main/java/com/mapbox/geojson/internal/typeadapters/RuntimeTypeAdapterFactory.java index e85089d2..9acf8876 100644 --- a/services-geojson/src/main/java/com/mapbox/geojson/internal/typeadapters/RuntimeTypeAdapterFactory.java +++ b/services-geojson/src/main/java/com/mapbox/geojson/internal/typeadapters/RuntimeTypeAdapterFactory.java @@ -95,7 +95,8 @@ * Both the type field name ({@code "type"}) and the type labels ({@code * "Rectangle"}) are configurable. * - *

Registering Types

+ *

Registering Types

+ * * Create a {@code RuntimeTypeAdapterFactory} by passing the base type and type field * name to the {@link #of} factory method. If you don't supply an explicit type * field name, {@code "type"} will be used.
   {@code
@@ -192,9 +193,9 @@ public static  RuntimeTypeAdapterFactory of(Class baseType) {
    *
    * @param type class of subtype of base type
    * @param label string value for field that distinguishes subtypes
-   * @throws IllegalArgumentException if either {@code type} or {@code label}
-   *     have already been registered on this type adapter.
    * @return The same object it is called on, so the calls can be chained
+   * @throws IllegalArgumentException if either {@code type} or {@code label}
+   *   have already been registered on this type adapter.
    */
   public RuntimeTypeAdapterFactory registerSubtype(Class type, String label) {
     if (type == null || label == null) {
@@ -213,9 +214,9 @@ public RuntimeTypeAdapterFactory registerSubtype(Class type, Str
    * name}. Labels are case sensitive.
    *
    * @param type type name
-   * @throws IllegalArgumentException if either {@code type} or its simple name
-   *     have already been registered on this type adapter.
    * @return The same object it is called on, so the calls can be chained
+   * @throws IllegalArgumentException if either {@code type} or its simple name
+   *   have already been registered on this type adapter.
    */
   @SuppressWarnings("unused")
   public RuntimeTypeAdapterFactory registerSubtype(Class type) {
diff --git a/services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java b/services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java
index 10c9df16..ec5eb9bd 100644
--- a/services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java
+++ b/services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java
@@ -216,7 +216,8 @@ private static double getSqDist(Point p1, Point p2) {
    * Square distance from a point to a segment.
    *
    * @param point {@link Point} whose distance from segment needs to be determined
-   * @param p1,p2 points defining the segment
+   * @param p1 point defining the segment
+   * @param p2 point defining the segment
    * @return square of the distance between first input point and segment defined by
    *   other two input points
    */
diff --git a/services-geojson/src/test/java/com/mapbox/geojson/FeatureCollectionTest.java b/services-geojson/src/test/java/com/mapbox/geojson/FeatureCollectionTest.java
index 4f9a7643..ad329236 100644
--- a/services-geojson/src/test/java/com/mapbox/geojson/FeatureCollectionTest.java
+++ b/services-geojson/src/test/java/com/mapbox/geojson/FeatureCollectionTest.java
@@ -119,4 +119,4 @@ public void toJson() throws IOException {
     FeatureCollection geo = FeatureCollection.fromJson(json);
     compareJson(json, geo.toJson());
   }
-}
\ No newline at end of file
+}
diff --git a/services-geojson/src/test/java/com/mapbox/geojson/FeatureTest.java b/services-geojson/src/test/java/com/mapbox/geojson/FeatureTest.java
index 02c1243f..df1a6039 100644
--- a/services-geojson/src/test/java/com/mapbox/geojson/FeatureTest.java
+++ b/services-geojson/src/test/java/com/mapbox/geojson/FeatureTest.java
@@ -98,10 +98,10 @@ public void point_feature_fromJson() throws IOException {
 
   @Test
   public void linestring_feature_fromJson() throws IOException {
-      final String json =  "{ \"type\": \"Feature\"," +
-      "\"geometry\": { \"type\": \"LineString\", "+
-      " \"coordinates\": [[ 102.0, 20],[103.0, 3.0],[104.0, 4.0], [105.0, 5.0]]}," +
-      "\"properties\": {\"name\": \"line name\" }}";
+    final String json =  "{ \"type\": \"Feature\"," +
+            "\"geometry\": { \"type\": \"LineString\", " +
+            " \"coordinates\": [[ 102.0, 20],[103.0, 3.0],[104.0, 4.0], [105.0, 5.0]]}," +
+            "\"properties\": {\"name\": \"line name\" }}";
     Feature geo = Feature.fromJson(json);
     assertEquals(geo.type(), "Feature");
     assertEquals(geo.geometry().type(), "LineString");
@@ -250,6 +250,5 @@ public void feature_property_doesnotexist() throws IOException {
 
     value = feature.getNumberProperty("does_not_exist");
     assertNull(value);
-    
   }
 }
diff --git a/services-geojson/src/test/java/com/mapbox/geojson/LineStringTest.java b/services-geojson/src/test/java/com/mapbox/geojson/LineStringTest.java
index 0e6a8d3f..37083b6e 100644
--- a/services-geojson/src/test/java/com/mapbox/geojson/LineStringTest.java
+++ b/services-geojson/src/test/java/com/mapbox/geojson/LineStringTest.java
@@ -150,4 +150,4 @@ public void fromJson_coordinatesPresent() throws Exception {
     thrown.expect(NullPointerException.class);
     LineString.fromJson("{\"type\":\"LineString\",\"coordinates\":null}");
   }
-}
\ No newline at end of file
+}
diff --git a/services-geojson/src/test/java/com/mapbox/geojson/MultiPointTest.java b/services-geojson/src/test/java/com/mapbox/geojson/MultiPointTest.java
index 3e93a76f..e3aad698 100644
--- a/services-geojson/src/test/java/com/mapbox/geojson/MultiPointTest.java
+++ b/services-geojson/src/test/java/com/mapbox/geojson/MultiPointTest.java
@@ -92,8 +92,8 @@ public void testSerializable() throws Exception {
 
   @Test
   public void fromJson() throws IOException {
-    final String json = "{ \"type\": \"MultiPoint\"," +
-            "\"coordinates\": [ [100, 0], [101, 1] ] } ";
+    final String json = "{ \"type\": \"MultiPoint\","
+            + "\"coordinates\": [ [100, 0], [101, 1] ] } ";
     MultiPoint geo = MultiPoint.fromJson(json);
     assertEquals(geo.type(), "MultiPoint");
     assertEquals(geo.coordinates().get(0).longitude(), 100.0, DELTA);
@@ -106,8 +106,8 @@ public void fromJson() throws IOException {
 
   @Test
   public void toJson() throws IOException {
-    final String json = "{ \"type\": \"MultiPoint\"," +
-            "\"coordinates\": [ [100, 0], [101, 1] ] } ";
+    final String json = "{ \"type\": \"MultiPoint\","
+            + "\"coordinates\": [ [100, 0], [101, 1] ] } ";
     MultiPoint geo = MultiPoint.fromJson(json);
     compareJson(json, geo.toJson());
   }
@@ -117,4 +117,4 @@ public void fromJson_coordinatesPresent() throws Exception {
     thrown.expect(NullPointerException.class);
     MultiPoint.fromJson("{\"type\":\"MultiPoint\",\"coordinates\":null}");
   }
-}
\ No newline at end of file
+}
diff --git a/services-geojson/src/test/java/com/mapbox/geojson/PointTest.java b/services-geojson/src/test/java/com/mapbox/geojson/PointTest.java
index 1b9335fe..5586b33f 100644
--- a/services-geojson/src/test/java/com/mapbox/geojson/PointTest.java
+++ b/services-geojson/src/test/java/com/mapbox/geojson/PointTest.java
@@ -158,4 +158,4 @@ public void fromJson_coordinatesPresent() throws Exception {
     thrown.expect(NullPointerException.class);
     Point.fromJson("{\"type\":\"Point\",\"coordinates\":null}");
   }
-}
\ No newline at end of file
+}
diff --git a/services-geojson/src/test/java/com/mapbox/geojson/TestUtils.java b/services-geojson/src/test/java/com/mapbox/geojson/TestUtils.java
index 6a57067b..80407339 100644
--- a/services-geojson/src/test/java/com/mapbox/geojson/TestUtils.java
+++ b/services-geojson/src/test/java/com/mapbox/geojson/TestUtils.java
@@ -51,7 +51,7 @@ public static  T deserialize(byte[] bytes, Class cl)
   }
 
   /**
-   * Comes from Google Utils Test Case
+   * Comes from Google Utils Test Case.
    */
   public static void expectNearNumber(double expected, double actual, double epsilon) {
     assertTrue(String.format("Expected %f to be near %f", actual, expected),
diff --git a/services-geojson/src/test/java/com/mapbox/geojson/shifter/ShifterTest.java b/services-geojson/src/test/java/com/mapbox/geojson/shifter/ShifterTest.java
index 559fbfe6..c08caf23 100644
--- a/services-geojson/src/test/java/com/mapbox/geojson/shifter/ShifterTest.java
+++ b/services-geojson/src/test/java/com/mapbox/geojson/shifter/ShifterTest.java
@@ -1,5 +1,11 @@
 package com.mapbox.geojson.shifter;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
 import com.google.gson.JsonParser;
 import com.mapbox.geojson.BoundingBox;
 import com.mapbox.geojson.LineString;
@@ -12,8 +18,6 @@
 import java.util.Arrays;
 import java.util.List;
 
-import static org.junit.Assert.*;
-
 public class ShifterTest {
 
   static class TestCoordinateShifter implements CoordinateShifter {
@@ -53,7 +57,7 @@ public void basic_coordinate_shifter_manager_creation() throws Exception {
   }
 
   @Test
-  public void default_shifter(){
+  public void default_shifter() {
     assertTrue(CoordinateShifterManager.isUsingDefaultShifter());
 
     CoordinateShifter shifter = new TestCoordinateShifter();
diff --git a/services-geojson/src/test/java/com/mapbox/geojson/utils/GeoJsonUtilsTest.java b/services-geojson/src/test/java/com/mapbox/geojson/utils/GeoJsonUtilsTest.java
index 981755a3..4cc2c90f 100644
--- a/services-geojson/src/test/java/com/mapbox/geojson/utils/GeoJsonUtilsTest.java
+++ b/services-geojson/src/test/java/com/mapbox/geojson/utils/GeoJsonUtilsTest.java
@@ -51,4 +51,4 @@ public void trimMaxLong() {
     double expected = Long.MAX_VALUE;
     assertEquals("trim to 7 digits after period", expected, trimmedValue, 1e-8);
   }
-}
\ No newline at end of file
+}
diff --git a/services-geojson/src/test/java/com/mapbox/geojson/utils/PolylineUtilsTest.java b/services-geojson/src/test/java/com/mapbox/geojson/utils/PolylineUtilsTest.java
index e4261e90..a13253f7 100644
--- a/services-geojson/src/test/java/com/mapbox/geojson/utils/PolylineUtilsTest.java
+++ b/services-geojson/src/test/java/com/mapbox/geojson/utils/PolylineUtilsTest.java
@@ -25,7 +25,7 @@ public class PolylineUtilsTest extends TestUtils {
 
   // Delta for Coordinates comparison
   private static final double DELTA = 0.000001;
-  
+
   private static final String SIMPLIFICATION_INPUT = "simplification-input";
   private static final String SIMPLIFICATION_EXPECTED_OUTPUT = "simplification-expected-output";
 
@@ -129,7 +129,7 @@ public void simplify_neverReturnsNullButRatherAnEmptyList() throws Exception {
   }
 
   @Test
-  public void simplify_returnSameListWhenListSizeIsLessThanOrEqualToTwo(){
+  public void simplify_returnSameListWhenListSizeIsLessThanOrEqualToTwo() {
     final List path = new ArrayList<>();
     path.add(Point.fromLngLat(0, 0));
     path.add(Point.fromLngLat(10, 0));
@@ -138,13 +138,13 @@ public void simplify_returnSameListWhenListSizeIsLessThanOrEqualToTwo(){
   }
 
   @Test
-  public void simplify_withHighestQuality() throws IOException{
+  public void simplify_withHighestQuality() throws IOException {
     List path = createPointListFromResourceFile(SIMPLIFICATION_INPUT);
     List simplifiedPath = simplify(path, PRECISION_5, true);
     List expectedSimplifiedPath = createPointListFromResourceFile(SIMPLIFICATION_EXPECTED_OUTPUT);
     assertTrue("Wrong number of points retained",simplifiedPath.size() == expectedSimplifiedPath.size());
     int counter = 0;
-    for(Point retainedPoint:simplifiedPath){
+    for (Point retainedPoint:simplifiedPath) {
       Point expectedPoint = expectedSimplifiedPath.get(counter);
       assertTrue("Wrong point retained by simplification algorithm",retainedPoint.equals(expectedPoint));
       ++counter;
@@ -156,10 +156,10 @@ private List createPointListFromResourceFile(String fileName) throws IOEx
     String[] coords = inputPoints.split(",", -1);
 
     final List pointList = new ArrayList<>();
-    for(int i= 0;i <= coords.length-2;i = i+2) {
-      double x = Double.parseDouble(coords[i]);
-      double y = Double.parseDouble(coords[i+1]);
-      pointList.add(Point.fromLngLat(x, y));
+    for (int idx = 0; idx <= coords.length - 2; idx = idx + 2) {
+      double xCoord = Double.parseDouble(coords[idx]);
+      double yCoord = Double.parseDouble(coords[idx + 1]);
+      pointList.add(Point.fromLngLat(xCoord, yCoord));
     }
 
     return pointList;
diff --git a/services-turf/build.gradle b/services-turf/build.gradle
index 0258c7ae..e5d4698a 100644
--- a/services-turf/build.gradle
+++ b/services-turf/build.gradle
@@ -1,9 +1,8 @@
 apply plugin: 'java-library'
-apply from: "../gradle/dependencies.gradle"
 
 dependencies {
   api project(":services-geojson")
 
   // Annotations
-  compileOnly dependenciesList.supportAnnotation
+  compileOnly libs.supportAnnotation
 }
diff --git a/services-turf/src/test/java/com/mapbox/turf/TestUtils.java b/services-turf/src/test/java/com/mapbox/turf/TestUtils.java
index a3185404..37a49a52 100644
--- a/services-turf/src/test/java/com/mapbox/turf/TestUtils.java
+++ b/services-turf/src/test/java/com/mapbox/turf/TestUtils.java
@@ -36,7 +36,7 @@ protected String loadJsonFixture(String filename) {
       String filepath = "src/test/resources/" + filename;
       byte[] encoded = Files.readAllBytes(Paths.get(filepath));
       return new String(encoded, UTF_8);
-    } catch (IOException e) {
+    } catch (IOException ex) {
       fail("Unable to load " + filename);
       return "";
     }
@@ -60,14 +60,14 @@ public static  T deserialize(byte[] bytes, Class cl)
   }
 
   /**
-   * Comes from Google Utils Test Case
+   * Comes from Google Utils Test Case.
    */
   public static void expectNearNumber(double expected, double actual, double epsilon) {
     assertTrue(String.format("Expected %f to be near %f", actual, expected),
       Math.abs(expected - actual) <= epsilon);
   }
 
-  protected List getResourceFolderFileNames (String folder) {
+  protected List getResourceFolderFileNames(String folder) {
     ClassLoader loader = getClass().getClassLoader();
     URL url = loader.getResource(folder);
     String path = url.getPath();
diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfAssertionsTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfAssertionsTest.java
index 47c25110..afccb453 100644
--- a/services-turf/src/test/java/com/mapbox/turf/TurfAssertionsTest.java
+++ b/services-turf/src/test/java/com/mapbox/turf/TurfAssertionsTest.java
@@ -9,7 +9,6 @@
 import org.junit.rules.ExpectedException;
 
 import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.assertEquals;
 
 public class TurfAssertionsTest extends TestUtils {
 
@@ -107,4 +106,4 @@ public void testInvariantCollectionOf4() {
       + "type: 'Point', coordinates: [0, 0]}, properties: {}}]}";
     TurfAssertions.collectionOf(FeatureCollection.fromJson(json), "Point", "myfn");
   }
-}
\ No newline at end of file
+}
diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfClassificationTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfClassificationTest.java
index b9fe3c3f..dedf4bce 100644
--- a/services-turf/src/test/java/com/mapbox/turf/TurfClassificationTest.java
+++ b/services-turf/src/test/java/com/mapbox/turf/TurfClassificationTest.java
@@ -32,4 +32,4 @@ public void testLineDistanceWithGeometries() throws IOException, TurfException {
     Assert.assertEquals(closestPt.longitude(), -75.33, DELTA);
     Assert.assertEquals(closestPt.latitude(), 39.44, DELTA);
   }
-}
\ No newline at end of file
+}
diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfConversionTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfConversionTest.java
index d6fb95ba..4cb8ca0d 100644
--- a/services-turf/src/test/java/com/mapbox/turf/TurfConversionTest.java
+++ b/services-turf/src/test/java/com/mapbox/turf/TurfConversionTest.java
@@ -14,7 +14,6 @@
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
-import java.io.IOException;
 import java.util.Arrays;
 
 import static org.hamcrest.CoreMatchers.startsWith;
@@ -33,8 +32,8 @@ public class TurfConversionTest extends TestUtils {
   private static final String TURF_POLYGON_TO_LINE_PATH_IN = "turf-polygon-to-line/in/";
   private static final String TURF_POLYGON_TO_LINE_PATH_OUT = "turf-polygon-to-line/expected/";
 
-  private static final String TURF_POLYGON_TO_LINE_FILENAME_POLYGON= "polygon.geojson";
-  private static final String TURF_POLYGON_TO_LINE_FILENAME_GEOMETRY_POLYGON= "geometry-polygon.geojson";
+  private static final String TURF_POLYGON_TO_LINE_FILENAME_POLYGON = "polygon.geojson";
+  private static final String TURF_POLYGON_TO_LINE_FILENAME_GEOMETRY_POLYGON = "geometry-polygon.geojson";
   private static final String TURF_POLYGON_TO_LINE_FILENAME_POLYGON_WITH_HOLE = "polygon-with-hole.geojson";
 
   private static final String TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON = "multi-polygon.geojson";
@@ -195,8 +194,8 @@ public void combineLineStringAndMultiLineStringToMultiLineString() throws Except
         TurfConversion.combine(lineStringFeatureCollection);
     assertNotNull(featureCollectionWithNewMultiLineStringObject);
 
-    MultiLineString multiLineString = (MultiLineString) featureCollectionWithNewMultiLineStringObject.
-        features().get(0).geometry();
+    MultiLineString multiLineString = (MultiLineString) featureCollectionWithNewMultiLineStringObject
+            .features().get(0).geometry();
     assertNotNull(multiLineString);
 
     // Checking the first LineString in the MultiLineString
diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfJoinsTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfJoinsTest.java
index fb33de8d..13dd163c 100644
--- a/services-turf/src/test/java/com/mapbox/turf/TurfJoinsTest.java
+++ b/services-turf/src/test/java/com/mapbox/turf/TurfJoinsTest.java
@@ -145,7 +145,7 @@ public void testWithin() throws TurfException {
       Point.fromLngLat(20, 20),
       Point.fromLngLat(20, 0),
       Point.fromLngLat(10, 0))));
-    
+
     polyFeatureCollection = FeatureCollection.fromFeatures(new Feature[] {
       Feature.fromGeometry(poly1),
       Feature.fromGeometry(poly2)});
diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfMeasurementTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfMeasurementTest.java
index 649a8b4a..16629258 100644
--- a/services-turf/src/test/java/com/mapbox/turf/TurfMeasurementTest.java
+++ b/services-turf/src/test/java/com/mapbox/turf/TurfMeasurementTest.java
@@ -466,15 +466,17 @@ public void envelope() throws IOException {
     expectedPoints.add(Point.fromLngLat(130, 4));
     expectedPoints.add(Point.fromLngLat(20, 4));
     expectedPoints.add(Point.fromLngLat(20, -10));
-    List> polygonPoints = new ArrayList>() {{
-      add(expectedPoints);
-    }};
+    List> polygonPoints = new ArrayList>() {
+      {
+        add(expectedPoints);
+      }
+    };
     Polygon expected = Polygon.fromLngLats(polygonPoints);
     assertEquals("Polygon should match.", expected, polygon);
   }
 
   @Test
-  public void square(){
+  public void square() {
     BoundingBox bbox1 =  BoundingBox.fromLngLats(0, 0, 5, 10);
     BoundingBox bbox2 = BoundingBox.fromLngLats(0, 0, 10, 5);
 
diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfMetaTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfMetaTest.java
index 3b8189c4..0ef75e06 100644
--- a/services-turf/src/test/java/com/mapbox/turf/TurfMetaTest.java
+++ b/services-turf/src/test/java/com/mapbox/turf/TurfMetaTest.java
@@ -157,4 +157,4 @@ public void wrongFeatureGeometryForGetCoordThrowsException() throws TurfExceptio
       Point.fromLngLat(0, 10)
     ))));
   }
-}
\ No newline at end of file
+}
diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfMiscTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfMiscTest.java
index f2b4a105..add4ec99 100644
--- a/services-turf/src/test/java/com/mapbox/turf/TurfMiscTest.java
+++ b/services-turf/src/test/java/com/mapbox/turf/TurfMiscTest.java
@@ -377,14 +377,14 @@ public void testLineSliceAlongLine1() throws IOException, TurfException {
     double start = 500;
     double stop = 750;
 
-    Point start_point = TurfMeasurement.along(lineStringLine1, start, TurfConstants.UNIT_MILES);
-    Point end_point = TurfMeasurement.along(lineStringLine1, stop, TurfConstants.UNIT_MILES);
+    Point startPoint = TurfMeasurement.along(lineStringLine1, start, TurfConstants.UNIT_MILES);
+    Point endPoint = TurfMeasurement.along(lineStringLine1, stop, TurfConstants.UNIT_MILES);
     LineString sliced = TurfMisc.lineSliceAlong(line1, start, stop, TurfConstants.UNIT_MILES);
 
     assertEquals(sliced.coordinates().get(0).coordinates(),
-      start_point.coordinates());
+      startPoint.coordinates());
     assertEquals(sliced.coordinates().get(sliced.coordinates().size() - 1).coordinates(),
-      end_point.coordinates());
+      endPoint.coordinates());
   }
 
   @Test
@@ -395,14 +395,14 @@ public void testLineSliceAlongOvershootLine1() throws IOException, TurfException
     double start = 500;
     double stop = 1500;
 
-    Point start_point = TurfMeasurement.along(lineStringLine1, start, TurfConstants.UNIT_MILES);
-    Point end_point = TurfMeasurement.along(lineStringLine1, stop, TurfConstants.UNIT_MILES);
+    Point startPoint = TurfMeasurement.along(lineStringLine1, start, TurfConstants.UNIT_MILES);
+    Point endPoint = TurfMeasurement.along(lineStringLine1, stop, TurfConstants.UNIT_MILES);
     LineString sliced = TurfMisc.lineSliceAlong(line1, start, stop, TurfConstants.UNIT_MILES);
 
     assertEquals(sliced.coordinates().get(0).coordinates(),
-      start_point.coordinates());
+      startPoint.coordinates());
     assertEquals(sliced.coordinates().get(sliced.coordinates().size() - 1).coordinates(),
-      end_point.coordinates());
+      endPoint.coordinates());
   }
 
   @Test
@@ -413,15 +413,15 @@ public void testLineSliceAlongRoute1() throws IOException, TurfException {
     double start = 500;
     double stop = 750;
 
-    Point start_point = TurfMeasurement.along(lineStringRoute1, start, TurfConstants.UNIT_MILES);
-    Point end_point = TurfMeasurement.along(lineStringRoute1, stop, TurfConstants.UNIT_MILES);
+    Point startPoint = TurfMeasurement.along(lineStringRoute1, start, TurfConstants.UNIT_MILES);
+    Point endPoint = TurfMeasurement.along(lineStringRoute1, stop, TurfConstants.UNIT_MILES);
 
     LineString sliced = TurfMisc.lineSliceAlong(route1, start, stop, TurfConstants.UNIT_MILES);
 
     assertEquals(sliced.coordinates().get(0).coordinates(),
-      start_point.coordinates());
+      startPoint.coordinates());
     assertEquals(sliced.coordinates().get(sliced.coordinates().size() - 1).coordinates(),
-      end_point.coordinates());
+      endPoint.coordinates());
   }
 
   @Test
@@ -432,14 +432,14 @@ public void testLineSliceAlongRoute2() throws IOException, TurfException {
     double start = 25;
     double stop = 50;
 
-    Point start_point = TurfMeasurement.along(lineStringRoute2, start, TurfConstants.UNIT_MILES);
-    Point end_point = TurfMeasurement.along(lineStringRoute2, stop, TurfConstants.UNIT_MILES);
+    Point startPoint = TurfMeasurement.along(lineStringRoute2, start, TurfConstants.UNIT_MILES);
+    Point endPoint = TurfMeasurement.along(lineStringRoute2, stop, TurfConstants.UNIT_MILES);
     LineString sliced = TurfMisc.lineSliceAlong(route2, start, stop, TurfConstants.UNIT_MILES);
 
     assertEquals(sliced.coordinates().get(0).coordinates(),
-      start_point.coordinates());
+      startPoint.coordinates());
     assertEquals(sliced.coordinates().get(sliced.coordinates().size() - 1).coordinates(),
-      end_point.coordinates());
+      endPoint.coordinates());
   }
 
   @Test
@@ -461,11 +461,11 @@ public void testLineAlongStopLongerThanLength() throws IOException, TurfExceptio
 
     double start = 500;
     double stop = 800000;
-    Point start_point = TurfMeasurement.along(lineStringLine1, start, TurfConstants.UNIT_MILES);
+    Point startPoint = TurfMeasurement.along(lineStringLine1, start, TurfConstants.UNIT_MILES);
     List lineCoordinates = lineStringLine1.coordinates();
     LineString sliced = TurfMisc.lineSliceAlong(line1, start, stop, TurfConstants.UNIT_MILES);
     assertEquals(sliced.coordinates().get(0).coordinates(),
-      start_point.coordinates());
+      startPoint.coordinates());
     assertEquals(sliced.coordinates().get(sliced.coordinates().size() - 1).coordinates(),
       lineCoordinates.get(lineCoordinates.size() - 1).coordinates());
   }
@@ -481,13 +481,13 @@ public void testShortLine() throws IOException, TurfException {
     double start = 50;
     double stop =  100;
 
-    Point start_point = TurfMeasurement.along(lineStringLine1, start, TurfConstants.UNIT_MILES);
-    Point end_point = TurfMeasurement.along(lineStringLine1, stop, TurfConstants.UNIT_MILES);
+    Point startPoint = TurfMeasurement.along(lineStringLine1, start, TurfConstants.UNIT_MILES);
+    Point endPoint = TurfMeasurement.along(lineStringLine1, stop, TurfConstants.UNIT_MILES);
     LineString sliced = TurfMisc.lineSliceAlong(lineStringLine1, start, stop, TurfConstants.UNIT_MILES);
 
     assertEquals(sliced.coordinates().get(0).coordinates(),
-      start_point.coordinates());
+      startPoint.coordinates());
     assertEquals(sliced.coordinates().get(sliced.coordinates().size() - 1).coordinates(),
-      end_point.coordinates());
+      endPoint.coordinates());
   }
-}
\ No newline at end of file
+}
diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfTransformationTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfTransformationTest.java
index ad41aec8..97436eee 100644
--- a/services-turf/src/test/java/com/mapbox/turf/TurfTransformationTest.java
+++ b/services-turf/src/test/java/com/mapbox/turf/TurfTransformationTest.java
@@ -23,4 +23,4 @@ public void name() throws Exception {
     FeatureCollection featureCollection = FeatureCollection.fromJson(loadJsonFixture(CIRCLE_OUT));
     compareJson(featureCollection.features().get(1).geometry().toJson(), polygon.toJson());
   }
-}
\ No newline at end of file
+}