├── jgeohash-core ├── src │ ├── main │ │ ├── resources │ │ │ ├── META-INF │ │ │ │ └── MANIFEST.MF │ │ │ ├── log4j2.xml │ │ │ └── LICENSE.txt │ │ └── java │ │ │ └── de │ │ │ └── alpharogroup │ │ │ └── jgeohash │ │ │ ├── api │ │ │ └── Position.java │ │ │ ├── model │ │ │ ├── Sectionizer.java │ │ │ ├── SectionComparator.java │ │ │ ├── FirstRingRegion.java │ │ │ ├── FirstAndSecondRingRegion.java │ │ │ └── Section.java │ │ │ ├── distance │ │ │ ├── MeasuringUnit.java │ │ │ ├── DistancePoint.java │ │ │ └── DistanceCalculator.java │ │ │ ├── Point.java │ │ │ ├── GeoHashPoint.java │ │ │ ├── Adjacent.java │ │ │ └── GeoHashExtensions.java │ └── test │ │ ├── resources │ │ ├── log4j2-test.xml │ │ └── testng.xml │ │ └── java │ │ └── de │ │ └── alpharogroup │ │ └── jgeohash │ │ ├── distance │ │ ├── enums │ │ │ ├── Alignment.java │ │ │ └── CellSize.java │ │ ├── MeasuringUnitTest.java │ │ ├── DistanceCalculatorTest.java │ │ └── DistancePointTest.java │ │ ├── model │ │ ├── FirstAndSecondRingRegionTest.java │ │ ├── SectionComparatorTest.java │ │ ├── SectionizerTest.java │ │ ├── FirstRingRegionTest.java │ │ └── SectionTest.java │ │ ├── GeoHashPointTest.java │ │ ├── PointTest.java │ │ └── GeoHashExtensionsTest.java ├── .gitignore └── build.gradle ├── jgeohash-geoip ├── src │ ├── main │ │ ├── resources │ │ │ ├── META-INF │ │ │ │ └── MANIFEST.MF │ │ │ ├── log4j2.xml │ │ │ └── LICENSE.txt │ │ └── java │ │ │ └── de │ │ │ └── alpharogroup │ │ │ └── jgeohash │ │ │ └── geoip │ │ │ ├── LookupServiceSingleton.java │ │ │ └── LocationExtensions.java │ └── test │ │ ├── resources │ │ ├── testng.xml │ │ └── log4j2-test.xml │ │ └── java │ │ └── de │ │ └── alpharogroup │ │ └── jgeohash │ │ └── geoip │ │ └── LocationExtensionsTest.java ├── .gitignore └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .github ├── PULL_REQUEST_TEMPLATE.md ├── CONTRIBUTING.md ├── workflows │ └── build-test.yml ├── FUNDING.yml └── CODE_OF_CONDUCT.md ├── src └── main │ └── resources │ ├── img │ ├── D5yi4Um8cpakd6yPRm2hGWuQ5nrVzhSSW1.png │ ├── 0xF708cA86D86C246B69c3F4BAe431eBbe0c2bfddD.png │ ├── 0xc057D159D3C8f3311E73568b334FF6fE82EB2b7D.png │ ├── bc1ql2y99q7e8psndhcc3gferk03esw3qqf677rhjy.png │ ├── FIO7tFMUVAA9cHiPPqKMfMXiSxHrbpiFyRYqTketNuM67aULuwjop.png │ └── 49bqeRQ7Bf49oJFVC72pqpe5hFbb62pfXDYPdLsadGGF81KZW2ZfrPZ8PbAVu5X2v1TYAspeczMya3cYQysNS4usRRPQHVw.png │ └── LICENSE.txt ├── .travis.yml ├── .idea └── runConfigurations │ ├── jgeohash__build_.xml │ ├── jgeohash__clean_.xml │ ├── jgeohash__javadoc_.xml │ ├── jgeohash__publish_.xml │ ├── jgeohash__dependencies_.xml │ ├── jgeohash__licenseFormat_.xml │ ├── jgeohash__jacocoTestReport_.xml │ ├── jgeohash__dependencyUpdates_.xml │ ├── jgeohash__jacocoTestCoverageVerification_.xml │ ├── jgeohash__code_coverage_.xml │ └── jgeohash__publishMavenJavaPublicationToMavenLocal_.xml ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── CHANGELOG.md ├── gradlew ├── LICENSE └── README.md /jgeohash-core/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 -------------------------------------------------------------------------------- /jgeohash-geoip/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | 2 | rootProject.name = 'jgeohash' 3 | include(':jgeohash-geoip') 4 | include(':jgeohash-core') 5 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astrapi69/jgeohash/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Fixes # . 2 | 3 | Changes proposed in this pull request: 4 | 5 | - 6 | 7 | @astrapi69 8 | -------------------------------------------------------------------------------- /src/main/resources/img/D5yi4Um8cpakd6yPRm2hGWuQ5nrVzhSSW1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astrapi69/jgeohash/HEAD/src/main/resources/img/D5yi4Um8cpakd6yPRm2hGWuQ5nrVzhSSW1.png -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | Your are welcome to create pull requests or join in our mailing list for bugfix, doc, example, suggestion or anything else. 4 | -------------------------------------------------------------------------------- /src/main/resources/img/0xF708cA86D86C246B69c3F4BAe431eBbe0c2bfddD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astrapi69/jgeohash/HEAD/src/main/resources/img/0xF708cA86D86C246B69c3F4BAe431eBbe0c2bfddD.png -------------------------------------------------------------------------------- /src/main/resources/img/0xc057D159D3C8f3311E73568b334FF6fE82EB2b7D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astrapi69/jgeohash/HEAD/src/main/resources/img/0xc057D159D3C8f3311E73568b334FF6fE82EB2b7D.png -------------------------------------------------------------------------------- /src/main/resources/img/bc1ql2y99q7e8psndhcc3gferk03esw3qqf677rhjy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astrapi69/jgeohash/HEAD/src/main/resources/img/bc1ql2y99q7e8psndhcc3gferk03esw3qqf677rhjy.png -------------------------------------------------------------------------------- /src/main/resources/img/FIO7tFMUVAA9cHiPPqKMfMXiSxHrbpiFyRYqTketNuM67aULuwjop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astrapi69/jgeohash/HEAD/src/main/resources/img/FIO7tFMUVAA9cHiPPqKMfMXiSxHrbpiFyRYqTketNuM67aULuwjop.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/main/resources/img/49bqeRQ7Bf49oJFVC72pqpe5hFbb62pfXDYPdLsadGGF81KZW2ZfrPZ8PbAVu5X2v1TYAspeczMya3cYQysNS4usRRPQHVw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astrapi69/jgeohash/HEAD/src/main/resources/img/49bqeRQ7Bf49oJFVC72pqpe5hFbb62pfXDYPdLsadGGF81KZW2ZfrPZ8PbAVu5X2v1TYAspeczMya3cYQysNS4usRRPQHVw.png -------------------------------------------------------------------------------- /jgeohash-geoip/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # jgeohash .travis.yml 2 | 3 | language: java 4 | 5 | jdk: 6 | - openjdk8 7 | 8 | notifications: 9 | email: 10 | recipients: 11 | - asterios.raptis@web.de 12 | on_failure: always 13 | 14 | after_success: 15 | - if [ -e ./gradlew ]; then ./gradlew jacocoTestReport;else gradle jacocoTestReport;fi 16 | - bash <(curl -s https://codecov.io/bash) 17 | -------------------------------------------------------------------------------- /jgeohash-core/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /jgeohash-geoip/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /jgeohash-core/src/test/resources/log4j2-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /jgeohash-geoip/src/test/resources/log4j2-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/resources/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) ${year} ${owner} 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /jgeohash-core/src/main/resources/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) ${year} ${owner} 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /jgeohash-geoip/src/main/resources/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) ${year} ${owner} 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /.github/workflows/build-test.yml: -------------------------------------------------------------------------------- 1 | name: Java CI build and test 2 | 3 | on: [push] 4 | 5 | jobs: 6 | test: 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | matrix: 10 | os: [ubuntu-latest, windows-latest, macOS-latest] 11 | java: [8, 11, 15] 12 | fail-fast: false 13 | max-parallel: 4 14 | name: Test JDK ${{ matrix.java }}, ${{ matrix.os }} 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Set up JDK ${{ matrix.java }} 18 | uses: actions/setup-java@v1 19 | with: 20 | java-version: ${{ matrix.java }} 21 | 22 | - name: Verify with Gradle 23 | run: ./gradlew build 24 | ... 25 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: astrapi69 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['https://flattr.com/@astrapi69'] 13 | -------------------------------------------------------------------------------- /.idea/runConfigurations/jgeohash__build_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | true 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/runConfigurations/jgeohash__clean_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | true 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/runConfigurations/jgeohash__javadoc_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | true 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/runConfigurations/jgeohash__publish_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | true 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/runConfigurations/jgeohash__dependencies_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | true 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/runConfigurations/jgeohash__licenseFormat_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | true 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/runConfigurations/jgeohash__jacocoTestReport_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | true 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/runConfigurations/jgeohash__dependencyUpdates_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | true 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /jgeohash-core/src/test/java/de/alpharogroup/jgeohash/distance/enums/Alignment.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.distance.enums; 17 | 18 | /** 19 | * The enum {@link Alignment} provides two directions of width and height 20 | */ 21 | public enum Alignment 22 | { 23 | HEIGHT, WIDTH; 24 | } 25 | -------------------------------------------------------------------------------- /.idea/runConfigurations/jgeohash__jacocoTestCoverageVerification_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | true 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /jgeohash-core/.gitignore: -------------------------------------------------------------------------------- 1 | ################## 2 | # Compiled files # 3 | ################## 4 | *.class 5 | 6 | ################## 7 | # intellij files # 8 | ################## 9 | *.iml 10 | .idea 11 | */.idea 12 | 13 | ################# 14 | # eclipse files # 15 | ################# 16 | /.project 17 | /.classpath 18 | /.settings 19 | 20 | ######################### 21 | # maven generated files # 22 | ######################### 23 | /target 24 | 25 | ############# 26 | # Zip files # 27 | ############# 28 | *.tar 29 | *.zip 30 | *.7z 31 | *.dmg 32 | *.gz 33 | *.iso 34 | *.jar 35 | *.rar 36 | 37 | ############## 38 | # Logs files # 39 | ############## 40 | *.log 41 | 42 | ################# 43 | # test-ng files # 44 | ################# 45 | /test-output 46 | 47 | ############################ 48 | # Binaries generated files # 49 | ############################ 50 | /bin 51 | 52 | ################ 53 | # gradle files # 54 | ################ 55 | /build 56 | /.gradle 57 | /gradle 58 | /pom.xml.bak 59 | -------------------------------------------------------------------------------- /jgeohash-geoip/.gitignore: -------------------------------------------------------------------------------- 1 | ################## 2 | # Compiled files # 3 | ################## 4 | *.class 5 | 6 | ################## 7 | # intellij files # 8 | ################## 9 | *.iml 10 | .idea 11 | */.idea 12 | 13 | ################# 14 | # eclipse files # 15 | ################# 16 | /.project 17 | /.classpath 18 | /.settings 19 | 20 | ######################### 21 | # maven generated files # 22 | ######################### 23 | /target 24 | 25 | ############# 26 | # Zip files # 27 | ############# 28 | *.tar 29 | *.zip 30 | *.7z 31 | *.dmg 32 | *.gz 33 | *.iso 34 | *.jar 35 | *.rar 36 | 37 | ############## 38 | # Logs files # 39 | ############## 40 | *.log 41 | 42 | ################# 43 | # test-ng files # 44 | ################# 45 | /test-output 46 | 47 | ############################ 48 | # Binaries generated files # 49 | ############################ 50 | /bin 51 | 52 | ################ 53 | # gradle files # 54 | ################ 55 | /build 56 | /.gradle 57 | /gradle 58 | /pom.xml.bak 59 | -------------------------------------------------------------------------------- /.idea/runConfigurations/jgeohash__code_coverage_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 23 | 24 | -------------------------------------------------------------------------------- /jgeohash-core/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/runConfigurations/jgeohash__publishMavenJavaPublicationToMavenLocal_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | true 19 | true 20 | false 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################## 2 | # Compiled files # 3 | ################## 4 | *.class 5 | 6 | ################## 7 | # intellij files # 8 | ################## 9 | *.iws 10 | *.iml 11 | *.ipr 12 | !.idea/runConfigurations 13 | .idea/inspectionProfiles 14 | .idea/libraries 15 | .idea/codeStyles 16 | .idea/*.* 17 | 18 | ################# 19 | # eclipse files # 20 | ################# 21 | /.project 22 | /.classpath 23 | /.settings 24 | 25 | ######################### 26 | # maven generated files # 27 | ######################### 28 | /target 29 | *.versionsBackup 30 | 31 | ############# 32 | # Zip files # 33 | ############# 34 | *.tar 35 | *.tar.gz 36 | *.zip 37 | *.7z 38 | *.dmg 39 | *.gz 40 | *.iso 41 | *.jar 42 | *.war 43 | *.ear 44 | *.rar 45 | 46 | ############## 47 | # Logs files # 48 | ############## 49 | *.log 50 | 51 | ################# 52 | # test-ng files # 53 | ################# 54 | /test-output 55 | 56 | ############################ 57 | # Binaries generated files # 58 | ############################ 59 | /bin 60 | 61 | ################ 62 | # gradle files # 63 | ################ 64 | /build 65 | /.gradle 66 | /gradle 67 | /pom.xml.bak 68 | 69 | ################ 70 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 71 | ################ 72 | hs_err_pid* 73 | /.attach_pid* 74 | -------------------------------------------------------------------------------- /jgeohash-core/src/main/java/de/alpharogroup/jgeohash/api/Position.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.api; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * The Interface Position defines a position from a latitude and a longitude. 22 | */ 23 | public interface Position extends Serializable 24 | { 25 | 26 | /** 27 | * Gets the latitude. 28 | * 29 | * @return the latitude 30 | */ 31 | double getLatitude(); 32 | 33 | /** 34 | * Gets the longitude. 35 | * 36 | * @return the longitude 37 | */ 38 | double getLongitude(); 39 | 40 | /** 41 | * Sets the latitude. 42 | * 43 | * @param latitude 44 | * the new latitude 45 | */ 46 | void setLatitude(final double latitude); 47 | 48 | /** 49 | * Sets the longitude. 50 | * 51 | * @param longitude 52 | * the new longitude 53 | */ 54 | void setLongitude(final double longitude); 55 | 56 | } -------------------------------------------------------------------------------- /jgeohash-core/src/main/java/de/alpharogroup/jgeohash/model/Sectionizer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.model; 17 | 18 | import java.util.Comparator; 19 | 20 | import de.alpharogroup.merge.api.GenericSummarizer; 21 | import lombok.Builder; 22 | import lombok.Getter; 23 | import lombok.Setter; 24 | 25 | /** 26 | * The class {@link Sectionizer} can merge {@link Section} objects. 27 | */ 28 | @Getter 29 | @Setter 30 | @Builder 31 | public class Sectionizer extends GenericSummarizer
32 | { 33 | 34 | /** 35 | * Instantiates a new {@link Sectionizer} object 36 | */ 37 | public Sectionizer() 38 | { 39 | super(); 40 | } 41 | 42 | /** 43 | * Instantiates a new {@link Sectionizer} object with the given max iteration 44 | * 45 | * @param maxIteration the max iteration 46 | */ 47 | public Sectionizer(int maxIteration) 48 | { 49 | super(maxIteration); 50 | } 51 | 52 | @Override 53 | protected Comparator
newComparator() 54 | { 55 | return new SectionComparator(); 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /jgeohash-core/src/main/java/de/alpharogroup/jgeohash/distance/MeasuringUnit.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.distance; 17 | 18 | import lombok.Getter; 19 | 20 | /** 21 | * The enum class {@link MeasuringUnit} provides the factors for kilometer, meter and miles. 22 | */ 23 | public enum MeasuringUnit 24 | { 25 | 26 | /** 27 | * The kilometer. 1.609344 is the number of kilometres in a mile 28 | */ 29 | KILOMETER(MeasuringUnit.KILOMETER_FACTOR), 30 | /** 31 | * The meter. 1609.344 is the number of metres in a mile 32 | */ 33 | METER(MeasuringUnit.METER_FACTOR), 34 | 35 | /** 36 | * The mile. 0.8684 is the factor for convert miles(statute) into miles (nautical). One nautical 37 | * mile is the length of one minute of latitude at the equator. 38 | **/ 39 | MILE(MeasuringUnit.MILE_FACTOR); 40 | 41 | public static final double KILOMETER_FACTOR = 1.609344; 42 | public static final double METER_FACTOR = KILOMETER_FACTOR * 1000; 43 | public static final double MILE_FACTOR = 0.8684; 44 | 45 | /** The factor. */ 46 | @Getter 47 | private final double factor; 48 | 49 | /** 50 | * Instantiates a new measuring unit. 51 | * 52 | * @param factor 53 | * the factor 54 | */ 55 | private MeasuringUnit(final double factor) 56 | { 57 | this.factor = factor; 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /jgeohash-core/src/test/java/de/alpharogroup/jgeohash/distance/MeasuringUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.distance; 17 | 18 | import static org.testng.AssertJUnit.assertEquals; 19 | 20 | import org.testng.annotations.Test; 21 | 22 | /** 23 | * The unit test class for the class {@link MeasuringUnit}. 24 | */ 25 | public class MeasuringUnitTest 26 | { 27 | 28 | /** 29 | * Test method for {@link MeasuringUnit#KILOMETER}. 30 | */ 31 | @Test 32 | public void testGetKILOMETERFactor() 33 | { 34 | double expected; 35 | double actual; 36 | actual = MeasuringUnit.KILOMETER.getFactor(); 37 | expected = MeasuringUnit.KILOMETER_FACTOR; 38 | assertEquals(actual, expected); 39 | } 40 | 41 | /** 42 | * Test method for {@link MeasuringUnit#METER}. 43 | */ 44 | @Test 45 | public void testGetMETERFactor() 46 | { 47 | double expected; 48 | double actual; 49 | actual = MeasuringUnit.METER.getFactor(); 50 | expected = MeasuringUnit.METER_FACTOR; 51 | assertEquals(actual, expected); 52 | } 53 | 54 | /** 55 | * Test method for {@link MeasuringUnit#MILE}. 56 | */ 57 | @Test 58 | public void testGetMILEFactor() 59 | { 60 | double expected; 61 | double actual; 62 | actual = MeasuringUnit.MILE.getFactor(); 63 | expected = MeasuringUnit.MILE_FACTOR; 64 | assertEquals(actual, expected); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /jgeohash-core/src/main/java/de/alpharogroup/jgeohash/model/SectionComparator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.model; 17 | 18 | import java.util.Comparator; 19 | 20 | /** 21 | * The class {@link SectionComparator} can compare {@link Section} objects. 22 | */ 23 | public class SectionComparator implements Comparator
24 | { 25 | 26 | /** 27 | * {@inheritDoc} 28 | */ 29 | @Override 30 | public int compare(final Section object, final Section compareWithObject) 31 | { 32 | // Check if one of the objects are null 33 | if (object != null && compareWithObject == null) 34 | { 35 | return 1;// compareWithObject is null so object is bigger 36 | } 37 | if (object == null && compareWithObject != null) 38 | { 39 | return -1; // object is null so compareWithObject is smaller 40 | } 41 | if (object == compareWithObject) 42 | { 43 | return 0;// it is the same Object 44 | } 45 | final int objStart = object.getStart(); 46 | final int objEnd = object.getEnd(); 47 | final int otherStart = compareWithObject.getStart(); 48 | final int otherEnd = compareWithObject.getEnd(); 49 | 50 | final int objectSum = objStart + objEnd; 51 | final int otherSum = otherStart + otherEnd; 52 | if (objStart < otherStart) 53 | { 54 | return 1; // object is bigger 55 | } 56 | if (objStart == otherStart) 57 | { 58 | if (otherSum < objectSum) 59 | { 60 | return 1; // object is bigger 61 | } 62 | if (otherSum > objectSum) 63 | { 64 | return -1; // object is smaller 65 | } 66 | return 0; 67 | } 68 | return -1; // object is smaller 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ###################### 2 | # project properties # 3 | ###################### 4 | projectVersion=2.7-SNAPSHOT 5 | groupPackage=de.alpharogroup 6 | projectSourceCompatibility=1.8 7 | projectInceptionYear=2010 8 | projectHolderUsername=astrapi69 9 | projectLeaderName=Asterios Raptis 10 | slash=/ 11 | colon=: 12 | issuesPath=/issues 13 | projectCoreDescription=This project holds the core classes of the jgeohash library 14 | projectGeoipDescription=This project holds the extension classes of the location and the lookup service 15 | projectScmProviderDomain=github.com 16 | projectScmProviderUrl=https://github.com/ 17 | projectScmGitUrlPrefix=scm:git:git:@ 18 | projectScmGitUrlSuffix=.git 19 | projectLicenseName=The Apache Software License, Version 2.0 20 | projectLicenseUrl=http://www.apache.org/licenses/LICENSE-2.0.txt 21 | projectOrganizationName=Alpha Ro Group UG (h.b.) 22 | projectOrganizationUrl=http://www.alpharogroup.de/ 23 | projectLicenseDistribution=repo 24 | projectIssueManagementSystem=GitHub 25 | projectRepositoriesReleasesRepoUrl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ 26 | projectRepositoriesSnapshotsRepoUrl=https://oss.sonatype.org/content/repositories/snapshots 27 | projectRepositoriesUserNameKey=OSSRHUSERNAME 28 | projectRepositoriesPasswordKey=OSSRHPASSWORD 29 | ########################### 30 | # gradle-plugins versions # 31 | ########################### 32 | gradlePluginLombokVersion=6.0.0-m2 33 | gradlePluginVersionsVersion=0.38.0 34 | licenseGradlePluginVersion=0.15.0 35 | ######################### 36 | # dependencies versions # 37 | ######################### 38 | lombokVersion=1.18.20 39 | mergeApiVersion=3 40 | geoipApiVersion=1.3.1 41 | jcommonsLangVersion=5.2.2 42 | ############################## 43 | # test dependencies versions # 44 | ############################## 45 | jobjContractVerifierVersion=3.3 46 | testObjectsVersion=5.3 47 | meanbeanVersion=2.0.3 48 | testngVersion=7.4.0 49 | sillyCollectionsVersion=8.4 50 | sillyBeansVersion=1.1 51 | ########################## 52 | # for deploy on sonatype # 53 | ########################## 54 | systemProp.org.gradle.internal.publish.checksums.insecure=true 55 | org.gradle.caching = true 56 | org.gradle.parallel = true 57 | org.gradle.configureondemand = true 58 | org.gradle.vfs.watch = true 59 | -------------------------------------------------------------------------------- /jgeohash-core/src/main/java/de/alpharogroup/jgeohash/distance/DistancePoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.distance; 17 | 18 | import de.alpharogroup.jgeohash.api.Position; 19 | import lombok.Builder; 20 | import lombok.EqualsAndHashCode; 21 | import lombok.Getter; 22 | import lombok.ToString; 23 | 24 | /** 25 | * The class {@link DistancePoint} is a pojo for holding a distance from one point. you can sort 26 | * than the objects from the distance. 27 | */ 28 | @Getter 29 | @EqualsAndHashCode 30 | @ToString 31 | @Builder(toBuilder = true) 32 | public class DistancePoint implements Comparable 33 | { 34 | 35 | /** The distance. */ 36 | private final Double distance; 37 | 38 | /** The position point. */ 39 | private final Position point; 40 | 41 | /** 42 | * Instantiates a new {@link DistancePoint} object from the given arguments 43 | * 44 | * @param distance 45 | * the distance 46 | * @param point 47 | * the position point 48 | */ 49 | public DistancePoint(final Double distance, final Position point) 50 | { 51 | this.distance = distance; 52 | this.point = point; 53 | } 54 | 55 | /** 56 | * Instantiates a new {@link DistancePoint} object from the given arguments 57 | * 58 | * @param point 59 | * the position point 60 | * @param distance 61 | * the distance 62 | */ 63 | public DistancePoint(final Position point, final Double distance) 64 | { 65 | this.point = point; 66 | this.distance = distance; 67 | } 68 | 69 | /** 70 | * {@inheritDoc} 71 | */ 72 | @Override 73 | public int compareTo(final DistancePoint o) 74 | { 75 | return distance.compareTo(o.distance); 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /jgeohash-core/src/test/java/de/alpharogroup/jgeohash/model/FirstAndSecondRingRegionTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.model; 17 | 18 | import static org.testng.AssertJUnit.assertEquals; 19 | 20 | import org.testng.annotations.Test; 21 | 22 | import de.alpharogroup.evaluate.object.evaluators.EqualsHashCodeAndToStringEvaluator; 23 | 24 | 25 | /** 26 | * The unit test class for the class {@link FirstAndSecondRingRegion}. 27 | */ 28 | public class FirstAndSecondRingRegionTest 29 | { 30 | 31 | /** 32 | * Test method for {@link FirstAndSecondRingRegion#clone()} 33 | */ 34 | @Test 35 | public void testClone() 36 | { 37 | FirstAndSecondRingRegion actual; 38 | FirstAndSecondRingRegion expected; 39 | expected = new FirstAndSecondRingRegion("u1x0etp"); 40 | actual = (FirstAndSecondRingRegion)expected.clone(); 41 | assertEquals(expected, actual); 42 | } 43 | 44 | /** 45 | * Test method for {@link FirstAndSecondRingRegion#equals(Object)} , 46 | * {@link FirstAndSecondRingRegion#hashCode()} and {@link FirstAndSecondRingRegion#toString()} 47 | */ 48 | @Test 49 | public void testEqualsHashcodeAndToString() 50 | { 51 | boolean expected; 52 | boolean actual; 53 | final FirstAndSecondRingRegion first = new FirstAndSecondRingRegion("u1x0etp"); 54 | final FirstAndSecondRingRegion second = new FirstAndSecondRingRegion("u1x0etq"); 55 | final FirstAndSecondRingRegion third = new FirstAndSecondRingRegion("u1x0etp"); 56 | final FirstAndSecondRingRegion fourth = new FirstAndSecondRingRegion("u1x0etp"); 57 | 58 | actual = EqualsHashCodeAndToStringEvaluator.evaluateEqualsHashcodeAndToString(first, second, 59 | third, fourth); 60 | expected = true; 61 | assertEquals(expected, actual); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /jgeohash-core/src/main/java/de/alpharogroup/jgeohash/model/FirstRingRegion.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.model; 17 | 18 | import java.io.Serializable; 19 | 20 | import de.alpharogroup.jgeohash.Adjacent; 21 | import de.alpharogroup.jgeohash.GeoHashExtensions; 22 | import lombok.EqualsAndHashCode; 23 | import lombok.Getter; 24 | import lombok.ToString; 25 | 26 | /** 27 | * The class {@link FirstRingRegion} provides the neighbors from the given geohash value. 28 | */ 29 | @Getter 30 | @EqualsAndHashCode 31 | @ToString 32 | public class FirstRingRegion implements Serializable, Cloneable 33 | { 34 | 35 | /** 36 | * The constant serialVersionUID. 37 | */ 38 | private static final long serialVersionUID = -1L; 39 | 40 | /** The center. */ 41 | private final String center; 42 | 43 | /** The east. */ 44 | private final String east; 45 | 46 | /** The north. */ 47 | private final String north; 48 | 49 | /** The north east. */ 50 | private final String northEast; 51 | 52 | /** The north west. */ 53 | private final String northWest; 54 | 55 | /** The south. */ 56 | private final String south; 57 | 58 | /** The south east. */ 59 | private final String southEast; 60 | 61 | /** The south west. */ 62 | private final String southWest; 63 | 64 | /** The west. */ 65 | private final String west; 66 | 67 | /** 68 | * Instantiates a new FirstRingRegion object from the given geohash value. 69 | * 70 | * @param geohash 71 | * the center 72 | */ 73 | public FirstRingRegion(final String geohash) 74 | { 75 | this.center = geohash; 76 | this.east = GeoHashExtensions.getAdjacent(geohash, Adjacent.RIGHT); 77 | this.west = GeoHashExtensions.getAdjacent(geohash, Adjacent.LEFT); 78 | this.north = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP); 79 | this.south = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM); 80 | this.southEast = GeoHashExtensions.getAdjacent(this.south, Adjacent.RIGHT); 81 | this.northEast = GeoHashExtensions.getAdjacent(this.north, Adjacent.RIGHT); 82 | this.northWest = GeoHashExtensions.getAdjacent(this.north, Adjacent.LEFT); 83 | this.southWest = GeoHashExtensions.getAdjacent(this.south, Adjacent.LEFT); 84 | } 85 | 86 | /** 87 | * {@inheritDoc} 88 | */ 89 | @Override 90 | public Object clone() 91 | { 92 | return new FirstRingRegion(this.center); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /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 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | ## Change log 3 | ---------------------- 4 | 5 | Version 2.7-SNAPSHOT 6 | ------------- 7 | 8 | Version 2.6 9 | ------------- 10 | 11 | ADDED: 12 | 13 | - gradle as build system 14 | - new barcode images for several crypto addresses 15 | 16 | CHANGED: 17 | 18 | - removed maven related files 19 | - changed project nature from maven to gradle nature 20 | - update of jcommons-lang version to 5.2.2 21 | - update of test-objects version to 5.3 22 | - update of silly-collections version to 8.4 23 | - dependency jobject-evaluate replaced with jobj-contract-verifier 24 | - new launch scripts for ide intellij created 25 | 26 | Version 2.5.2 27 | ------------- 28 | 29 | CHANGED: 30 | 31 | - update of parent version to 4.4 32 | - update of jcommons-lang version to 5.1 33 | - update of jobject-extensions version to 2.5 34 | - update of silly-collections version to 5 35 | - update of silly-collections version to 5 36 | - update of dependency test-objects version to 5 37 | - removed exclusions from dependency jcommons-lang 38 | 39 | Version 2.5.1 40 | ------------- 41 | 42 | CHANGED: 43 | 44 | - update of parent version to 4.2 45 | - update of jcommons-lang version to 5 46 | - update of jobject-extensions version to 2.3 47 | - update of silly-collections version to 4.35 48 | - moved dependencies from parent to the specific jgeohash-geoip project 49 | - added exclusions to unneeded transitive dependencies from dependency jcommons-lang 50 | 51 | Version 2.5 52 | ------------- 53 | 54 | ADDED: 55 | 56 | - new test dependency of test-objects 57 | - new test dependency of silly-collections 58 | 59 | CHANGED: 60 | 61 | - update of parent version to 3.11 62 | - removed unneeded .0 at the end of version 63 | - unit tests extended for improve code coverage 64 | 65 | Version 2.4.0 66 | ------------- 67 | 68 | ADDED: 69 | 70 | - Note section added 71 | 72 | CHANGED: 73 | 74 | - update of java parent version 75 | - moved changelog to its own file 76 | 77 | Version 2.3.0 78 | ------------- 79 | - Created new module projects. jgeohash-core and jgeohash-geoip 80 | 81 | Version 2.0.0 82 | ------------- 83 | - JDK version upgraded to version 8. 84 | 85 | Version 1.4.6 86 | ------------- 87 | - Added project to sonatype repository. 88 | - Added project to continous integration: https://travis-ci.org/astrapi69/jgeohash 89 | - Added project to flattr.com: https://flattr.com/thing/4067696/astrapi69jgeohash-on-GitHub 90 | 91 | Version 1.4.5 92 | ------------- 93 | Gets the geohash from the given ip address 94 | added dependency for geoip-api 95 | 96 | Version 1.4.3 97 | ------------- 98 | Extend functionality to calculate distance from two Points, Positions, coordinate values(latitude, longitude) or two geohash values in meters. 99 | Created a new class for keeping data of the neighbors cells from the given geohash to cardinal directions for the first and second ring region. 100 | 101 | 102 | Version 1.4.2 103 | ------------- 104 | Added new interface Position for the class Point. 105 | 106 | Created new class that calculates distance from two Points or two geohash values in km or miles. 107 | 108 | 109 | Version 1.4.1 110 | ------------- 111 | 112 | Added method to get getAdjacent from multiply directions. 113 | 114 | Added functionality for get first and second ring neighbors from a geohash cell. 115 | 116 | 117 | -------------------------------------------------------------------------------- /jgeohash-geoip/src/main/java/de/alpharogroup/jgeohash/geoip/LookupServiceSingleton.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.geoip; 17 | 18 | import java.io.File; 19 | import java.io.FileOutputStream; 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | 23 | import org.apache.commons.io.IOUtils; 24 | 25 | import com.maxmind.geoip.LookupService; 26 | 27 | import de.alpharogroup.lang.ClassExtensions; 28 | 29 | /** 30 | * The class {@link LookupServiceSingleton} is a singleton class for the {@link LookupService}.
31 | *
32 | * Note:
33 | * There have to be the file with the file name 'GeoLiteCity.dat' in the classpath for appropriate 34 | * work of the {@link LookupService}. 35 | */ 36 | public final class LookupServiceSingleton 37 | { 38 | /** The single instance of the {@link LookupService}. */ 39 | private static volatile LookupService instance; 40 | 41 | /** The constant for the file name prefix. */ 42 | private static final String PREFIX = "GeoLiteCity"; 43 | 44 | /** The Constant for the file name suffix. */ 45 | private static final String SUFFIX = ".dat"; 46 | 47 | /** 48 | * Gets the single instance of the {@link LookupService} 49 | * 50 | * @return the single instance of the {@link LookupService} 51 | * 52 | * @throws IOException 53 | * Signals that an I/O exception has occurred. 54 | */ 55 | public static LookupService getInstance() throws IOException 56 | { 57 | if (instance == null) 58 | { 59 | synchronized (LookupServiceSingleton.class) 60 | { // double check... 61 | if (instance == null) 62 | { 63 | File fileLocation = null; 64 | final InputStream is = ClassExtensions.getResourceAsStream(PREFIX + SUFFIX); 65 | fileLocation = inputStreamToFile(is); 66 | instance = new LookupService(fileLocation, LookupService.GEOIP_MEMORY_CACHE); 67 | } 68 | } 69 | } 70 | return instance; 71 | } 72 | 73 | /** 74 | * Creates a temporary file from the given {@link InputStream} object. Note: the created 75 | * temporary file from the given {@link InputStream} object will be deleted on finish of the 76 | * application. 77 | * 78 | * @param inputStream 79 | * the {@link InputStream} object 80 | * @return the temporary file from the given {@link InputStream} object 81 | * @throws IOException 82 | * Signals that an I/O exception has occurred. 83 | */ 84 | private static File inputStreamToFile(final InputStream inputStream) throws IOException 85 | { 86 | final File tempFile = File.createTempFile(PREFIX, SUFFIX); 87 | tempFile.deleteOnExit(); 88 | final FileOutputStream out = new FileOutputStream(tempFile); 89 | IOUtils.copy(inputStream, out); 90 | return tempFile; 91 | } 92 | 93 | /** 94 | * Private constructor. 95 | */ 96 | private LookupServiceSingleton() 97 | { 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /jgeohash-core/src/test/java/de/alpharogroup/jgeohash/GeoHashPointTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash; 17 | 18 | import static org.testng.Assert.assertEquals; 19 | import static org.testng.Assert.assertTrue; 20 | import static org.testng.AssertJUnit.assertNotNull; 21 | 22 | import java.math.BigDecimal; 23 | 24 | import org.testng.annotations.Test; 25 | 26 | import de.alpharogroup.evaluate.object.verifier.ContractVerifier; 27 | 28 | /** 29 | * The unit test class for the class {@link GeoHashPoint} 30 | */ 31 | public class GeoHashPointTest 32 | { 33 | 34 | /** 35 | * Test method for {@link Point#compareTo(Point)}. 36 | */ 37 | @Test 38 | public void testCompareTo() 39 | { 40 | /** For use of the expected result. */ 41 | boolean expected; 42 | /** For use of the result of the comparison. */ 43 | int actual; 44 | String geohash; 45 | GeoHashPoint o1; 46 | GeoHashPoint o2; 47 | 48 | geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); 49 | 50 | o1 = new GeoHashPoint(geohash); 51 | o2 = new GeoHashPoint(geohash); 52 | actual = o1.compareTo(o2); 53 | expected = actual == 0; 54 | assertTrue(expected); 55 | } 56 | 57 | /** 58 | * Test method for {@link Point} constructors 59 | */ 60 | @Test 61 | public final void testConstructors() 62 | { 63 | GeoHashPoint model; 64 | model = new GeoHashPoint(Double.valueOf(53.5526394d), Double.valueOf(10.0067103d)); 65 | assertNotNull(model); 66 | model = new GeoHashPoint(Float.valueOf(53.5526394f), Float.valueOf(10.0067103f)); 67 | assertNotNull(model); 68 | model = new GeoHashPoint(53.5526394f, 10.0067103f); 69 | assertNotNull(model); 70 | model = new GeoHashPoint( 71 | Point.builder().latitude(53.5526394d).longitude(10.0067103d).build()); 72 | assertNotNull(model); 73 | } 74 | 75 | /** 76 | * Test method for {@link GeoHashPoint#equals(Object)} , {@link GeoHashPoint#hashCode()} and 77 | * {@link GeoHashPoint#toString()} 78 | */ 79 | @Test 80 | public void verifyEqualsHashcodeAndToStringWithClass() 81 | { 82 | ContractVerifier.of(GeoHashPoint.class).verify(); 83 | } 84 | 85 | /** 86 | * Test method for {@link GeoHashPoint#getLat()}. 87 | */ 88 | @Test 89 | public void testGetLat() 90 | { 91 | BigDecimal actual; 92 | BigDecimal expected; 93 | GeoHashPoint model; 94 | model = new GeoHashPoint(Double.valueOf(53.5526394d), Double.valueOf(10.0067103d)); 95 | actual = model.getLat(); 96 | expected = BigDecimal.valueOf(Double.valueOf(53.5526394d)); 97 | assertEquals(expected, actual); 98 | } 99 | 100 | /** 101 | * Test method for {@link GeoHashPoint#getLng()}. 102 | */ 103 | @Test 104 | public void testGetLng() 105 | { 106 | BigDecimal actual; 107 | BigDecimal expected; 108 | GeoHashPoint model; 109 | model = new GeoHashPoint(Double.valueOf(53.5526394d), Double.valueOf(10.0067103d)); 110 | actual = model.getLng(); 111 | expected = BigDecimal.valueOf(Double.valueOf(10.0067103d)); 112 | assertEquals(expected, actual); 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /jgeohash-core/src/main/java/de/alpharogroup/jgeohash/Point.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash; 17 | 18 | import de.alpharogroup.jgeohash.api.Position; 19 | import lombok.Builder; 20 | import lombok.EqualsAndHashCode; 21 | 22 | /** 23 | * The class {@link Point} represents a point on earth with the latitude and longitude. 24 | */ 25 | @EqualsAndHashCode 26 | @Builder(toBuilder = true) 27 | public class Point implements Comparable, Cloneable, Position 28 | { 29 | 30 | /** 31 | * The serialVersionUID. 32 | */ 33 | private static final long serialVersionUID = -4799959551221362673L; 34 | 35 | /** The latitude. */ 36 | private double latitude; 37 | 38 | /** The longitude. */ 39 | private double longitude; 40 | 41 | /** 42 | * Instantiates a new {@link Point} object. 43 | * 44 | * @param latitude 45 | * the latitude 46 | * @param longitude 47 | * the longitude 48 | */ 49 | public Point(final double latitude, final double longitude) 50 | { 51 | if (Math.abs(latitude) > 90 || Math.abs(longitude) > 180) 52 | { 53 | throw new IllegalArgumentException( 54 | "The given coordinates " + this.toString() + " are out of range."); 55 | } 56 | this.latitude = latitude; 57 | this.longitude = longitude; 58 | } 59 | 60 | /** 61 | * {@inheritDoc} 62 | */ 63 | @Override 64 | public Object clone() 65 | { 66 | final Position inst = new Point(this.latitude, this.longitude); 67 | return inst; 68 | } 69 | 70 | /** 71 | * {@inheritDoc} 72 | */ 73 | @Override 74 | public int compareTo(final Point other) 75 | { 76 | if (this == other) 77 | { 78 | return 0; 79 | } 80 | if (this.latitude < other.latitude) 81 | { 82 | return -1; 83 | } 84 | if (this.latitude > other.latitude) 85 | { 86 | return 1; 87 | } 88 | if (this.longitude < other.longitude) 89 | { 90 | return -1; 91 | } 92 | if (this.longitude > other.longitude) 93 | { 94 | return 1; 95 | } 96 | // all comparisons have yielded equality 97 | // verify that compareTo is consistent with equals (optional) 98 | assert this.equals(other) : "compareTo inconsistent with equals."; 99 | return 0; 100 | } 101 | 102 | /** 103 | * {@inheritDoc} 104 | */ 105 | @Override 106 | public double getLatitude() 107 | { 108 | return latitude; 109 | } 110 | 111 | /** 112 | * {@inheritDoc} 113 | */ 114 | @Override 115 | public double getLongitude() 116 | { 117 | return longitude; 118 | } 119 | 120 | /** 121 | * {@inheritDoc} 122 | */ 123 | @Override 124 | public void setLatitude(final double latitude) 125 | { 126 | if (Math.abs(latitude) > 90) 127 | { 128 | throw new IllegalArgumentException( 129 | "The given coordinates for latitude " + latitude + " are out of range."); 130 | } 131 | this.latitude = latitude; 132 | } 133 | 134 | /** 135 | * {@inheritDoc} 136 | */ 137 | @Override 138 | public void setLongitude(final double longitude) 139 | { 140 | if (Math.abs(longitude) > 180) 141 | { 142 | throw new IllegalArgumentException( 143 | "The given coordinates for longitude " + longitude + " are out of range."); 144 | } 145 | this.longitude = longitude; 146 | } 147 | 148 | /** 149 | * {@inheritDoc} 150 | */ 151 | @Override 152 | public String toString() 153 | { 154 | return "Latitude : " + latitude + " Longitude : " + longitude; 155 | } 156 | 157 | } 158 | -------------------------------------------------------------------------------- /jgeohash-core/src/main/java/de/alpharogroup/jgeohash/distance/DistanceCalculator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.distance; 17 | 18 | import static java.lang.Math.acos; 19 | import static java.lang.Math.cos; 20 | import static java.lang.Math.sin; 21 | import static java.lang.Math.toDegrees; 22 | import static java.lang.Math.toRadians; 23 | 24 | import de.alpharogroup.jgeohash.GeoHashPoint; 25 | import de.alpharogroup.jgeohash.api.Position; 26 | import lombok.experimental.UtilityClass; 27 | 28 | /** 29 | * The class {@link DistanceCalculator} provides methods for calculate the distance between two 30 | * geohash, position or coordinate values. 31 | */ 32 | @UtilityClass 33 | public final class DistanceCalculator 34 | { 35 | 36 | /** 37 | * Returns the distance from the given coordinates values. 38 | * 39 | * @param startLatitude 40 | * the latitude from start point. 41 | * @param startLongitude 42 | * the longitude from start point. 43 | * @param endLatitude 44 | * the latitude from end point. 45 | * @param endLongitude 46 | * the longitude from end point. 47 | * @param unit 48 | * the measurement unit 49 | * @return the distance between the given coordinates values. 50 | */ 51 | public static double distance(final double startLatitude, final double startLongitude, 52 | final double endLatitude, final double endLongitude, final MeasuringUnit unit) 53 | { 54 | final double theta = toRadians(startLongitude - endLongitude); 55 | final double latitudePoint1 = toRadians(startLatitude); 56 | final double latitudePoint2 = toRadians(endLatitude); 57 | double distance = sin(latitudePoint1) * sin(latitudePoint2) 58 | + cos(latitudePoint1) * cos(latitudePoint2) * cos(theta); 59 | // 60 is the number of minutes in a degree 60 | // 1.1515 is the number of statute miles in a nautical mile 61 | // One nautical mile is the length of one minute of latitude at the equator. 62 | distance = toDegrees(acos(distance)) * 60 * 1.1515; 63 | switch (unit) 64 | { 65 | case MILE : 66 | distance = distance * unit.getFactor(); 67 | break; 68 | case KILOMETER : 69 | distance = distance * unit.getFactor(); 70 | break; 71 | case METER : 72 | distance = distance * unit.getFactor(); 73 | break; 74 | } 75 | return distance; 76 | } 77 | 78 | /** 79 | * Returns the distance between two points. 80 | * 81 | * @param start 82 | * the start position. 83 | * @param end 84 | * the end position. 85 | * @param unit 86 | * the measurement unit 87 | * @return the distance between points 88 | */ 89 | public static double distanceBetweenPoints(final Position start, final Position end, 90 | final MeasuringUnit unit) 91 | { 92 | final double distance = distance(start.getLatitude(), start.getLongitude(), 93 | end.getLatitude(), end.getLongitude(), unit); 94 | return distance; 95 | } 96 | 97 | /** 98 | * Returns the distance between two given geohash values. 99 | * 100 | * @param startGeohashValue 101 | * the geohash value from where to start the measurement. 102 | * @param endGeohashValue 103 | * the geohash value where to end the measurement. 104 | * @param unit 105 | * the measurement unit 106 | * @return the distance between the given geohash values. 107 | */ 108 | public static double distanceBetweenPoints(final String startGeohashValue, 109 | final String endGeohashValue, final MeasuringUnit unit) 110 | { 111 | return distanceBetweenPoints(new GeoHashPoint(startGeohashValue), 112 | new GeoHashPoint(endGeohashValue), unit); 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /jgeohash-core/src/test/java/de/alpharogroup/jgeohash/model/SectionComparatorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.model; 17 | 18 | import java.util.Comparator; 19 | import java.util.List; 20 | 21 | import org.meanbean.test.BeanTester; 22 | import org.testng.annotations.Test; 23 | 24 | import de.alpharogroup.BaseComparatorTestCase; 25 | import de.alpharogroup.collections.list.ListFactory; 26 | import lombok.AccessLevel; 27 | import lombok.experimental.FieldDefaults; 28 | 29 | /** 30 | * The unit test class for the class {@link SectionComparator} 31 | */ 32 | @FieldDefaults(level = AccessLevel.PRIVATE) 33 | public class SectionComparatorTest extends BaseComparatorTestCase
34 | { 35 | 36 | Section first = Section.builder().start(10).end(12).build(); 37 | Section fourth = Section.builder().start(0).end(2).build(); 38 | Section second = Section.builder().start(8).end(13).build(); 39 | Section third = Section.builder().start(17).end(19).build(); 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | @Override 45 | protected List
newActualList() 46 | { 47 | List
actual = ListFactory.newArrayList(first, second, third, fourth); 48 | return actual; 49 | } 50 | 51 | /** 52 | * {@inheritDoc} 53 | */ 54 | @Override 55 | protected Comparator
newComparator() 56 | { 57 | return new SectionComparator(); 58 | } 59 | 60 | /** 61 | * {@inheritDoc} 62 | */ 63 | @Override 64 | protected List
newExpectedSortedList() 65 | { 66 | List
expected = ListFactory.newArrayList(third, first, second, fourth); 67 | return expected; 68 | } 69 | 70 | /** 71 | * {@inheritDoc} 72 | */ 73 | @Override 74 | protected List
newExpectedUnsortedList() 75 | { 76 | List
expected = ListFactory.newArrayList(first, second, third, fourth); 77 | return expected; 78 | } 79 | 80 | /** 81 | * {@inheritDoc} 82 | */ 83 | @Override 84 | protected Section newO1Equal() 85 | { 86 | return Section.builder().start(0).end(2).build(); 87 | } 88 | 89 | /** 90 | * {@inheritDoc} 91 | */ 92 | @Override 93 | protected Section newO1GreaterThan() 94 | { 95 | return Section.builder().start(0).end(2).build(); 96 | } 97 | 98 | /** 99 | * {@inheritDoc} 100 | */ 101 | @Override 102 | protected Section newO1LessThan() 103 | { 104 | return Section.builder().start(1).end(2).build(); 105 | } 106 | 107 | /** 108 | * {@inheritDoc} 109 | */ 110 | @Override 111 | protected Section newO2Equal() 112 | { 113 | return newO1Equal(); 114 | } 115 | 116 | 117 | /** 118 | * {@inheritDoc} 119 | */ 120 | @Override 121 | protected Section newO2GreaterThan() 122 | { 123 | return Section.builder().start(1).end(2).build(); 124 | } 125 | 126 | /** 127 | * {@inheritDoc} 128 | */ 129 | @Override 130 | protected Section newO2LessThan() 131 | { 132 | return Section.builder().start(0).end(2).build(); 133 | } 134 | 135 | /** 136 | * {@inheritDoc} 137 | */ 138 | @Override 139 | @Test 140 | public void testCompare() 141 | { 142 | super.testCompare(); 143 | } 144 | 145 | /** 146 | * {@inheritDoc} 147 | */ 148 | @Override 149 | @Test 150 | public void testEqual() 151 | { 152 | super.testEqual(); 153 | } 154 | 155 | /** 156 | * {@inheritDoc} 157 | */ 158 | @Override 159 | @Test 160 | public void testGreaterThan() 161 | { 162 | super.testGreaterThan(); 163 | } 164 | 165 | /** 166 | * {@inheritDoc} 167 | */ 168 | @Override 169 | @Test 170 | public void testLessThan() 171 | { 172 | super.testLessThan(); 173 | } 174 | 175 | /** 176 | * Test method for {@link SectionComparator} 177 | */ 178 | @Test 179 | public void testWithBeanTester() 180 | { 181 | final BeanTester beanTester = new BeanTester(); 182 | beanTester.testBean(SectionComparator.class); 183 | } 184 | 185 | } 186 | -------------------------------------------------------------------------------- /jgeohash-core/src/main/java/de/alpharogroup/jgeohash/GeoHashPoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash; 17 | 18 | import java.math.BigDecimal; 19 | 20 | import de.alpharogroup.jgeohash.api.Position; 21 | import lombok.EqualsAndHashCode; 22 | 23 | /** 24 | * The class {@link GeoHashPoint}. 25 | */ 26 | @EqualsAndHashCode(callSuper = true) 27 | public class GeoHashPoint extends Point 28 | { 29 | 30 | /** The Constant GEOHASH_KEY. */ 31 | public static final String GEOHASH_KEY = "GEOHASH_KEY"; 32 | 33 | /** 34 | * The serialVersionUID. 35 | */ 36 | private static final long serialVersionUID = -3580536765079661097L; 37 | 38 | /** 39 | * Instantiates a new {@link GeoHashPoint}. 40 | * 41 | * @param latitude 42 | * the latitude 43 | * @param longitude 44 | * the longitude 45 | */ 46 | public GeoHashPoint(final double latitude, final double longitude) 47 | { 48 | super(latitude, longitude); 49 | } 50 | 51 | /** 52 | * Instantiates a new {@link GeoHashPoint}. 53 | * 54 | * @param latitude 55 | * the latitude 56 | * @param longitude 57 | * the longitude 58 | */ 59 | public GeoHashPoint(final Double latitude, final Double longitude) 60 | { 61 | super(latitude, longitude); 62 | } 63 | 64 | /** 65 | * Instantiates a new {@link GeoHashPoint}. 66 | * 67 | * @param latitude 68 | * the latitude 69 | * @param longitude 70 | * the longitude 71 | */ 72 | public GeoHashPoint(final float latitude, final float longitude) 73 | { 74 | this(Float.toString(latitude), Float.toString(longitude)); 75 | } 76 | 77 | /** 78 | * Instantiates a new {@link GeoHashPoint}. 79 | * 80 | * @param position 81 | * the position 82 | */ 83 | public GeoHashPoint(final Position position) 84 | { 85 | this(position.getLatitude(), position.getLongitude()); 86 | } 87 | 88 | /** 89 | * Instantiates a new {@link GeoHashPoint}. 90 | * 91 | * @param geohash 92 | * the Geohash code. 93 | */ 94 | public GeoHashPoint(final String geohash) 95 | { 96 | super(GeoHashExtensions.decode(geohash)[0], GeoHashExtensions.decode(geohash)[1]); 97 | } 98 | 99 | /** 100 | * Instantiates a new {@link GeoHashPoint}. 101 | * 102 | * @param lat 103 | * the latitude as String object. 104 | * @param lng 105 | * the longitude as String object. 106 | */ 107 | public GeoHashPoint(final String lat, final String lng) 108 | { 109 | super(Double.parseDouble(lat), Double.parseDouble(lng)); 110 | } 111 | 112 | /** 113 | * {@inheritDoc} 114 | */ 115 | @Override 116 | public Object clone() 117 | { 118 | return new GeoHashPoint(getLatitude(), getLongitude()); 119 | } 120 | 121 | /** 122 | * Gets the geohash. 123 | * 124 | * @return the geohash 125 | */ 126 | public String getGeohash() 127 | { 128 | return GeoHashExtensions.encode(getLatitude(), getLongitude()); 129 | } 130 | 131 | /** 132 | * Gets the latitude as BigDecimal object. 133 | * 134 | * @return the latitude as BigDecimal object. 135 | */ 136 | public BigDecimal getLat() 137 | { 138 | return BigDecimal.valueOf(getLatitude()); 139 | } 140 | 141 | /** 142 | * Gets the longitude as BigDecimal object. 143 | * 144 | * @return the longitude as BigDecimal object. 145 | */ 146 | public BigDecimal getLng() 147 | { 148 | return BigDecimal.valueOf(getLongitude()); 149 | } 150 | 151 | /** 152 | * {@inheritDoc} 153 | */ 154 | @Override 155 | public String toString() 156 | { 157 | final StringBuilder buffer = new StringBuilder(); 158 | buffer.append("[GeoHashPoint:"); 159 | buffer.append(super.toString()); 160 | buffer.append(" Geohash : "); 161 | buffer.append(getGeohash()); 162 | buffer.append("]"); 163 | return buffer.toString(); 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /jgeohash-core/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | dependencies { 3 | implementation("de.alpharogroup:merge-api:$mergeApiVersion") 4 | } 5 | 6 | license { 7 | ext.year="$projectInceptionYear" 8 | ext.owner="$projectLeaderName" 9 | header rootProject.file('src/main/resources/LICENSE.txt') 10 | excludes(["**/README", 11 | "**/README.md", 12 | "**/LICENSE", 13 | "**/NOTICE", 14 | "**/*.xml", 15 | "**/*.xsl", 16 | "**/*.xsd", 17 | "**/*.dtd", 18 | "**/*.html", 19 | "**/*.jsp", 20 | "**/*.jpa", 21 | "**/*.sql", 22 | "**/*.properties", 23 | "**/*.bat", 24 | "**/*.gradle", 25 | "**/*.MF", 26 | "**/*.txt", 27 | "**/*.vm", 28 | "**/*.log", 29 | "**/*.map", 30 | "**/*.js.map", 31 | "**/*.tmpl", 32 | "**/*.js.tmpl", 33 | "**/*.editorconfig", 34 | "**/*.lombok.config", 35 | "src/test/resources/**", 36 | "src/main/resources/**", 37 | "out/**", 38 | "build/**"]) 39 | } 40 | 41 | task sourcesJar(type: Jar) { 42 | archiveClassifier.set("sources") 43 | from(sourceSets.main.allJava) 44 | } 45 | 46 | task javadocJar(type: Jar) { 47 | from javadoc 48 | archiveClassifier.set("javadoc") 49 | javadoc.properties.failOnError = true 50 | } 51 | 52 | def releaseVersion = !version.endsWith("SNAPSHOT") 53 | 54 | publishing { 55 | publications { 56 | mavenJava(MavenPublication) { 57 | artifactId = "$project.name" 58 | from components.java 59 | artifact sourcesJar 60 | artifact javadocJar 61 | pom { 62 | name = "$project.name" 63 | description = "$projectCoreDescription" 64 | url = "$projectScmProviderUrl"+"$projectHolderUsername"+"$slash"+"$rootProject.name" 65 | organization { 66 | name = "$projectOrganizationName" 67 | url = "$projectOrganizationUrl" 68 | } 69 | issueManagement { 70 | system = "$projectIssueManagementSystem" 71 | url = "$projectScmProviderUrl"+"$projectHolderUsername"+"$slash"+"$rootProject.name"+"$issuesPath" 72 | } 73 | licenses { 74 | license { 75 | name = "$projectLicenseName" 76 | url = "$projectLicenseUrl" 77 | distribution = "$projectLicenseDistribution" 78 | } 79 | } 80 | developers { 81 | developer { 82 | id = "$projectHolderUsername" 83 | name = "$projectLeaderName" 84 | } 85 | } 86 | scm { 87 | connection = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" 88 | developerConnection = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" 89 | url = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" 90 | } 91 | } 92 | } 93 | } 94 | repositories { 95 | if (releaseVersion) { 96 | maven { 97 | credentials { 98 | username System.getenv("$projectRepositoriesUserNameKey") ?: project.property("$projectRepositoriesUserNameKey") 99 | password System.getenv("$projectRepositoriesPasswordKey") ?: project.property("$projectRepositoriesPasswordKey") 100 | } 101 | def releasesRepoUrl = "$projectRepositoriesReleasesRepoUrl" 102 | def snapshotsRepoUrl = "$projectRepositoriesSnapshotsRepoUrl" 103 | url = releaseVersion ? releasesRepoUrl : snapshotsRepoUrl 104 | } 105 | } 106 | } 107 | } 108 | 109 | signing { 110 | if (releaseVersion) { 111 | sign publishing.publications.mavenJava 112 | } 113 | } 114 | 115 | 116 | -------------------------------------------------------------------------------- /jgeohash-geoip/src/test/java/de/alpharogroup/jgeohash/geoip/LocationExtensionsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.geoip; 17 | 18 | import static org.testng.AssertJUnit.assertEquals; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | import org.meanbean.factories.ObjectCreationException; 24 | import org.meanbean.test.BeanTestException; 25 | import org.meanbean.test.BeanTester; 26 | import org.testng.annotations.Test; 27 | 28 | import de.alpharogroup.collections.list.ListFactory; 29 | import de.alpharogroup.jgeohash.GeoHashPoint; 30 | import de.alpharogroup.jgeohash.api.Position; 31 | import de.alpharogroup.jgeohash.distance.MeasuringUnit; 32 | 33 | /** 34 | * The unit test class for the class {@link LocationExtensions}. 35 | */ 36 | public class LocationExtensionsTest 37 | { 38 | 39 | /** 40 | * Test method for {@link LocationExtensions#sortByDistance(Position, List, MeasuringUnit)} 41 | */ 42 | @Test 43 | public void testSortByDistance() 44 | { 45 | List geohashes = new ArrayList<>(); 46 | geohashes.add(new GeoHashPoint("u0vf2w1s5tsy")); 47 | geohashes.add(new GeoHashPoint("u0t3z7cnznrx")); 48 | geohashes.add(new GeoHashPoint("u0td0v9xnz28")); 49 | Position startPoint = new GeoHashPoint("u11fyhzqhp3c"); 50 | 51 | LocationExtensions.sortByDistance(startPoint, geohashes, MeasuringUnit.METER); 52 | 53 | geohashes = new ArrayList<>(); 54 | geohashes.add(new GeoHashPoint("u0z4")); // below Wuerzburg 55 | geohashes.add(new GeoHashPoint("u1p1")); // right from Bad Hersfeld 56 | geohashes.add(new GeoHashPoint("u28j")); // Ingolstadt 57 | geohashes.add(new GeoHashPoint("u0zc4wp0k")); // Nurremberg at work 58 | startPoint = new GeoHashPoint("u0ww"); // Ludwigsburg 59 | 60 | LocationExtensions.sortByDistance(startPoint, geohashes, MeasuringUnit.METER); 61 | } 62 | 63 | /** 64 | * Test method for {@link LocationExtensions#sortByDistanceInMeters(Position, List)} 65 | */ 66 | @Test 67 | public void testSortByDistanceInMeters() 68 | { 69 | List actual; 70 | List expected; 71 | List geohashes = ListFactory.newArrayList(); 72 | geohashes.add(new GeoHashPoint("u0vf2w1s5tsy")); 73 | geohashes.add(new GeoHashPoint("u0t3z7cnznrx")); 74 | geohashes.add(new GeoHashPoint("u0td0v9xnz28")); 75 | Position startPoint = new GeoHashPoint("u11fyhzqhp3c"); 76 | 77 | actual = LocationExtensions.sortByDistanceInMeters(startPoint, geohashes); 78 | expected = ListFactory.newArrayList(new GeoHashPoint("u0vf2w1s5tsy"), 79 | new GeoHashPoint("u0td0v9xnz28"), new GeoHashPoint("u0t3z7cnznrx")); 80 | for (int i = 0; i < actual.size(); i++) 81 | { 82 | assertEquals(expected.get(i), actual.get(i)); 83 | } 84 | 85 | geohashes = ListFactory.newArrayList(); 86 | geohashes.add(new GeoHashPoint("u0z4")); // below Wuerzburg 87 | geohashes.add(new GeoHashPoint("u1p1")); // right from Bad Hersfeld 88 | geohashes.add(new GeoHashPoint("u28j")); // Ingolstadt 89 | geohashes.add(new GeoHashPoint("u0zc4wp0k")); // Nurremberg at work 90 | startPoint = new GeoHashPoint("u0ww"); // Ludwigsburg 91 | 92 | actual = LocationExtensions.sortByDistanceInMeters(startPoint, geohashes); 93 | expected = ListFactory.newArrayList(new GeoHashPoint(49.658203125d, 10.01953125d), 94 | new GeoHashPoint(49.42755460739136d, 11.018106937408447d), 95 | new GeoHashPoint(48.779296875d, 11.42578125d), 96 | new GeoHashPoint(50.888671875d, 10.01953125d)); 97 | for (int i = 0; i < actual.size(); i++) 98 | { 99 | assertEquals(expected.get(i), actual.get(i)); 100 | } 101 | } 102 | 103 | /** 104 | * Test method for {@link LocationExtensions} 105 | */ 106 | @Test(expectedExceptions = { BeanTestException.class, ObjectCreationException.class }) 107 | public void testWithBeanTester() 108 | { 109 | final BeanTester beanTester = new BeanTester(); 110 | beanTester.testBean(LocationExtensions.class); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /jgeohash-geoip/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | dependencies { 3 | implementation project(':jgeohash-core') 4 | implementation("com.maxmind.geoip:geoip-api:$geoipApiVersion") 5 | implementation("de.alpharogroup:jcommons-lang:$jcommonsLangVersion") 6 | } 7 | 8 | license { 9 | ext.year="$projectInceptionYear" 10 | ext.owner="$projectLeaderName" 11 | header rootProject.file('src/main/resources/LICENSE.txt') 12 | excludes(["**/README", 13 | "**/README.md", 14 | "**/LICENSE", 15 | "**/NOTICE", 16 | "**/*.xml", 17 | "**/*.xsl", 18 | "**/*.xsd", 19 | "**/*.dtd", 20 | "**/*.html", 21 | "**/*.jsp", 22 | "**/*.jpa", 23 | "**/*.sql", 24 | "**/*.properties", 25 | "**/*.bat", 26 | "**/*.gradle", 27 | "**/*.MF", 28 | "**/*.txt", 29 | "**/*.vm", 30 | "**/*.log", 31 | "**/*.map", 32 | "**/*.js.map", 33 | "**/*.tmpl", 34 | "**/*.js.tmpl", 35 | "**/*.editorconfig", 36 | "**/*.lombok.config", 37 | "src/test/resources/**", 38 | "src/main/resources/**", 39 | "out/**", 40 | "build/**"]) 41 | } 42 | 43 | task sourcesJar(type: Jar) { 44 | archiveClassifier.set("sources") 45 | from(sourceSets.main.allJava) 46 | } 47 | 48 | task javadocJar(type: Jar) { 49 | from javadoc 50 | archiveClassifier.set("javadoc") 51 | javadoc.properties.failOnError = true 52 | } 53 | 54 | def releaseVersion = !version.endsWith("SNAPSHOT") 55 | 56 | publishing { 57 | publications { 58 | mavenJava(MavenPublication) { 59 | artifactId = "$project.name" 60 | from components.java 61 | artifact sourcesJar 62 | artifact javadocJar 63 | pom { 64 | name = "$project.name" 65 | description = "$projectGeoipDescription" 66 | url = "$projectScmProviderUrl"+"$projectHolderUsername"+"$slash"+"$rootProject.name" 67 | organization { 68 | name = "$projectOrganizationName" 69 | url = "$projectOrganizationUrl" 70 | } 71 | issueManagement { 72 | system = "$projectIssueManagementSystem" 73 | url = "$projectScmProviderUrl"+"$projectHolderUsername"+"$slash"+"$rootProject.name"+"$issuesPath" 74 | } 75 | licenses { 76 | license { 77 | name = "$projectLicenseName" 78 | url = "$projectLicenseUrl" 79 | distribution = "$projectLicenseDistribution" 80 | } 81 | } 82 | developers { 83 | developer { 84 | id = "$projectHolderUsername" 85 | name = "$projectLeaderName" 86 | } 87 | } 88 | scm { 89 | connection = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" 90 | developerConnection = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" 91 | url = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" 92 | } 93 | } 94 | } 95 | } 96 | repositories { 97 | if (releaseVersion) { 98 | maven { 99 | credentials { 100 | username System.getenv("$projectRepositoriesUserNameKey") ?: project.property("$projectRepositoriesUserNameKey") 101 | password System.getenv("$projectRepositoriesPasswordKey") ?: project.property("$projectRepositoriesPasswordKey") 102 | } 103 | def releasesRepoUrl = "$projectRepositoriesReleasesRepoUrl" 104 | def snapshotsRepoUrl = "$projectRepositoriesSnapshotsRepoUrl" 105 | url = releaseVersion ? releasesRepoUrl : snapshotsRepoUrl 106 | } 107 | } 108 | } 109 | } 110 | 111 | signing { 112 | if (releaseVersion) { 113 | sign publishing.publications.mavenJava 114 | } 115 | } 116 | 117 | 118 | -------------------------------------------------------------------------------- /jgeohash-core/src/test/java/de/alpharogroup/jgeohash/model/SectionizerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.model; 17 | 18 | import static org.testng.AssertJUnit.assertEquals; 19 | 20 | import java.util.List; 21 | 22 | import org.testng.annotations.Test; 23 | 24 | import de.alpharogroup.collections.list.ListFactory; 25 | 26 | /** 27 | * The unit test class for the class {@link Sectionizer} 28 | */ 29 | public class SectionizerTest 30 | { 31 | 32 | /** 33 | * Test method for {@link Sectionizer#getMaxIteration()}. 34 | */ 35 | @Test 36 | public void testGetMaxIteration() 37 | { 38 | int actual; 39 | int expected; 40 | Sectionizer sectionizer; 41 | sectionizer = Sectionizer.builder().build(); 42 | 43 | actual = sectionizer.getMaxIteration(); 44 | expected = Sectionizer.DEFAULT_MAX_ITERATION; 45 | assertEquals(expected, actual); 46 | } 47 | 48 | 49 | /** 50 | * Test method for {@link Sectionizer#merge(Section, Section)} 51 | */ 52 | @Test 53 | public void testMerge() 54 | { 55 | Section expected; 56 | Section actual; 57 | Section foo; 58 | Section bar; 59 | Sectionizer sectionizer; 60 | sectionizer = Sectionizer.builder().build(); 61 | 62 | // no left match case... 63 | foo = Section.builder().start(23).end(45).build(); 64 | bar = Section.builder().start(13).end(21).build(); 65 | expected = foo; 66 | actual = sectionizer.merge(foo, bar); 67 | assertEquals(expected, actual); 68 | 69 | // no right match case... 70 | foo = Section.builder().start(23).end(45).build(); 71 | bar = Section.builder().start(47).end(57).build(); 72 | expected = foo; 73 | actual = sectionizer.merge(foo, bar); 74 | assertEquals(expected, actual); 75 | 76 | // is between match case... 77 | foo = Section.builder().start(23).end(45).build(); 78 | bar = Section.builder().start(13).end(65).build(); 79 | expected = bar; 80 | actual = sectionizer.merge(foo, bar); 81 | assertEquals(expected, actual); 82 | 83 | // is left overlapping match case... 84 | foo = Section.builder().start(23).end(45).build(); 85 | bar = Section.builder().start(13).end(35).build(); 86 | expected = Section.builder().start(13).end(45).build(); 87 | actual = sectionizer.merge(foo, bar); 88 | assertEquals(expected, actual); 89 | 90 | // is right overlapping match case... 91 | foo = Section.builder().start(23).end(45).build(); 92 | bar = Section.builder().start(42).end(57).build(); 93 | expected = Section.builder().start(23).end(57).build(); 94 | actual = sectionizer.merge(foo, bar); 95 | assertEquals(expected, actual); 96 | 97 | // is to left match case... 98 | foo = Section.builder().start(23).end(45).build(); 99 | bar = Section.builder().start(13).end(22).build(); 100 | expected = Section.builder().start(13).end(45).build(); 101 | actual = sectionizer.merge(foo, bar); 102 | assertEquals(expected, actual); 103 | 104 | // is to right match case... 105 | foo = Section.builder().start(23).end(45).build(); 106 | bar = Section.builder().start(46).end(57).build(); 107 | expected = Section.builder().start(23).end(57).build(); 108 | actual = sectionizer.merge(foo, bar); 109 | assertEquals(expected, actual); 110 | } 111 | 112 | /** 113 | * Test method for {@link Sectionizer#merge(List)}. 114 | */ 115 | @Test 116 | public void testMergeListOfSection() 117 | { 118 | List
expected; 119 | List
actual; 120 | List
sections; 121 | 122 | sections = ListFactory.newArrayList(Section.builder().start(23).end(45).build(), 123 | Section.builder().start(13).end(21).build(), 124 | Section.builder().start(46).end(57).build()); 125 | Sectionizer sectionizer = new Sectionizer(10000); 126 | actual = sectionizer.merge(sections); 127 | expected = ListFactory.newArrayList(Section.builder().start(23).end(57).build(), 128 | Section.builder().start(13).end(21).build()); 129 | for (int i = 0; i < actual.size(); i++) 130 | { 131 | assertEquals(expected.get(i), actual.get(i)); 132 | } 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /jgeohash-core/src/test/java/de/alpharogroup/jgeohash/distance/DistanceCalculatorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.distance; 17 | 18 | import static org.testng.AssertJUnit.assertEquals; 19 | 20 | import java.util.Map; 21 | 22 | import org.meanbean.factories.ObjectCreationException; 23 | import org.meanbean.test.BeanTestException; 24 | import org.meanbean.test.BeanTester; 25 | import org.testng.annotations.Test; 26 | 27 | import de.alpharogroup.jgeohash.Adjacent; 28 | import de.alpharogroup.jgeohash.GeoHashExtensions; 29 | import de.alpharogroup.jgeohash.GeoHashPoint; 30 | import de.alpharogroup.jgeohash.Point; 31 | import de.alpharogroup.jgeohash.api.Position; 32 | 33 | /** 34 | * The unit test class for the class {@link DistanceCalculator}. 35 | */ 36 | public class DistanceCalculatorTest 37 | { 38 | 39 | /** 40 | * Test method for 41 | * {@link DistanceCalculator#distanceBetweenPoints(Position, Position, MeasuringUnit)} 42 | */ 43 | @Test(enabled = true) 44 | public void testDistanceBetweenPointsPositionPositionMeasuringUnit() 45 | { 46 | double actual; 47 | double expected; 48 | 49 | final String alterTeichwegGeohash = "u1x0v54rmjwej"; 50 | final double[] coordinates = GeoHashExtensions.decodeAndRound(alterTeichwegGeohash); 51 | final Position alterTeichweg = new Point(coordinates[0], coordinates[1]); 52 | final Position ludwigsburg = new GeoHashPoint(48.889380, 9.190459); 53 | 54 | actual = DistanceCalculator.distanceBetweenPoints(ludwigsburg, alterTeichweg, 55 | MeasuringUnit.KILOMETER); 56 | expected = 525.875517661088d; 57 | assertEquals(expected, actual); 58 | } 59 | 60 | /** 61 | * Test method for 62 | * {@link DistanceCalculator#distanceBetweenPoints(String, String, MeasuringUnit)} 63 | */ 64 | @Test(enabled = true) 65 | public void testDistanceBetweenPointsStringStringMeasuringUnit() 66 | { 67 | double actual; 68 | double expected; 69 | 70 | final String alterTeichwegGeohash = "u1x0v54rmjwej"; 71 | final String subGeohash = alterTeichwegGeohash.substring(0, 1); 72 | final Map firstRingCells = GeoHashExtensions 73 | .getAllAdjacentAreasMap(subGeohash); 74 | final Position ludwigsburg = new GeoHashPoint(48.889380, 9.190459); 75 | final String ludwigsburgGeohash = ((GeoHashPoint)ludwigsburg).getGeohash(); 76 | 77 | actual = DistanceCalculator.distanceBetweenPoints(ludwigsburgGeohash, alterTeichwegGeohash, 78 | MeasuringUnit.KILOMETER); 79 | expected = 525.875517737948d; 80 | assertEquals(expected, actual); 81 | 82 | actual = DistanceCalculator.distanceBetweenPoints(ludwigsburgGeohash, alterTeichwegGeohash, 83 | MeasuringUnit.METER); 84 | expected = 525875.517737948d; 85 | assertEquals(expected, actual); 86 | 87 | actual = DistanceCalculator.distanceBetweenPoints(firstRingCells.get(Adjacent.CENTER), 88 | firstRingCells.get(Adjacent.RIGHT), MeasuringUnit.KILOMETER); 89 | expected = 1872.667779425215d; 90 | assertEquals(expected, actual); 91 | 92 | actual = DistanceCalculator.distanceBetweenPoints(firstRingCells.get(Adjacent.CENTER), 93 | firstRingCells.get(Adjacent.BOTTOM), MeasuringUnit.KILOMETER); 94 | expected = 5003.530963199998d; 95 | assertEquals(expected, actual); 96 | 97 | actual = DistanceCalculator.distanceBetweenPoints(firstRingCells.get(Adjacent.CENTER), 98 | firstRingCells.get(Adjacent.RIGHT), MeasuringUnit.MILE); 99 | expected = 1010.4891804690958d; 100 | assertEquals(expected, actual); 101 | 102 | actual = DistanceCalculator.distanceBetweenPoints(firstRingCells.get(Adjacent.CENTER), 103 | firstRingCells.get(Adjacent.BOTTOM), MeasuringUnit.MILE); 104 | expected = 2699.899019999999d; 105 | assertEquals(expected, actual); 106 | } 107 | 108 | /** 109 | * Test method for {@link DistanceCalculator} 110 | */ 111 | @Test(expectedExceptions = { BeanTestException.class, ObjectCreationException.class }) 112 | public void testWithBeanTester() 113 | { 114 | final BeanTester beanTester = new BeanTester(); 115 | beanTester.testBean(DistanceCalculator.class); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /jgeohash-core/src/main/java/de/alpharogroup/jgeohash/model/FirstAndSecondRingRegion.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.model; 17 | 18 | import de.alpharogroup.jgeohash.Adjacent; 19 | import de.alpharogroup.jgeohash.GeoHashExtensions; 20 | import lombok.EqualsAndHashCode; 21 | import lombok.Getter; 22 | import lombok.ToString; 23 | 24 | /** 25 | * The class {@link FirstAndSecondRingRegion} provides the neighbors from the given geohash value in 26 | * first and second ring. 27 | */ 28 | @Getter 29 | @EqualsAndHashCode(callSuper = true) 30 | @ToString(callSuper = true) 31 | public class FirstAndSecondRingRegion extends FirstRingRegion 32 | { 33 | 34 | /** The Constant serialVersionUID. */ 35 | private static final long serialVersionUID = -6668301917974379694L; 36 | 37 | /** The east east. */ 38 | private final String eastEast; 39 | 40 | /** The east north east. */ 41 | private final String eastNorthEast; 42 | 43 | /** The east south east. */ 44 | private final String eastSouthEast; 45 | 46 | /** The north east north east. */ 47 | private final String northEastNorthEast; 48 | 49 | /** The north north. */ 50 | private final String northNorth; 51 | 52 | /** The north north east. */ 53 | private final String northNorthEast; 54 | 55 | /** The north north west. */ 56 | private final String northNorthWest; 57 | 58 | /** The north west north west. */ 59 | private final String northWestNorthWest; 60 | 61 | /** The south east south east. */ 62 | private final String southEastSouthEast; 63 | 64 | /** The south south. */ 65 | private final String southSouth; 66 | 67 | /** The south south east. */ 68 | private final String southSouthEast; 69 | 70 | /** The south south west. */ 71 | private final String southSouthWest; 72 | 73 | /** The south west south west. */ 74 | private final String southWestSouthWest; 75 | 76 | /** The west north west. */ 77 | private final String westNorthWest; 78 | 79 | /** The west south west. */ 80 | private final String westSouthWest; 81 | 82 | /** The west west. */ 83 | private final String westWest; 84 | 85 | /** 86 | * Instantiates a new FirstAndSecondRingRegion from the given geohash value. 87 | * 88 | * @param geohash 89 | * the geohash 90 | */ 91 | public FirstAndSecondRingRegion(final String geohash) 92 | { 93 | super(geohash); 94 | northNorth = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP, Adjacent.TOP); 95 | northNorthWest = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP, Adjacent.LEFT, 96 | Adjacent.TOP); 97 | northWestNorthWest = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP, Adjacent.LEFT, 98 | Adjacent.TOP, Adjacent.LEFT); 99 | westNorthWest = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP, Adjacent.LEFT, 100 | Adjacent.LEFT); 101 | northNorthEast = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP, Adjacent.RIGHT, 102 | Adjacent.TOP); 103 | northEastNorthEast = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP, Adjacent.RIGHT, 104 | Adjacent.TOP, Adjacent.RIGHT); 105 | eastNorthEast = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP, Adjacent.RIGHT, 106 | Adjacent.RIGHT); 107 | eastEast = GeoHashExtensions.getAdjacent(geohash, Adjacent.RIGHT, Adjacent.RIGHT); 108 | eastSouthEast = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM, Adjacent.RIGHT, 109 | Adjacent.RIGHT); 110 | southSouthEast = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM, Adjacent.RIGHT, 111 | Adjacent.BOTTOM); 112 | southEastSouthEast = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM, Adjacent.RIGHT, 113 | Adjacent.BOTTOM, Adjacent.RIGHT); 114 | southSouth = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM, Adjacent.BOTTOM); 115 | southSouthWest = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM, Adjacent.LEFT, 116 | Adjacent.BOTTOM); 117 | southWestSouthWest = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM, Adjacent.LEFT, 118 | Adjacent.BOTTOM, Adjacent.LEFT); 119 | westSouthWest = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM, Adjacent.LEFT, 120 | Adjacent.LEFT); 121 | westWest = GeoHashExtensions.getAdjacent(geohash, Adjacent.LEFT, Adjacent.LEFT); 122 | } 123 | 124 | /** 125 | * {@inheritDoc} 126 | */ 127 | @Override 128 | public Object clone() 129 | { 130 | return new FirstAndSecondRingRegion(getCenter()); 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /jgeohash-geoip/src/main/java/de/alpharogroup/jgeohash/geoip/LocationExtensions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.geoip; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Collections; 20 | import java.util.List; 21 | 22 | import com.maxmind.geoip.Location; 23 | import com.maxmind.geoip.LookupService; 24 | 25 | import de.alpharogroup.jgeohash.GeoHashPoint; 26 | import de.alpharogroup.jgeohash.api.Position; 27 | import de.alpharogroup.jgeohash.distance.DistanceCalculator; 28 | import de.alpharogroup.jgeohash.distance.DistancePoint; 29 | import de.alpharogroup.jgeohash.distance.MeasuringUnit; 30 | import lombok.experimental.UtilityClass; 31 | 32 | /** 33 | * The class {@link LocationExtensions} is for location specific data. 34 | */ 35 | @UtilityClass 36 | public final class LocationExtensions 37 | { 38 | 39 | /** 40 | * Sort the given list by distance from the given start position and returns a list of 41 | * {@link DistancePoint} objects. 42 | * 43 | * @param startPoint 44 | * the start point 45 | * @param geohashes 46 | * the geohashes 47 | * @param unit 48 | * the unit 49 | * @return the distance points 50 | */ 51 | public static List getDistancePoints(final Position startPoint, 52 | final List geohashes, final MeasuringUnit unit) 53 | { 54 | final List distancePoints = new ArrayList<>(); 55 | for (final Position geoHashPoint : geohashes) 56 | { 57 | final DistancePoint distancePoint = new DistancePoint(geoHashPoint, 58 | DistanceCalculator.distanceBetweenPoints(startPoint, geoHashPoint, unit)); 59 | distancePoints.add(distancePoint); 60 | } 61 | return distancePoints; 62 | } 63 | 64 | /** 65 | * Gets the geohash from the given ip address or return an empty String if nothing is found. 66 | * 67 | * @param lookupService 68 | * the lookup service 69 | * @param ipAddress 70 | * the ip address 71 | * @return the geohash from ip address or an empty String if nothing is found. 72 | */ 73 | public static String getGeohashFromIpAddress(final LookupService lookupService, 74 | final String ipAddress) 75 | { 76 | final GeoHashPoint geoHashPoint = getGeoHashPoint(lookupService, ipAddress); 77 | if (geoHashPoint != null) 78 | { 79 | return geoHashPoint.getGeohash(); 80 | } 81 | return ""; 82 | } 83 | 84 | /** 85 | * Gets the {@link GeoHashPoint} object from the given ip address or return null if nothing is 86 | * found. 87 | * 88 | * @param lookupService 89 | * the lookup service 90 | * @param ipAddress 91 | * the ip address 92 | * @return the {@link GeoHashPoint} object from the given ip address or return null if nothing 93 | * is found. 94 | */ 95 | public static GeoHashPoint getGeoHashPoint(final LookupService lookupService, 96 | final String ipAddress) 97 | { 98 | final Location lc = lookupService.getLocation(ipAddress); 99 | if (lc != null) 100 | { 101 | return new GeoHashPoint(lc.latitude, lc.longitude); 102 | } 103 | return null; 104 | } 105 | 106 | /** 107 | * Sort the given list by distance from the given start position. 108 | * 109 | * @param startPoint 110 | * the start point 111 | * @param geohashes 112 | * the geohashes 113 | * @param unit 114 | * the unit 115 | * @return the list 116 | */ 117 | public static List sortByDistance(final Position startPoint, 118 | final List geohashes, final MeasuringUnit unit) 119 | { 120 | final List distancePoints = getDistancePoints(startPoint, geohashes, unit); 121 | Collections.sort(distancePoints); 122 | final List geosorted = new ArrayList<>(); 123 | for (int i = 0; i < distancePoints.size(); i++) 124 | { 125 | geosorted.add(distancePoints.get(i).getPoint()); 126 | } 127 | return geosorted; 128 | } 129 | 130 | /** 131 | * Sort the given list by distance from the given start position in meters. 132 | * 133 | * @param startPoint 134 | * the start point 135 | * @param geohashes 136 | * the geohashes 137 | * @return the list 138 | */ 139 | public static List sortByDistanceInMeters(final Position startPoint, 140 | final List geohashes) 141 | { 142 | return sortByDistance(startPoint, geohashes, MeasuringUnit.METER); 143 | } 144 | 145 | } -------------------------------------------------------------------------------- /jgeohash-core/src/test/java/de/alpharogroup/jgeohash/distance/enums/CellSize.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.distance.enums; 17 | 18 | import lombok.Getter; 19 | 20 | /** 21 | * The enum {@link CellSize} represents the size of a cell from a geohash value 22 | */ 23 | @Getter 24 | public enum CellSize 25 | { 26 | /** 27 | * The enum value HEIGHT_1_CELL represents the height from a cell from a geohash value with 1 28 | * characters. 29 | **/ 30 | HEIGHT_1_CELL(1, 5003.53096, Alignment.HEIGHT), 31 | /** 32 | * The enum value HEIGHT_2_CELL represents the height from a cell from a geohash value with 2 33 | * characters. 34 | **/ 35 | HEIGHT_2_CELL(2, 744.37693, Alignment.HEIGHT), 36 | /** 37 | * The enum value HEIGHT_3_CELL represents the height from a cell from a geohash value with 3 38 | * characters. 39 | **/ 40 | HEIGHT_3_CELL(3, 156.36034, Alignment.HEIGHT), 41 | /** 42 | * The enum value HEIGHT_4_CELL represents the height from a cell from a geohash value with 4 43 | * characters. 44 | **/ 45 | HEIGHT_4_CELL(4, 19.54504, Alignment.HEIGHT), 46 | /** 47 | * The enum value HEIGHT_5_CELL represents the height from a cell from a geohash value with 5 48 | * characters. 49 | **/ 50 | HEIGHT_5_CELL(5, 5.88626, Alignment.HEIGHT), 51 | /** 52 | * The enum value HEIGHT_6_CELL represents the height from a cell from a geohash value with 6 53 | * characters. 54 | **/ 55 | HEIGHT_6_CELL(6, 0.61078, Alignment.HEIGHT), 56 | /** 57 | * The enum value HEIGHT_7_CELL represents the height from a cell from a geohash value with 7 58 | * characters. 59 | **/ 60 | HEIGHT_7_CELL(7, 0.15269, Alignment.HEIGHT), 61 | /** 62 | * The enum value HEIGHT_8_CELL represents the height from a cell from a geohash value with 8 63 | * characters. 64 | **/ 65 | HEIGHT_8_CELL(8, 0.01908, Alignment.HEIGHT), 66 | /** 67 | * The enum value HEIGHT_9_CELL represents the height from a cell from a geohash value with 9 68 | * characters. 69 | **/ 70 | HEIGHT_9_CELL(9, 0.00283, Alignment.HEIGHT), 71 | /** 72 | * The enum value WIDTH_1_CELL represents the width from a cell from a geohash value with 1 73 | * characters. 74 | **/ 75 | WIDTH_1_CELL(1, 4604.31836, Alignment.WIDTH), 76 | /** 77 | * The enum value WIDTH_2_CELL represents the width from a cell from a geohash value with 2 78 | * characters. 79 | **/ 80 | WIDTH_2_CELL(2, 625.44137, Alignment.WIDTH), 81 | /** 82 | * The enum value WIDTH_3_CELL represents the width from a cell from a geohash value with 3 83 | * characters. 84 | **/ 85 | WIDTH_3_CELL(3, 103.57409, Alignment.WIDTH), 86 | /** 87 | * The enum value WIDTH_4_CELL represents the width from a cell from a geohash value with 4 88 | * characters. 89 | **/ 90 | WIDTH_4_CELL(4, 25.66850, Alignment.WIDTH), 91 | /** 92 | * The enum value WIDTH_5_CELL represents the width from a cell from a geohash value with 5 93 | * characters. 94 | **/ 95 | WIDTH_5_CELL(5, 3.21280, Alignment.WIDTH), 96 | /** 97 | * The enum value WIDTH_6_CELL represents the width from a cell from a geohash value with 6 98 | * characters. 99 | **/ 100 | WIDTH_6_CELL(6, 0.80315, Alignment.WIDTH), 101 | /** 102 | * The enum value WIDTH_7_CELL represents the width from a cell from a geohash value with 7 103 | * characters. 104 | **/ 105 | WIDTH_7_CELL(7, 0.10039, Alignment.WIDTH), 106 | /** 107 | * The enum value WIDTH_8_CELL represents the width from a cell from a geohash value with 8 108 | * characters. 109 | **/ 110 | WIDTH_8_CELL(8, 0.02509, Alignment.WIDTH), 111 | /** 112 | * The enum value WIDTH_9_CELL represents the width from a cell from a geohash value with 9 113 | * characters. 114 | **/ 115 | WIDTH_9_CELL(9, 0.00477, Alignment.WIDTH); 116 | 117 | /** The alignment. */ 118 | private final Alignment alignment; 119 | 120 | /** The size of the characters in the geohash value. */ 121 | private final int characters; 122 | 123 | /** The size. */ 124 | private final double size; 125 | 126 | /** 127 | * Instantiates a new cell size. 128 | * 129 | * @param characters 130 | * the characters 131 | * @param size 132 | * the size 133 | * @param alignment 134 | * the alignment 135 | */ 136 | private CellSize(int characters, double size, Alignment alignment) 137 | { 138 | this.characters = characters; 139 | this.size = size; 140 | this.alignment = alignment; 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /jgeohash-core/src/test/java/de/alpharogroup/jgeohash/PointTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash; 17 | 18 | import static org.testng.AssertJUnit.assertEquals; 19 | import static org.testng.AssertJUnit.assertNotNull; 20 | import static org.testng.AssertJUnit.assertTrue; 21 | 22 | import org.testng.annotations.Test; 23 | 24 | import de.alpharogroup.evaluate.object.verifier.ContractVerifier; 25 | 26 | /** 27 | * The unit test class for the class {@link Point}. 28 | */ 29 | public class PointTest 30 | { 31 | 32 | /** 33 | * Test method for {@link Point#compareTo(Point)}. 34 | */ 35 | @Test 36 | public void testCompareTo() 37 | { 38 | /** For use of the expected result. */ 39 | boolean expected; 40 | /** For use of the result of the comparison. */ 41 | int actual; 42 | String geohash; 43 | Point o1; 44 | Point o2; 45 | 46 | geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); 47 | 48 | o1 = new GeoHashPoint(geohash); 49 | o2 = new GeoHashPoint(geohash); 50 | actual = o1.compareTo(o2); 51 | expected = actual == 0; 52 | assertTrue(expected); 53 | actual = o1.compareTo(o1); 54 | expected = actual == 0; 55 | assertTrue(expected); 56 | 57 | geohash = GeoHashExtensions.encode(30.0, -90.0); 58 | o2 = new GeoHashPoint(geohash); 59 | actual = o1.compareTo(o2); 60 | expected = 0 < actual; 61 | assertTrue(expected); 62 | 63 | actual = o2.compareTo(o1); 64 | expected = actual < 0; 65 | assertTrue(expected); 66 | } 67 | 68 | /** 69 | * Test method for {@link Point} constructors and builders 70 | */ 71 | @Test 72 | public final void testConstructors() 73 | { 74 | Point model = new Point(53.5526394, 10.0067103); 75 | assertNotNull(model); 76 | model = Point.builder().build(); 77 | assertNotNull(model); 78 | } 79 | 80 | /** 81 | * Test method for {@link Point} constructors and builders with an unappropriated latitude 82 | * number. 83 | */ 84 | @Test(expectedExceptions = IllegalArgumentException.class) 85 | public final void testConstructorsWithUnappropriatedLatitudeNumber() 86 | { 87 | new Point(153.5526394, 10.0067103); 88 | } 89 | 90 | /** 91 | * Test method for {@link Point} constructors and builders with an unappropriated longitude 92 | * number. 93 | */ 94 | @Test(expectedExceptions = IllegalArgumentException.class) 95 | public final void testConstructorsWithUnappropriatedLongitudeNumber() 96 | { 97 | new Point(53.5526394, 190.0067103); 98 | } 99 | 100 | /** 101 | * Test method for {@link Point#equals(Object)} , {@link Point#hashCode()} and 102 | * {@link Point#toString()} 103 | */ 104 | @Test 105 | public void verifyEqualsHashcodeAndToStringWithClass() 106 | { 107 | ContractVerifier.of(Point.class).verify(); 108 | } 109 | 110 | /** 111 | * Test method for {@link Point#setLatitude(double)}. 112 | */ 113 | @Test 114 | public void testSetLatitude() 115 | { 116 | double actual; 117 | double expected; 118 | Point o1; 119 | o1 = new GeoHashPoint(GeoHashExtensions.encode(53.5526394, 10.0067103)); 120 | o1.setLatitude(52.0d); 121 | actual = o1.getLatitude(); 122 | expected = 52.0d; 123 | assertEquals(expected, actual); 124 | } 125 | 126 | /** 127 | * Test method for {@link Point#setLatitude(double)} with an unappropriated latitude number. 128 | */ 129 | @Test(expectedExceptions = IllegalArgumentException.class) 130 | public void testSetLatitudeUnappropriateLatitudeNumber() 131 | { 132 | Point o1 = new GeoHashPoint(GeoHashExtensions.encode(53.5526394, 10.0067103)); 133 | o1.setLatitude(100.0d); 134 | } 135 | 136 | /** 137 | * Test method for {@link Point#setLongitude(double)}. 138 | */ 139 | @Test 140 | public void testSetLongitude() 141 | { 142 | double actual; 143 | double expected; 144 | String geohash; 145 | Point o1; 146 | geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); 147 | 148 | o1 = new GeoHashPoint(geohash); 149 | o1.setLongitude(9.8d); 150 | actual = o1.getLongitude(); 151 | expected = 9.8d; 152 | assertEquals(expected, actual); 153 | } 154 | 155 | /** 156 | * Test method for {@link Point#setLongitude(double)} with an unappropriated longitude number. 157 | */ 158 | @Test(expectedExceptions = IllegalArgumentException.class) 159 | public void testSetLongitudeWithUnappropriatedNumber() 160 | { 161 | String geohash; 162 | Point o1; 163 | geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); 164 | 165 | o1 = new GeoHashPoint(geohash); 166 | o1.setLongitude(190.0d); 167 | } 168 | 169 | } 170 | -------------------------------------------------------------------------------- /jgeohash-core/src/test/java/de/alpharogroup/jgeohash/distance/DistancePointTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.distance; 17 | 18 | import static org.testng.AssertJUnit.assertEquals; 19 | import static org.testng.AssertJUnit.assertNotNull; 20 | import static org.testng.AssertJUnit.assertNotSame; 21 | import static org.testng.AssertJUnit.assertTrue; 22 | 23 | import org.testng.annotations.Test; 24 | 25 | import de.alpharogroup.evaluate.object.evaluators.EqualsEvaluator; 26 | import de.alpharogroup.evaluate.object.evaluators.HashcodeEvaluator; 27 | import de.alpharogroup.evaluate.object.evaluators.ToStringEvaluator; 28 | import de.alpharogroup.jgeohash.Point; 29 | import de.alpharogroup.jgeohash.api.Position; 30 | 31 | /** 32 | * The unit test class for the class {@link DistancePoint}. 33 | */ 34 | public class DistancePointTest 35 | { 36 | 37 | /** 38 | * Test method for {@link DistancePoint#compareTo(DistancePoint)} 39 | */ 40 | @Test 41 | public void testCompareTo() 42 | { 43 | boolean expected; 44 | int actual; 45 | Position point; 46 | Double distance; 47 | 48 | point = Point.builder().longitude(0.1d).latitude(20.0d).build(); 49 | distance = 1000.0d; 50 | final DistancePoint distancePoint = DistancePoint.builder().distance(distance).point(point) 51 | .build(); 52 | point = Point.builder().longitude(0.2d).latitude(3.5d).build(); 53 | distance = 20.0d; 54 | DistancePoint anotherPoint = DistancePoint.builder().distance(distance).point(point) 55 | .build(); 56 | 57 | actual = distancePoint.compareTo(anotherPoint); 58 | expected = 0 < actual; 59 | assertTrue(expected); 60 | } 61 | 62 | /** 63 | * Test method for {@link DistancePoint} constructors 64 | */ 65 | @Test 66 | public final void testConstructors() 67 | { 68 | DistancePoint model = new DistancePoint( 69 | Point.builder().latitude(0.0d).longitude(0.0d).build(), Double.valueOf(1.0d)); 70 | assertNotNull(model); 71 | } 72 | 73 | /** 74 | * Test method for {@link DistancePoint#equals(Object)} 75 | */ 76 | @Test 77 | public void testEqualsObject() 78 | { 79 | Position point; 80 | Double distance; 81 | point = Point.builder().longitude(0.1d).latitude(20.0d).build(); 82 | distance = 1000.0d; 83 | final DistancePoint expected = DistancePoint.builder().distance(distance).point(point) 84 | .build(); 85 | 86 | point = Point.builder().longitude(0.2d).latitude(3.5d).build(); 87 | distance = 20.0d; 88 | final DistancePoint actual = new DistancePoint(point, distance); 89 | 90 | assertNotSame(expected, actual); 91 | 92 | point = Point.builder().longitude(0.1d).latitude(20.0d).build(); 93 | distance = 1000.0d; 94 | final DistancePoint distancePoint = new DistancePoint(point, distance); 95 | assertEquals(expected, distancePoint); 96 | assertTrue( 97 | EqualsEvaluator.evaluateReflexivityNonNullSymmetricAndConsistency(expected, actual)); 98 | assertTrue(EqualsEvaluator.evaluateReflexivityNonNullSymmetricConsistencyAndTransitivity( 99 | expected, distancePoint, new DistancePoint(point, distance))); 100 | } 101 | 102 | /** 103 | * Test method for {@link DistancePoint#hashCode()} 104 | */ 105 | @Test 106 | public void testHashcode() 107 | { 108 | boolean expected; 109 | boolean actual; 110 | Position point; 111 | Double distance; 112 | point = Point.builder().longitude(0.1d).latitude(20.0d).build(); 113 | distance = 1000.0d; 114 | final DistancePoint distancePoint = DistancePoint.builder().distance(distance).point(point) 115 | .build(); 116 | actual = HashcodeEvaluator.evaluateEquality(distancePoint, 117 | new DistancePoint(point, distance)); 118 | expected = true; 119 | assertEquals(expected, actual); 120 | 121 | actual = HashcodeEvaluator.evaluateConsistency(distancePoint); 122 | expected = true; 123 | assertEquals(expected, actual); 124 | 125 | expected = true; 126 | point = Point.builder().longitude(0.2d).latitude(3.5d).build(); 127 | distance = 20.0d; 128 | DistancePoint stringBox = DistancePoint.builder().distance(distance).point(point).build(); 129 | actual = HashcodeEvaluator.evaluateUnequality(distancePoint, stringBox); 130 | assertEquals(expected, actual); 131 | } 132 | 133 | /** 134 | * Test method for {@link DistancePoint#toString()} 135 | */ 136 | @Test 137 | public void testToString() 138 | { 139 | boolean expected; 140 | boolean actual; 141 | Position point; 142 | Double distance; 143 | actual = ToStringEvaluator.evaluate(DistancePoint.class); 144 | expected = true; 145 | assertEquals(expected, actual); 146 | 147 | point = Point.builder().longitude(0.1d).latitude(20.0d).build(); 148 | distance = 1000.0d; 149 | final DistancePoint distancePoint = DistancePoint.builder().distance(distance).point(point) 150 | .build(); 151 | actual = ToStringEvaluator.evaluateConsistency(distancePoint); 152 | expected = true; 153 | assertEquals(expected, actual); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | ## 1. Purpose 4 | 5 | A primary goal of jgeohash is to be inclusive to the largest number of contributors, with the most varied and diverse backgrounds possible. As such, we are committed to providing a friendly, 6 | safe and welcoming environment for all, regardless of gender, sexual orientation, ability, ethnicity, socioeconomic status, and religion (or lack thereof). 7 | 8 | This code of conduct outlines our expectations for all those who participate in our community, as well as the consequences for unacceptable behavior. 9 | 10 | We invite all those who participate in jgeohash to help us create safe and positive experiences for everyone. 11 | 12 | ## 2. Open Source Citizenship 13 | 14 | A supplemental goal of this Code of Conduct is to increase open source citizenship by encouraging participants to recognize and strengthen the relationships between our actions and their effects on our community. 15 | 16 | Communities mirror the societies in which they exist and positive action is essential to counteract the many forms of inequality and abuses of power that exist in society. 17 | 18 | If you see someone who is making an extra effort to ensure our community is welcoming, friendly, and encourages all participants to contribute to the fullest extent, we want to know. 19 | 20 | ## 3. Expected Behavior 21 | 22 | The following behaviors are expected and requested of all community members: 23 | 24 | * Participate in an authentic and active way. In doing so, you contribute to the health and longevity of this community. 25 | * Exercise consideration and respect in your speech and actions. 26 | * Attempt collaboration before conflict. 27 | * Refrain from demeaning, discriminatory, or harassing behavior and speech. 28 | * Be mindful of your surroundings and of your fellow participants. Alert community leaders if you notice a dangerous situation, someone in distress, 29 | or violations of this Code of Conduct, even if they seem inconsequential. 30 | * Remember that community event venues may be shared with members of the public; please be respectful to all patrons of these locations. 31 | 32 | ## 4. Unacceptable Behavior 33 | 34 | The following behaviors are considered harassment and are unacceptable within our community: 35 | 36 | * Violence, threats of violence or violent language directed against another person. 37 | * Sexist, racist, homophobic, transphobic, ableist or otherwise discriminatory jokes and language. 38 | * Posting or displaying sexually explicit or violent material. 39 | * Posting or threatening to post other people’s personally identifying information ("doxing"). 40 | * Personal insults, particularly those related to gender, sexual orientation, race, religion, or disability. 41 | * Inappropriate photography or recording. 42 | * Inappropriate physical contact. You should have someone’s consent before touching them. 43 | * Unwelcome sexual attention. This includes, sexualized comments or jokes; inappropriate touching, groping, and unwelcomed sexual advances. 44 | * Deliberate intimidation, stalking or following (online or in person). 45 | * Advocating for, or encouraging, any of the above behavior. 46 | * Sustained disruption of community events, including talks and presentations. 47 | 48 | ## 5. Consequences of Unacceptable Behavior 49 | 50 | Unacceptable behavior from any community member, including sponsors and those with decision-making authority, will not be tolerated. 51 | 52 | Anyone asked to stop unacceptable behavior is expected to comply immediately. 53 | 54 | If a community member engages in unacceptable behavior, the community organizers may take any action they deem appropriate, up to and including a temporary ban or permanent expulsion 55 | from the community without warning (and without refund in the case of a paid event). 56 | 57 | ## 6. Reporting Guidelines 58 | 59 | If you are subject to or witness unacceptable behavior, or have any other concerns, please notify a community organizer as soon as possible. asterios.raptis@web.de. 60 | 61 | 62 | 63 | Additionally, community organizers are available to help community members engage with local law enforcement or to otherwise help those experiencing unacceptable behavior feel safe. 64 | In the context of in-person events, organizers will also provide escorts as desired by the person experiencing distress. 65 | 66 | ## 7. Addressing Grievances 67 | 68 | If you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should notify astrapi69 with a concise description of your grievance. 69 | Your grievance will be handled in accordance with our existing governing policies. 70 | 71 | 72 | 73 | ## 8. Scope 74 | 75 | We expect all community participants (contributors, paid or otherwise; sponsors; and other guests) to abide by this Code of Conduct in all community venues–online and in-person–as well as 76 | in all one-on-one communications pertaining to community business. 77 | 78 | This code of conduct and its related procedures also applies to unacceptable behavior occurring outside the scope of community activities when such behavior has the potential to adversely 79 | affect the safety and well-being of community members. 80 | 81 | ## 9. Contact info 82 | 83 | asterios.raptis@web.de 84 | 85 | ## 10. License and attribution 86 | 87 | This Code of Conduct is distributed under a [Creative Commons Attribution-ShareAlike license](http://creativecommons.org/licenses/by-sa/3.0/). 88 | 89 | Portions of text derived from the [Django Code of Conduct](https://www.djangoproject.com/conduct/) and the [Geek Feminism Anti-Harassment Policy](http://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy). 90 | 91 | Retrieved on November 22, 2016 from [http://citizencodeofconduct.org/](http://citizencodeofconduct.org/) 92 | -------------------------------------------------------------------------------- /jgeohash-core/src/main/java/de/alpharogroup/jgeohash/model/Section.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.model; 17 | 18 | import de.alpharogroup.merge.api.Mergeable; 19 | import lombok.AccessLevel; 20 | import lombok.AllArgsConstructor; 21 | import lombok.Builder; 22 | import lombok.EqualsAndHashCode; 23 | import lombok.Getter; 24 | import lombok.Setter; 25 | import lombok.ToString; 26 | import lombok.experimental.FieldDefaults; 27 | 28 | /** 29 | * The class {@link Section} represents a section with start and end point. 30 | */ 31 | @Getter 32 | @Setter 33 | @EqualsAndHashCode 34 | @ToString 35 | @AllArgsConstructor 36 | @Builder(toBuilder = true) 37 | @FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) 38 | public class Section implements Mergeable
39 | { 40 | 41 | /** 42 | * Checks the given int index is between the range from min and max. 43 | * 44 | * @param min 45 | * The minimum. 46 | * @param max 47 | * The maximum. 48 | * @param index 49 | * The index. 50 | * @param includeMin 51 | * if true than min value is included 52 | * @param includeMax 53 | * if true than max value is included 54 | * @return Returns true if the index is between the range from min and max considered the given 55 | * flags otherwise false. 56 | */ 57 | public static boolean isBetween(final int min, final int max, final int index, 58 | final boolean includeMin, final boolean includeMax) 59 | { 60 | if (includeMin && includeMax) 61 | { 62 | 63 | if (index >= min && index <= max) 64 | { 65 | return true; 66 | } 67 | else 68 | { 69 | return false; 70 | } 71 | } 72 | if (includeMin && !includeMax) 73 | { 74 | 75 | if (index >= min && index < max) 76 | { 77 | return true; 78 | } 79 | else 80 | { 81 | return false; 82 | } 83 | } 84 | if (!includeMin && includeMax) 85 | { 86 | 87 | if (index > min && index <= max) 88 | { 89 | return true; 90 | } 91 | else 92 | { 93 | return false; 94 | } 95 | } 96 | if (min < index && index < max) 97 | { 98 | return true; 99 | } 100 | else 101 | { 102 | return false; 103 | } 104 | } 105 | 106 | /** The end. */ 107 | int end; 108 | 109 | /** The start. */ 110 | int start; 111 | 112 | /** 113 | * Checks if the given {@link Section} is between this {@link Section} object. 114 | * 115 | * @param other 116 | * the other {@link Section} object 117 | * @return true, if the given {@link Section} is between this {@link Section} object otherwise 118 | * false. 119 | */ 120 | public boolean isBetween(final Section other) 121 | { 122 | boolean start = isBetween(this.start, this.end, other.start, true, true); 123 | boolean end = isBetween(this.start, this.end, other.end, true, true); 124 | boolean between = start && end; 125 | return between; 126 | } 127 | 128 | /** 129 | * Checks if this {@link Section} is to left from the given {@link Section} object. 130 | * 131 | * @param other 132 | * the other {@link Section} object 133 | * @return true, if this {@link Section} is to left from the given {@link Section} object 134 | * otherwise false. 135 | */ 136 | public boolean isToLeft(final Section other) 137 | { 138 | int oneAfter = other.getEnd() + 1; 139 | return this.start == oneAfter; 140 | } 141 | 142 | /** 143 | * Checks if this {@link Section} is to right from the given {@link Section} object. 144 | * 145 | * @param other 146 | * the other {@link Section} object 147 | * @return true, if this {@link Section} is to right from the given {@link Section} object 148 | * otherwise false. 149 | */ 150 | public boolean isToRight(final Section other) 151 | { 152 | int oneBefore = other.getStart() - 1; 153 | return this.end == oneBefore; 154 | } 155 | 156 | /** 157 | * {@inheritDoc} 158 | */ 159 | @Override 160 | public Section merge(final Section other) 161 | { 162 | Section merged = this; 163 | if (this.isToLeft(other)) 164 | { 165 | merged = Section.builder().start(other.getStart()).end(this.end).build(); 166 | return merged; 167 | } 168 | if (this.isToRight(other)) 169 | { 170 | merged = Section.builder().start(this.getStart()).end(other.end).build(); 171 | return merged; 172 | } 173 | final boolean overlapsWith = this.overlapsWith(other); 174 | if (overlapsWith) 175 | { 176 | if (this.getStart() <= other.getStart()) 177 | { 178 | if (this.getEnd() >= other.getEnd()) 179 | { 180 | merged = this; 181 | return merged; 182 | } 183 | else 184 | { 185 | merged = Section.builder().start(this.getStart()).end(other.getEnd()).build(); 186 | return merged; 187 | } 188 | } 189 | else 190 | { 191 | if (this.getEnd() >= other.getEnd()) 192 | { 193 | merged = Section.builder().start(other.getStart()).end(this.getEnd()).build(); 194 | return merged; 195 | } 196 | else 197 | { 198 | merged = Section.builder().start(other.getStart()).end(other.getEnd()).build(); 199 | return merged; 200 | } 201 | } 202 | } 203 | return merged; 204 | } 205 | 206 | /** 207 | * Checks if this {@link Section} overlaps with the given {@link Section} object. 208 | * 209 | * @param other 210 | * the other {@link Section} object 211 | * @return true, if this {@link Section} overlaps with the given {@link Section} object 212 | * otherwise false. 213 | */ 214 | public boolean overlapsWith(final Section other) 215 | { 216 | return ((this.start <= other.start && this.end >= other.start) 217 | || (this.start <= other.end && this.end >= other.end)) 218 | || ((this.start >= other.start && this.start <= other.end) 219 | || (this.end >= other.start && this.end <= other.end)); 220 | } 221 | 222 | } 223 | -------------------------------------------------------------------------------- /jgeohash-core/src/test/java/de/alpharogroup/jgeohash/model/FirstRingRegionTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.model; 17 | 18 | import static org.testng.AssertJUnit.assertEquals; 19 | 20 | import org.testng.annotations.Test; 21 | 22 | import de.alpharogroup.AbstractTestCase; 23 | import de.alpharogroup.evaluate.object.evaluators.EqualsHashCodeAndToStringEvaluator; 24 | 25 | /** 26 | * The unit test class for the class {@link FirstRingRegion} 27 | */ 28 | public class FirstRingRegionTest extends AbstractTestCase 29 | { 30 | 31 | /** 32 | * Test method for {@link FirstRingRegion#clone()} 33 | */ 34 | @Test 35 | public void testClone() 36 | { 37 | FirstRingRegion actual; 38 | FirstRingRegion expected; 39 | expected = new FirstRingRegion("u1x0etp"); 40 | actual = (FirstRingRegion)expected.clone(); 41 | assertEquals(expected, actual); 42 | } 43 | 44 | /** 45 | * Test method for {@link FirstRingRegion#equals(Object)} , {@link FirstRingRegion#hashCode()} 46 | * and {@link FirstRingRegion#toString()} 47 | */ 48 | @Test 49 | public void testEqualsHashcodeAndToString() 50 | { 51 | boolean expected; 52 | boolean actual; 53 | final FirstRingRegion first = new FirstRingRegion("u1x0etp"); 54 | final FirstRingRegion second = new FirstRingRegion("u1x0etq"); 55 | final FirstRingRegion third = new FirstRingRegion("u1x0etp"); 56 | final FirstRingRegion fourth = new FirstRingRegion("u1x0etp"); 57 | 58 | actual = EqualsHashCodeAndToStringEvaluator.evaluateEqualsHashcodeAndToString(first, second, 59 | third, fourth); 60 | expected = true; 61 | assertEquals(expected, actual); 62 | } 63 | 64 | /** 65 | * Test method for {@link FirstRingRegion#getCenter()}. 66 | */ 67 | @Test 68 | public void testGetCenter() 69 | { 70 | FirstRingRegion geoHashRegion = new FirstRingRegion("u"); 71 | 72 | expected = "u"; 73 | actual = geoHashRegion.getCenter(); 74 | assertEquals(expected, actual); 75 | 76 | geoHashRegion = new FirstRingRegion("t"); 77 | 78 | expected = "t"; 79 | actual = geoHashRegion.getCenter(); 80 | assertEquals(expected, actual); 81 | } 82 | 83 | /** 84 | * Test method for {@link FirstRingRegion#getEast()}. 85 | */ 86 | @Test 87 | public void testGetEast() 88 | { 89 | FirstRingRegion geoHashRegion = new FirstRingRegion("u"); 90 | 91 | expected = "v"; 92 | actual = geoHashRegion.getEast(); 93 | assertEquals(expected, actual); 94 | 95 | geoHashRegion = new FirstRingRegion("t"); 96 | 97 | expected = "w"; 98 | actual = geoHashRegion.getEast(); 99 | assertEquals(expected, actual); 100 | } 101 | 102 | /** 103 | * Test method for {@link FirstRingRegion#getNorth()}. 104 | */ 105 | @Test 106 | public void testGetNorth() 107 | { 108 | FirstRingRegion geoHashRegion = new FirstRingRegion("u"); 109 | expected = "h"; 110 | actual = geoHashRegion.getNorth(); 111 | assertEquals(expected, actual); 112 | 113 | geoHashRegion = new FirstRingRegion("t"); 114 | expected = "v"; 115 | actual = geoHashRegion.getNorth(); 116 | assertEquals(expected, actual); 117 | } 118 | 119 | /** 120 | * Test method for {@link FirstRingRegion#getNorthEast()}. 121 | */ 122 | @Test 123 | public void testGetNorthEast() 124 | { 125 | FirstRingRegion geoHashRegion = new FirstRingRegion("u"); 126 | 127 | expected = "j"; 128 | actual = geoHashRegion.getNorthEast(); 129 | assertEquals(expected, actual); 130 | 131 | geoHashRegion = new FirstRingRegion("t"); 132 | 133 | expected = "y"; 134 | actual = geoHashRegion.getNorthEast(); 135 | assertEquals(expected, actual); 136 | } 137 | 138 | /** 139 | * Test method for {@link FirstRingRegion#getNorthWest()}. 140 | */ 141 | @Test 142 | public void testGetNorthWest() 143 | { 144 | FirstRingRegion geoHashRegion = new FirstRingRegion("u"); 145 | 146 | expected = "5"; 147 | actual = geoHashRegion.getNorthWest(); 148 | assertEquals(expected, actual); 149 | 150 | geoHashRegion = new FirstRingRegion("t"); 151 | 152 | expected = "u"; 153 | actual = geoHashRegion.getNorthWest(); 154 | assertEquals(expected, actual); 155 | } 156 | 157 | /** 158 | * Test method for {@link FirstRingRegion#getSouth()}. 159 | */ 160 | @Test 161 | public void testGetSouth() 162 | { 163 | FirstRingRegion geoHashRegion = new FirstRingRegion("u"); 164 | 165 | expected = "s"; 166 | actual = geoHashRegion.getSouth(); 167 | assertEquals(expected, actual); 168 | 169 | geoHashRegion = new FirstRingRegion("t"); 170 | 171 | expected = "m"; 172 | actual = geoHashRegion.getSouth(); 173 | assertEquals(expected, actual); 174 | } 175 | 176 | /** 177 | * Test method for {@link FirstRingRegion#getSouthEast()}. 178 | */ 179 | @Test 180 | public void testGetSouthEast() 181 | { 182 | FirstRingRegion geoHashRegion = new FirstRingRegion("u"); 183 | 184 | expected = "t"; 185 | actual = geoHashRegion.getSouthEast(); 186 | assertEquals(expected, actual); 187 | 188 | geoHashRegion = new FirstRingRegion("t"); 189 | 190 | expected = "q"; 191 | actual = geoHashRegion.getSouthEast(); 192 | assertEquals(expected, actual); 193 | } 194 | 195 | /** 196 | * Test method for {@link FirstRingRegion#getSouthWest()}. 197 | */ 198 | @Test 199 | public void testGetSouthWest() 200 | { 201 | FirstRingRegion geoHashRegion = new FirstRingRegion("u"); 202 | 203 | expected = "e"; 204 | actual = geoHashRegion.getSouthWest(); 205 | assertEquals(expected, actual); 206 | 207 | geoHashRegion = new FirstRingRegion("t"); 208 | 209 | expected = "k"; 210 | actual = geoHashRegion.getSouthWest(); 211 | assertEquals(expected, actual); 212 | } 213 | 214 | /** 215 | * Test method for {@link FirstRingRegion#getWest()}. 216 | */ 217 | @Test 218 | public void testGetWest() 219 | { 220 | FirstRingRegion geoHashRegion = new FirstRingRegion("u"); 221 | 222 | expected = "g"; 223 | actual = geoHashRegion.getWest(); 224 | assertEquals(expected, actual); 225 | 226 | geoHashRegion = new FirstRingRegion("t"); 227 | 228 | expected = "s"; 229 | actual = geoHashRegion.getWest(); 230 | assertEquals(expected, actual); 231 | } 232 | 233 | } 234 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=$((i+1)) 158 | done 159 | case $i in 160 | (0) set -- ;; 161 | (1) set -- "$args0" ;; 162 | (2) set -- "$args0" "$args1" ;; 163 | (3) set -- "$args0" "$args1" "$args2" ;; 164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=$(save "$@") 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 185 | cd "$(dirname "$0")" 186 | fi 187 | 188 | exec "$JAVACMD" "$@" 189 | -------------------------------------------------------------------------------- /jgeohash-core/src/main/java/de/alpharogroup/jgeohash/Adjacent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash; 17 | 18 | import java.util.LinkedHashMap; 19 | import java.util.Map; 20 | 21 | /** 22 | * The class {@link Adjacent}. 23 | */ 24 | public abstract class Adjacent 25 | { 26 | 27 | /** 28 | * The static class Borders. 29 | */ 30 | public static class Borders 31 | { 32 | 33 | /** The Constant borders. */ 34 | public static final Map> borders = new LinkedHashMap<>(); 35 | 36 | /** The Constant BOTTOM_LEFT. */ 37 | private static final String BOTTOM_LEFT = "028b"; 38 | 39 | /** The Constant LEFT_BOTTOM. */ 40 | private static final String LEFT_BOTTOM = "0145hjnp"; 41 | 42 | /** The Constant RIGHT_TOP. */ 43 | private static final String RIGHT_TOP = "bcfguvyz"; 44 | 45 | /** The Constant TOP_RIGHT. */ 46 | private static final String TOP_RIGHT = "prxz"; 47 | 48 | /** 49 | * Initializes the borders map. 50 | **/ 51 | static 52 | { 53 | final Map right = new LinkedHashMap<>(); 54 | right.put(Adjacent.EVEN, Borders.RIGHT_TOP); 55 | right.put(Adjacent.ODD, Borders.TOP_RIGHT); 56 | final Map left = new LinkedHashMap<>(); 57 | left.put(Adjacent.EVEN, Borders.LEFT_BOTTOM); 58 | left.put(Adjacent.ODD, Borders.BOTTOM_LEFT); 59 | final Map top = new LinkedHashMap<>(); 60 | top.put(Adjacent.EVEN, Borders.TOP_RIGHT); 61 | top.put(Adjacent.ODD, Borders.RIGHT_TOP); 62 | final Map bottom = new LinkedHashMap<>(); 63 | bottom.put(Adjacent.EVEN, Borders.BOTTOM_LEFT); 64 | bottom.put(Adjacent.ODD, Borders.LEFT_BOTTOM); 65 | borders.put(Adjacent.TOP, right); 66 | borders.put(Adjacent.BOTTOM, left); 67 | borders.put(Adjacent.RIGHT, top); 68 | borders.put(Adjacent.LEFT, bottom); 69 | } 70 | } 71 | 72 | /** 73 | * The static class Neighbors. 74 | */ 75 | public static class Neighbors 76 | { 77 | 78 | /** The Constant BOTTOM_LEFT. */ 79 | private static final String BOTTOM_LEFT = "14365h7k9dcfesgujnmqp0r2twvyx8zb"; 80 | 81 | /** The Constant LEFT_BOTTOM. */ 82 | private static final String LEFT_BOTTOM = "238967debc01fg45kmstqrwxuvhjyznp"; 83 | 84 | /** The Constant neighbors. */ 85 | public static final Map> neighbors = new LinkedHashMap<>(); 86 | 87 | /** The Constant RIGHT_TOP. */ 88 | private static final String RIGHT_TOP = "bc01fg45238967deuvhjyznpkmstqrwx"; 89 | 90 | /** The Constant TOP_RIGHT. */ 91 | private static final String TOP_RIGHT = "p0r21436x8zb9dcf5h7kjnmqesgutwvy"; 92 | 93 | /** 94 | * Initializes the neighbors map. 95 | **/ 96 | static 97 | { 98 | final Map right = new LinkedHashMap<>(); 99 | right.put(Adjacent.EVEN, Neighbors.RIGHT_TOP); 100 | right.put(Adjacent.ODD, Neighbors.TOP_RIGHT); 101 | final Map left = new LinkedHashMap<>(); 102 | left.put(Adjacent.EVEN, Neighbors.LEFT_BOTTOM); 103 | left.put(Adjacent.ODD, Neighbors.BOTTOM_LEFT); 104 | final Map top = new LinkedHashMap<>(); 105 | top.put(Adjacent.EVEN, Neighbors.TOP_RIGHT); 106 | top.put(Adjacent.ODD, Neighbors.RIGHT_TOP); 107 | final Map bottom = new LinkedHashMap<>(); 108 | bottom.put(Adjacent.EVEN, Neighbors.BOTTOM_LEFT); 109 | bottom.put(Adjacent.ODD, Neighbors.LEFT_BOTTOM); 110 | neighbors.put(Adjacent.TOP, right); 111 | neighbors.put(Adjacent.BOTTOM, left); 112 | neighbors.put(Adjacent.RIGHT, top); 113 | neighbors.put(Adjacent.LEFT, bottom); 114 | } 115 | } 116 | 117 | /** The Constant BOTTOM. */ 118 | public static final String BOTTOM = "bottom"; 119 | 120 | /** The Constant BOTTOM_BOTTOM. */ 121 | public static final String BOTTOM_BOTTOM = "bottom_bottom"; 122 | 123 | /** The Constant BOTTOM_LEFT. */ 124 | public static final String BOTTOM_LEFT = "bottomleft"; 125 | 126 | /** The Constant BOTTOM_LEFT_BOTTOM. */ 127 | public static final String BOTTOM_LEFT_BOTTOM = "bottomleft_bottom"; 128 | 129 | /** The Constant BOTTOM_LEFT_BOTTOM_LEFT. */ 130 | public static final String BOTTOM_LEFT_BOTTOM_LEFT = "bottomleft_bottom_left"; 131 | 132 | /** The Constant BOTTOM_LEFT_LEFT. */ 133 | public static final String BOTTOM_LEFT_LEFT = "bottomleft_left"; 134 | 135 | /** The Constant BOTTOM_RIGHT. */ 136 | public static final String BOTTOM_RIGHT = "bottomright"; 137 | 138 | /** The Constant BOTTOM_RIGHT_BOTTOM. */ 139 | public static final String BOTTOM_RIGHT_BOTTOM = "bottomright_bottom"; 140 | 141 | /** The Constant BOTTOM_RIGHT_BOTTOM_RIGHT. */ 142 | public static final String BOTTOM_RIGHT_BOTTOM_RIGHT = "bottomright_bottom_right"; 143 | 144 | /** The Constant BOTTOM_RIGHT_RIGHT. */ 145 | public static final String BOTTOM_RIGHT_RIGHT = "bottomright_right"; 146 | 147 | /** The Constant CENTER. */ 148 | public static final String CENTER = "center"; 149 | 150 | /** The Constant EVEN. */ 151 | public static final String EVEN = "even"; 152 | 153 | /** The Constant LEFT. */ 154 | public static final String LEFT = "left"; 155 | 156 | /** The Constant LEFT_LEFT. */ 157 | public static final String LEFT_LEFT = "left_left"; 158 | 159 | /** The Constant ODD. */ 160 | public static final String ODD = "odd"; 161 | 162 | /** The Constant RIGHT. */ 163 | public static final String RIGHT = "right"; 164 | 165 | /** The Constant RIGHT_RIGHT. */ 166 | public static final String RIGHT_RIGHT = "right_right"; 167 | 168 | /** The Constant TOP. */ 169 | public static final String TOP = "top"; 170 | 171 | /** The Constant TOP_LEFT. */ 172 | public static final String TOP_LEFT = "topleft"; 173 | 174 | /** The Constant TOP_LEFT_LEFT. */ 175 | public static final String TOP_LEFT_LEFT = "topleft_left"; 176 | 177 | /** The Constant TOP_LEFT_TOP. */ 178 | public static final String TOP_LEFT_TOP = "topleft_top"; 179 | 180 | /** The Constant TOP_LEFT_TOP_LEFT. */ 181 | public static final String TOP_LEFT_TOP_LEFT = "topleft_top_left"; 182 | 183 | /** The Constant TOP_RIGHT. */ 184 | public static final String TOP_RIGHT = "topright"; 185 | 186 | /** The Constant TOP_RIGHT_RIGHT. */ 187 | public static final String TOP_RIGHT_RIGHT = "topright_right"; 188 | 189 | /** The Constant TOP_RIGHT_TOP. */ 190 | public static final String TOP_RIGHT_TOP = "topright_top"; 191 | 192 | /** The Constant TOP_RIGHT_RIGHT_TOP. */ 193 | public static final String TOP_RIGHT_TOP_RIGHT = "topright_top_right"; 194 | 195 | /** The Constant TOP_TOP. */ 196 | public static final String TOP_TOP = "top_top"; 197 | 198 | } -------------------------------------------------------------------------------- /jgeohash-core/src/test/java/de/alpharogroup/jgeohash/model/SectionTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash.model; 17 | 18 | import static org.testng.Assert.assertEquals; 19 | 20 | import org.testng.annotations.Test; 21 | 22 | import de.alpharogroup.evaluate.object.verifier.ContractVerifier; 23 | 24 | /** 25 | * The unit test class for the class {@link Section} 26 | */ 27 | public class SectionTest 28 | { 29 | 30 | /** 31 | * Test method for {@link Section#isBetween(Section)}. 32 | */ 33 | @Test 34 | public void testIsBetween() 35 | { 36 | boolean expected; 37 | boolean actual; 38 | Section section; 39 | Section other; 40 | 41 | section = Section.builder().start(23).end(45).build(); 42 | other = Section.builder().start(22).end(44).build(); 43 | 44 | actual = section.isBetween(other); 45 | expected = false; 46 | assertEquals(expected, actual); 47 | 48 | section = Section.builder().start(23).end(45).build(); 49 | other = Section.builder().start(23).end(45).build(); 50 | 51 | actual = section.isBetween(other); 52 | expected = true; 53 | assertEquals(expected, actual); 54 | 55 | section = Section.builder().start(23).end(45).build(); 56 | other = Section.builder().start(24).end(44).build(); 57 | 58 | actual = section.isBetween(other); 59 | expected = true; 60 | assertEquals(expected, actual); 61 | 62 | section = Section.builder().start(23).end(45).build(); 63 | other = Section.builder().start(23).end(46).build(); 64 | 65 | actual = section.isBetween(other); 66 | expected = false; 67 | assertEquals(expected, actual); 68 | 69 | section = Section.builder().start(23).end(45).build(); 70 | other = Section.builder().start(24).end(46).build(); 71 | 72 | actual = section.isBetween(other); 73 | expected = false; 74 | assertEquals(expected, actual); 75 | } 76 | 77 | /** 78 | * Test method for {@link Section#isBetween(int, int, int, boolean, boolean)}. 79 | */ 80 | @Test 81 | public void testIsBetweenIntIntIntBooleanBoolean() 82 | { 83 | boolean expected; 84 | boolean actual; 85 | int min; 86 | int max; 87 | int index; 88 | final int primitiveOne = 1; 89 | boolean includeMin; 90 | boolean includeMax; 91 | min = 0; 92 | max = 10; 93 | // first test case 94 | index = min; 95 | includeMin = false; 96 | includeMax = false; 97 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 98 | expected = false; 99 | assertEquals(actual, expected); 100 | for (index = min + primitiveOne; index < max; index++) 101 | { 102 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 103 | expected = true; 104 | assertEquals(actual, expected); 105 | } 106 | index = max; 107 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 108 | expected = false; 109 | assertEquals(actual, expected); 110 | 111 | // Now check negative cases 112 | index = min - primitiveOne; 113 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 114 | expected = false; 115 | assertEquals(actual, expected); 116 | index = max + primitiveOne; 117 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 118 | expected = false; 119 | assertEquals(actual, expected); 120 | 121 | // second test case 122 | index = min; 123 | includeMin = true; 124 | includeMax = true; 125 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 126 | expected = true; 127 | assertEquals(actual, expected); 128 | for (index = min + primitiveOne; index < max; index++) 129 | { 130 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 131 | expected = true; 132 | assertEquals(actual, expected); 133 | } 134 | index = max; 135 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 136 | expected = true; 137 | assertEquals(actual, expected); 138 | // Now check negative cases 139 | index = min - primitiveOne; 140 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 141 | expected = false; 142 | assertEquals(actual, expected); 143 | index = max + primitiveOne; 144 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 145 | expected = false; 146 | assertEquals(actual, expected); 147 | 148 | // third test case 149 | index = min; 150 | includeMin = false; 151 | includeMax = true; 152 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 153 | expected = false; 154 | assertEquals(actual, expected); 155 | for (index = min + primitiveOne; index < max; index++) 156 | { 157 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 158 | expected = true; 159 | assertEquals(actual, expected); 160 | } 161 | index = max; 162 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 163 | expected = true; 164 | assertEquals(actual, expected); 165 | // Now check negative cases 166 | index = min - primitiveOne; 167 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 168 | expected = false; 169 | assertEquals(actual, expected); 170 | index = max + primitiveOne; 171 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 172 | expected = false; 173 | assertEquals(actual, expected); 174 | 175 | // fourth test case 176 | index = min; 177 | includeMin = true; 178 | includeMax = false; 179 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 180 | expected = true; 181 | assertEquals(actual, expected); 182 | for (index = min + primitiveOne; index < max; index++) 183 | { 184 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 185 | expected = true; 186 | assertEquals(actual, expected); 187 | } 188 | index = max; 189 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 190 | expected = false; 191 | assertEquals(actual, expected); 192 | // Now check negative cases 193 | index = min - primitiveOne; 194 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 195 | expected = false; 196 | assertEquals(actual, expected); 197 | index = max + primitiveOne; 198 | actual = Section.isBetween(min, max, index, includeMin, includeMax); 199 | expected = false; 200 | assertEquals(actual, expected); 201 | } 202 | 203 | /** 204 | * Test method for {@link Section#equals(Object)} , {@link Section#hashCode()} and 205 | * {@link Section#toString()} 206 | */ 207 | @Test 208 | public void verifyEqualsHashcodeAndToStringWithClass() 209 | { 210 | ContractVerifier.of(Section.class).verify(); 211 | } 212 | 213 | } 214 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 |
3 | 4 | [![build status](https://travis-ci.com/astrapi69/jgeohash.svg?branch=master)](https://travis-ci.com/astrapi69/jgeohash) 5 | [![Java CI build and test](https://github.com/astrapi69/jgeohash/actions/workflows/build-test.yml/badge.svg)](https://github.com/astrapi69/jgeohash/actions/workflows/build-test.yml) 6 | [![Coverage Status](https://codecov.io/gh/astrapi69/jgeohash/branch/develop/graph/badge.svg)](https://codecov.io/gh/astrapi69/jgeohash) 7 | [![Coverage Status](https://coveralls.io/repos/github/astrapi69/jgeohash/badge.svg?branch=develop)](https://coveralls.io/github/astrapi69/jgeohash?branch=develop) 8 | [![open issues](https://img.shields.io/github/issues/astrapi69/jgeohash.svg?style=flat)](https://github.com/astrapi69/jgeohash/issues) 9 | [![license apache2](https://img.shields.io/badge/license-apache2-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0) 10 | [![Donate](https://img.shields.io/badge/donate-❤-ff2244.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GVBTWLRAZ7HB8) 11 | 12 |
13 | 14 | An easy-to-implement library that can assist Java developers in using the [GeoHash](https://en.wikipedia.org/wiki/Geohash) algorithm in order to create geocodes based on custom latitude and longitude values. 15 | 16 | With the help of jGeohash, Java developers will be able to quickly and easily generate a geohash code using user-defined latitude and longitude values. By using the GeoHash algorithm, the space can be divided into multiple grid shapes. 17 | 18 | This library is a basic implementation from the GeoHash algorithm written in the java and can be applied to generate from the latitude and longitude a geohash code and reverse. 19 | 20 | The library is kept simple and have no dependencies to other libraries. 21 | 22 | 23 | > Please support this project by simply putting a Github 24 | Star ⭐. Share this library with friends on Twitter and everywhere else you can. 25 | If you love this project [![donation](https://img.shields.io/badge/donate-❤-ff2244.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GVBTWLRAZ7HB8) 26 | 27 | ## Note 28 | 29 | No animals were harmed in the making of this library. 30 | 31 | # Donations 32 | 33 | This project is kept as an open source product and relies on contributions to remain being 34 | developed. If you like this library, please consider a donation 35 | 36 | over paypal:

37 | 38 | PayPal this 39 | 40 |

41 | or over bitcoin(BTC) with this address: 42 | 43 | bc1ql2y99q7e8psndhcc3gferk03esw3qqf677rhjy 44 | 45 | Donation Bitcoin Wallet 47 | 48 | or over FIO with this address: 49 | 50 | FIO7tFMUVAA9cHiPPqKMfMXiSxHrbpiFyRYqTketNuM67aULuwjop 51 | 52 | Donation FIO Wallet 54 | 55 | or over Ethereum(ETH) with: 56 | 57 | 0xc057D159D3C8f3311E73568b334FF6fE82EB2b7D 58 | 59 | Donation Ethereum Wallet 61 | 62 | or over Ethereum Classic(ETC) with: 63 | 64 | 0xF708cA86D86C246B69c3F4BAe431eBbe0c2bfddD 65 | 66 | Donation Ethereum Classic Wallet 68 | 69 | or over Dogecoin(DOGE) with: 70 | 71 | D5yi4Um8cpakd6yPRm2hGWuQ5nrVzhSSW1 72 | 73 | Donation Dogecoin Wallet 75 | 76 | or over Monero(XMR) with: 77 | 78 | 49bqeRQ7Bf49oJFVC72pqpe5hFbb62pfXDYPdLsadGGF81KZW2ZfrPZ8PbAVu5X2v1TYAspeczMya3cYQysNS4usRRPQHVw 79 | 80 | Donation Monero Wallet 82 | 83 | or over flattr: 84 | 85 | 86 | Flattr this 87 | 88 | 89 | ## Key features: 90 | 91 | 1. Very small size (<35Kb) 92 | 2. Can get the adjacent geohash area from the given direction 93 | 3. Can get the geohash from an ip address 94 | 4. Can calculate distance between two geohash values in various measuring units like miles, km, meters 95 | 5. Can get the geohash cells around from the first, second or thrird ring from a given geohash cell 96 | 97 | ## License 98 | 99 | The source code comes under the liberal Apache License V2.0, making jgeohash great for all types of applications. 100 | 101 | ## Maven Central 102 | 103 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/de.alpharogroup/jgeohash-core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/de.alpharogroup/jgeohash-core) jgeohash-core 104 | 105 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/de.alpharogroup/jgeohash-geoip/badge.svg)](https://maven-badges.herokuapp.com/maven-central/de.alpharogroup/jgeohash-geoip) jgeohash-geoip 106 | 107 | ## javadoc 108 | 109 | [![Javadocs](http://www.javadoc.io/badge/de.alpharogroup/jgeohash.svg)](http://www.javadoc.io/doc/de.alpharogroup/jgeohash-core) jgeohash-core 110 | 111 | [![Javadocs](http://www.javadoc.io/badge/de.alpharogroup/jgeohash.svg)](http://www.javadoc.io/doc/de.alpharogroup/jgeohash-geoip) jgeohash-geoip 112 | 113 | ## javadoc 114 | 115 | jgeohash-core [![Javadocs](http://www.javadoc.io/badge/de.alpharogroup/jgeohash.svg)](http://www.javadoc.io/doc/de.alpharogroup/jgeohash-core) 116 | 117 | jgeohash-geoip [![Javadocs](http://www.javadoc.io/badge/de.alpharogroup/jgeohash.svg)](http://www.javadoc.io/doc/de.alpharogroup/jgeohash-geoip) 118 | 119 | ## Maven dependency 120 | 121 | Maven dependency is now on sonatype. 122 | Check out [sonatype repository](https://oss.sonatype.org/index.html#nexus-search;quick~jgeohash) for latest snapshots and releases. 123 | 124 | You can add the following maven dependencies to your project `pom.xml` if you want to import the library. 125 | 126 | You can first define the version properties: 127 | 128 | 129 | ... 130 | 131 | 2.5.2 132 | ${jgeohash.version} 133 | ${jgeohash.version} 134 | ... 135 | 136 | 137 | Add the following maven dependency to your project `pom.xml` if you want to import the core functionality of jgeohash: 138 | 139 | 140 | ... 141 | 142 | 143 | de.alpharogroup 144 | jgeohash-core 145 | ${jgeohash-core.version} 146 | 147 | 148 | 149 | Add the following maven dependency to your project `pom.xml` if you want to import the geoip functionality of jgeohash: 150 | 151 | 152 | ... 153 | 154 | 155 | de.alpharogroup 156 | jgeohash-geoip 157 | ${jgeohash-geoip.version} 158 | 159 | 160 | 161 | ## Semantic Versioning 162 | 163 | The versions of jgeohash are maintained with the Semantic Versioning guidelines. 164 | 165 | Release version numbers will be incremented in the following format: 166 | 167 | `..` 168 | 169 | For detailed information on versioning for this project you can visit this [wiki page](https://github.com/lightblueseas/mvn-parent-projects/wiki/Semantic-Versioning). 170 | 171 | ## Want to Help and improve it? ### 172 | 173 | The source code for jGeohash are on GitHub. Please feel free to fork and send pull requests! 174 | 175 | Create your own fork of [astrapi69/jgeohash/fork](https://github.com/astrapi69/jgeohash/fork) 176 | 177 | To share your changes, [submit a pull request](https://github.com/astrapi69/jgeohash/pull/new/develop). 178 | 179 | Don't forget to add new units tests on your changes. 180 | 181 | ## Contacting the Developer 182 | 183 | Do not hesitate to contact the jgeohash developers with your questions, concerns, comments, bug reports, or feature requests. 184 | - Feature requests, questions and bug reports can be reported at the [issues page](https://github.com/astrapi69/jgeohash/issues). 185 | 186 | ## Examples 187 | 188 | * [SpatialDataQueries][SpatialDataQueries] 189 | * [Simple-example][Simple-example] 190 | * [Hibernate-example][Hibernate-example] 191 | 192 | [SpatialDataQueries]: https://github.com/astrapi69/jgeohash/wiki/Adding-spatial-data-queries-to-Phoenix-on-HBase "Adding spatial data queries to Phoenix on HBase" 193 | [Simple-example]: https://github.com/astrapi69/jgeohash/wiki/Simple-example "Simple-example" 194 | [Hibernate-example]: https://github.com/astrapi69/jgeohash/wiki/Hibernate-example "Hibernate-example" 195 | 196 | 197 | ## Similar projects 198 | 199 | Here is a list of awesome projects that uses geohash: 200 | 201 | * [geohash-java](https://github.com/kungfoo/geohash-java) Another implementation of Geohashes in pure Java. 202 | * [geo](https://github.com/davidmoten/geo) Geohash utitlies in java 203 | 204 | ## Blogs 205 | 206 | * [Designing a Spacial Index](https://dzone.com/articles/designing-spacial-index) 207 | 208 | ## Useful links 209 | 210 | * [geohash.org browser](http://geohash.org/) 211 | * [alternative geohash browser](https://www.movable-type.co.uk/scripts/geohash.html) 212 | 213 | ## Change log 214 | 215 | The changelog is moved in its own file. It can be found on following [page](https://github.com/astrapi69/jgeohash/blob/develop/CHANGELOG.md) 216 | 217 | ## Credits 218 | 219 | |**Travis CI**| 220 | | :---: | 221 | |![Travis CI](https://travis-ci.com/images/logos/TravisCI-Full-Color.png) | 222 | |[![build status](https://travis-ci.com/astrapi69/jgeohash.svg?branch=master)](https://travis-ci.com/astrapi69/jgeohash) | 223 | |Special thanks to [Travis CI](https://travis-ci.com) for providing a free continuous integration service for open source projects| 224 | | | 225 | 226 | |**Nexus Sonatype repositories**| 227 | | :---: | 228 | |[![sonatype repository](https://img.shields.io/nexus/r/https/oss.sonatype.org/de.alpharogroup/jgeohash-core.svg?style=for-the-badge)](https://oss.sonatype.org/index.html#nexus-search;gav~de.alpharogroup~jgeohash-core~~~) jgeohash-core| 229 | |[![sonatype repository](https://img.shields.io/nexus/r/https/oss.sonatype.org/de.alpharogroup/jgeohash-geoip.svg?style=for-the-badge)](https://oss.sonatype.org/index.html#nexus-search;gav~de.alpharogroup~jgeohash-geoip~~~) jgeohash-geoip| 230 | |Special thanks to [sonatype repository](https://www.sonatype.com) for providing a free maven repository service for open source projects| 231 | | | 232 | 233 | |**coveralls.io**| 234 | | :---: | 235 | |[![Coverage Status](https://coveralls.io/repos/github/astrapi69/jgeohash/badge.svg?branch=develop)](https://coveralls.io/github/astrapi69/jgeohash?branch=master)| 236 | |Special thanks to [coveralls.io](https://coveralls.io) for providing a free code coverage for open source projects| 237 | | | 238 | 239 | |**javadoc.io**| 240 | | :---: | 241 | |[![Javadoc](http://www.javadoc.io/badge/de.alpharogroup/jgeohash-core.svg)](http://www.javadoc.io/doc/de.alpharogroup/jgeohash-core) jgeohash-core| 242 | |[![Javadoc](http://www.javadoc.io/badge/de.alpharogroup/jgeohash-geoip.svg)](http://www.javadoc.io/doc/de.alpharogroup/jgeohash-geoip) jgeohash-geoip| 243 | |Special thanks to [javadoc.io](http://www.javadoc.io) for providing a free javadoc documentation for open source projects| 244 | | | 245 | -------------------------------------------------------------------------------- /jgeohash-core/src/test/java/de/alpharogroup/jgeohash/GeoHashExtensionsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash; 17 | 18 | import static org.testng.Assert.assertNotNull; 19 | import static org.testng.Assert.assertTrue; 20 | import static org.testng.AssertJUnit.assertEquals; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Map.Entry; 25 | 26 | import org.meanbean.factories.ObjectCreationException; 27 | import org.meanbean.test.BeanTestException; 28 | import org.meanbean.test.BeanTester; 29 | import org.testng.annotations.Test; 30 | 31 | import de.alpharogroup.collections.list.ListFactory; 32 | import de.alpharogroup.collections.map.MapFactory; 33 | import de.alpharogroup.jgeohash.model.FirstAndSecondRingRegion; 34 | import de.alpharogroup.jgeohash.model.FirstRingRegion; 35 | 36 | /** 37 | * The unit test class for the class {@link GeoHashExtensions}. 38 | */ 39 | public class GeoHashExtensionsTest 40 | { 41 | 42 | /** 43 | * Test method for {@link GeoHashExtensions#decode(String)}. 44 | */ 45 | @Test 46 | public void testDecode() 47 | { 48 | double[] actual; 49 | double[] expected; 50 | String geohash; 51 | expected = new double[2]; 52 | 53 | geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); 54 | expected[0] = 53.55263943783939d; 55 | expected[1] = 10.006710458546877d; 56 | actual = GeoHashExtensions.decode(geohash); 57 | assertEquals(expected[0], actual[0]); 58 | assertEquals(expected[1], actual[1]); 59 | 60 | geohash = GeoHashExtensions.encode(30.0, -90.0); 61 | expected[0] = 29.999999972060323d; 62 | expected[1] = -90.00000016763806d; 63 | actual = GeoHashExtensions.decode(geohash); 64 | assertEquals(expected[0], actual[0]); 65 | assertEquals(expected[1], actual[1]); 66 | 67 | geohash = GeoHashExtensions.encode(51.4797, -0.0124); 68 | expected[0] = 51.47970006801188d; 69 | expected[1] = -0.01240001991391182d; 70 | actual = GeoHashExtensions.decode(geohash); 71 | assertEquals(expected[0], actual[0]); 72 | assertEquals(expected[1], actual[1]); 73 | } 74 | 75 | /** 76 | * Test method for {@link GeoHashExtensions#decodeAndRound(String)}. 77 | */ 78 | @Test 79 | public void testDecodeAndRound() 80 | { 81 | double[] actual; 82 | double[] expected; 83 | String geohash; 84 | expected = new double[2]; 85 | 86 | geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); 87 | expected[0] = 53.552639d; 88 | expected[1] = 10.00671d; 89 | actual = GeoHashExtensions.decodeAndRound(geohash); 90 | assertEquals(expected[0], actual[0]); 91 | assertEquals(expected[1], actual[1]); 92 | 93 | geohash = GeoHashExtensions.encode(30.0, -90.0); 94 | expected[0] = 29.999999d; 95 | expected[1] = -90.0d; 96 | actual = GeoHashExtensions.decodeAndRound(geohash); 97 | assertEquals(expected[0], actual[0]); 98 | assertEquals(expected[1], actual[1]); 99 | 100 | geohash = GeoHashExtensions.encode(51.4797, -0.0124); 101 | expected[0] = 51.4797d; 102 | expected[1] = -0.0124d; 103 | actual = GeoHashExtensions.decodeAndRound(geohash); 104 | assertEquals(expected[0], actual[0]); 105 | assertEquals(expected[1], actual[1]); 106 | } 107 | 108 | /** 109 | * Test method for {@link GeoHashExtensions#decode(String)} with empty value 110 | */ 111 | @Test(expectedExceptions = IllegalArgumentException.class) 112 | public final void testDecodeWithEmptyValue() 113 | { 114 | GeoHashExtensions.decode(""); 115 | } 116 | 117 | /** 118 | * Test method for {@link GeoHashExtensions#decode(String)} with null value 119 | */ 120 | @Test(expectedExceptions = IllegalArgumentException.class) 121 | public final void testDecodeWithNullValue() 122 | { 123 | GeoHashExtensions.decode(null); 124 | } 125 | 126 | /** 127 | * Test method for {@link GeoHashExtensions#encode(double, double)}. 128 | */ 129 | @Test 130 | public void testEncode() 131 | { 132 | String expected; 133 | String actual; 134 | 135 | actual = GeoHashExtensions.encode(53.5526394, 10.0067103); 136 | expected = "u1x0esywtr81"; 137 | assertEquals(expected, actual); 138 | 139 | actual = GeoHashExtensions.encode(30.0, -90.0); 140 | expected = "9vrfxvrfxvrf"; 141 | assertEquals(expected, actual); 142 | 143 | actual = GeoHashExtensions.encode(51.4797, -0.0124); 144 | expected = "gcpuzewfzp9u"; 145 | assertEquals(expected, actual); 146 | } 147 | 148 | /** 149 | * Test method for {@link GeoHashExtensions#getAdjacent(String, String)} 150 | */ 151 | @Test(enabled = true) 152 | public void testGetAdjacentStringString() 153 | { 154 | String expected; 155 | String actual; 156 | String alterTeichwegGeohash; 157 | String geohash; 158 | String right; 159 | String left; 160 | 161 | alterTeichwegGeohash = "u1x0v54rmjwej"; 162 | geohash = alterTeichwegGeohash; 163 | 164 | expected = "h"; 165 | actual = GeoHashExtensions.getAdjacent("u", Adjacent.TOP); 166 | assertEquals(expected, actual); 167 | 168 | expected = "v"; 169 | actual = GeoHashExtensions.getAdjacent("u", Adjacent.RIGHT); 170 | assertEquals(expected, actual); 171 | 172 | expected = "s"; 173 | actual = GeoHashExtensions.getAdjacent("u", Adjacent.BOTTOM); 174 | assertEquals(expected, actual); 175 | 176 | expected = "g"; 177 | actual = GeoHashExtensions.getAdjacent("u", Adjacent.LEFT); 178 | assertEquals(expected, actual); 179 | 180 | expected = "dr"; 181 | actual = GeoHashExtensions.getAdjacent("dq", Adjacent.TOP); 182 | assertEquals(expected, actual); 183 | 184 | expected = "dw"; 185 | actual = GeoHashExtensions.getAdjacent("dq", Adjacent.RIGHT); 186 | assertEquals(expected, actual); 187 | 188 | expected = "u1x0v54rmjwem"; 189 | actual = GeoHashExtensions.getAdjacent(geohash, "top"); 190 | assertEquals(expected, actual); 191 | 192 | expected = "u1x0v54rmjwdv"; 193 | actual = GeoHashExtensions.getAdjacent(geohash, "bottom"); 194 | assertEquals(expected, actual); 195 | 196 | expected = "u1x0v54rmjwen"; 197 | actual = GeoHashExtensions.getAdjacent(geohash, "right"); 198 | right = actual; 199 | assertEquals(expected, actual); 200 | 201 | expected = "u1x0v54rmjweh"; 202 | actual = GeoHashExtensions.getAdjacent(geohash, "left"); 203 | left = actual; 204 | assertEquals(expected, actual); 205 | 206 | expected = "u1x0v54rmjwek"; 207 | actual = GeoHashExtensions.getAdjacent(left, "top"); 208 | assertEquals(expected, actual); 209 | 210 | expected = "u1x0v54rmjweq"; 211 | actual = GeoHashExtensions.getAdjacent(right, "top"); 212 | assertEquals(expected, actual); 213 | 214 | expected = "u1x0v54rmjwdy"; 215 | actual = GeoHashExtensions.getAdjacent(right, "bottom"); 216 | assertEquals(expected, actual); 217 | 218 | expected = "u1x0v54rmjwdu"; 219 | actual = GeoHashExtensions.getAdjacent(left, "bottom"); 220 | assertEquals(expected, actual); 221 | } 222 | 223 | /** 224 | * Test method for {@link GeoHashExtensions#getAdjacent(String, String...)} 225 | */ 226 | @Test(enabled = true) 227 | public void testGetAdjacentStringStringArray() 228 | { 229 | String expected; 230 | String actual; 231 | String geohash; 232 | String subGeohash; 233 | 234 | geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); 235 | subGeohash = geohash.substring(0, 7); 236 | expected = "u1x0etp"; 237 | actual = GeoHashExtensions.getAdjacent(subGeohash, Adjacent.TOP, Adjacent.RIGHT); 238 | assertEquals(expected, actual); 239 | 240 | expected = "u1x0etj"; 241 | actual = GeoHashExtensions.getAdjacent(subGeohash, Adjacent.TOP, Adjacent.LEFT); 242 | assertEquals(expected, actual); 243 | expected = "u1x0etq"; 244 | actual = GeoHashExtensions.getAdjacent(subGeohash, Adjacent.TOP, Adjacent.TOP); 245 | assertEquals(expected, actual); 246 | 247 | expected = "j"; 248 | actual = GeoHashExtensions.getAdjacent("u", Adjacent.TOP, Adjacent.RIGHT); 249 | assertEquals(expected, actual); 250 | 251 | expected = "t"; 252 | actual = GeoHashExtensions.getAdjacent("u", Adjacent.BOTTOM, Adjacent.RIGHT); 253 | assertEquals(expected, actual); 254 | 255 | expected = "e"; 256 | actual = GeoHashExtensions.getAdjacent("u", Adjacent.BOTTOM, Adjacent.LEFT); 257 | assertEquals(expected, actual); 258 | 259 | expected = "5"; 260 | actual = GeoHashExtensions.getAdjacent("u", Adjacent.LEFT, Adjacent.TOP); 261 | assertEquals(expected, actual); 262 | } 263 | 264 | /** 265 | * Test method for {@link GeoHashExtensions#getAdjacent(String, String)} with direction empty 266 | * value 267 | */ 268 | @Test(expectedExceptions = IllegalArgumentException.class) 269 | public final void testGetAdjacentStringStringDirectionEmptyValue() 270 | { 271 | GeoHashExtensions.getAdjacent("u", ""); 272 | } 273 | 274 | /** 275 | * Test method for {@link GeoHashExtensions#getAdjacent(String, String)} with direction null 276 | * value 277 | */ 278 | @Test(expectedExceptions = IllegalArgumentException.class) 279 | public final void testGetAdjacentStringStringDirectionNullValue() 280 | { 281 | GeoHashExtensions.getAdjacent("u", (String)null); 282 | } 283 | 284 | /** 285 | * Test method for {@link GeoHashExtensions#getAdjacent(String, String)} with geohash empty 286 | * value 287 | */ 288 | @Test(expectedExceptions = IllegalArgumentException.class) 289 | public final void testGetAdjacentStringStringGeohashEmptyValue() 290 | { 291 | GeoHashExtensions.getAdjacent("", Adjacent.TOP); 292 | } 293 | 294 | /** 295 | * Test method for {@link GeoHashExtensions#getAdjacent(String, String)} with geohash null value 296 | */ 297 | @Test(expectedExceptions = IllegalArgumentException.class) 298 | public final void testGetAdjacentStringStringGeohashNullValue() 299 | { 300 | GeoHashExtensions.getAdjacent(null, Adjacent.TOP); 301 | } 302 | 303 | /** 304 | * Test method for {@link GeoHashExtensions#getAllAdjacentAreasList(String)}. 305 | */ 306 | @Test 307 | public void testGetAllAdjacentAreasList() 308 | { 309 | List expected; 310 | List actual; 311 | String geohash; 312 | String subGeohash; 313 | 314 | geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); 315 | subGeohash = geohash.substring(0, 7); 316 | 317 | actual = GeoHashExtensions.getAllAdjacentAreasList(subGeohash); 318 | expected = ListFactory.newArrayList("u1x0esy", "u1x0etn", "u1x0etp", "u1x0esz", "u1x0esx", 319 | "u1x0esw", "u1x0est", "u1x0esv", "u1x0etj"); 320 | for (int i = 0; i < actual.size(); i++) 321 | { 322 | assertEquals(expected.get(i), actual.get(i)); 323 | } 324 | } 325 | 326 | /** 327 | * Test method for {@link GeoHashExtensions#decode(String)} with null value 328 | */ 329 | @Test(expectedExceptions = IllegalArgumentException.class) 330 | public final void testGetAllAdjacentAreasListNullValue() 331 | { 332 | GeoHashExtensions.getAllAdjacentAreasList(null); 333 | } 334 | 335 | /** 336 | * Test method for {@link GeoHashExtensions#decode(String)} with empty value 337 | */ 338 | @Test(expectedExceptions = IllegalArgumentException.class) 339 | public final void testGetAllAdjacentAreasListWithEmptyValue() 340 | { 341 | GeoHashExtensions.getAllAdjacentAreasList(""); 342 | } 343 | 344 | /** 345 | * Test method for {@link GeoHashExtensions#getAllAdjacentAreasMap(String)}. 346 | */ 347 | @Test 348 | public void testGetAllAdjacentAreasMap() 349 | { 350 | Map expected; 351 | Map actual; 352 | String geohash; 353 | String subGeohash; 354 | 355 | geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); 356 | subGeohash = geohash.substring(0, 7); 357 | actual = GeoHashExtensions.getAllAdjacentAreasMap(subGeohash); 358 | 359 | expected = MapFactory.newHashMap(9); 360 | expected.put("center", "u1x0esy"); 361 | expected.put("top", "u1x0etn"); 362 | expected.put("bottom", "u1x0esw"); 363 | expected.put("right", "u1x0esz"); 364 | expected.put("left", "u1x0esv"); 365 | expected.put("topleft", "u1x0etj"); 366 | expected.put("topright", "u1x0etp"); 367 | expected.put("bottomright", "u1x0esx"); 368 | expected.put("bottomleft", "u1x0est"); 369 | for (Entry entry : actual.entrySet()) 370 | { 371 | assertEquals(expected.get(entry.getKey()), actual.get(entry.getKey())); 372 | } 373 | } 374 | 375 | /** 376 | * Test method for {@link GeoHashExtensions#decode(String)} with null value 377 | */ 378 | @Test(expectedExceptions = IllegalArgumentException.class) 379 | public final void testGetAllAdjacentAreasMapNullValue() 380 | { 381 | GeoHashExtensions.getAllAdjacentAreasMap(null); 382 | } 383 | 384 | /** 385 | * Test method for {@link GeoHashExtensions#decode(String)} with empty value 386 | */ 387 | @Test(expectedExceptions = IllegalArgumentException.class) 388 | public final void testGetAllAdjacentAreasMapWithEmptyValue() 389 | { 390 | GeoHashExtensions.getAllAdjacentAreasMap(""); 391 | } 392 | 393 | /** 394 | * Test method for {@link GeoHashExtensions#getFirstAndSecondRingRegion(String)}. 395 | */ 396 | @Test 397 | public void testGetFirstAndSecondRingRegion() 398 | { 399 | FirstAndSecondRingRegion actual; 400 | FirstAndSecondRingRegion expected; 401 | String geohash; 402 | 403 | geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); 404 | actual = GeoHashExtensions.getFirstAndSecondRingRegion(geohash); 405 | assertNotNull(actual); 406 | expected = new FirstAndSecondRingRegion(geohash); 407 | assertEquals(expected, actual); 408 | } 409 | 410 | /** 411 | * Test method for {@link GeoHashExtensions#getFirstRingRegion(String)}. 412 | */ 413 | @Test 414 | public void testGetFirstRingRegion() 415 | { 416 | FirstRingRegion actual; 417 | FirstRingRegion expected; 418 | String geohash; 419 | 420 | geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); 421 | actual = GeoHashExtensions.getFirstRingRegion(geohash); 422 | assertNotNull(actual); 423 | expected = new FirstRingRegion(geohash); 424 | assertEquals(expected, actual); 425 | } 426 | 427 | /** 428 | * Test method for {@link GeoHashExtensions#getLatitude(String)}. 429 | */ 430 | @Test 431 | public void testGetLatitude() 432 | { 433 | double actual; 434 | double expected; 435 | String geohash; 436 | 437 | geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); 438 | 439 | actual = GeoHashExtensions.getLatitude(geohash); 440 | expected = 53.552639; 441 | assertEquals(expected, actual); 442 | } 443 | 444 | /** 445 | * Test method for {@link GeoHashExtensions#getLongitude(String)}. 446 | */ 447 | @Test 448 | public void testGetLongitude() 449 | { 450 | double actual; 451 | double expected; 452 | String geohash; 453 | 454 | geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); 455 | 456 | actual = GeoHashExtensions.getLongitude(geohash); 457 | expected = 10.006710; 458 | assertEquals(expected, actual); 459 | } 460 | 461 | /** 462 | * Test method for {@link GeoHashExtensions#getTwentyFiveAreasMap(String)}. 463 | */ 464 | @Test 465 | public void testGetTwentyFiveAreasMap() 466 | { 467 | Map actual; 468 | Map expected; 469 | String geohash; 470 | 471 | geohash = GeoHashExtensions.encode(53.5526394, 10.0067103); 472 | actual = GeoHashExtensions.getTwentyFiveAreasMap(geohash); 473 | assertNotNull(actual); 474 | assertTrue(actual.size() == 25); 475 | expected = MapFactory.newLinkedHashMap(25); 476 | expected.put("center", "u1x0esywtr81"); 477 | expected.put("top", "u1x0esywtr84"); 478 | expected.put("bottom", "u1x0esywtr80"); 479 | expected.put("right", "u1x0esywtr83"); 480 | expected.put("left", "u1x0esywtpxc"); 481 | expected.put("topleft", "u1x0esywtpxf"); 482 | expected.put("topright", "u1x0esywtr86"); 483 | expected.put("bottomright", "u1x0esywtr82"); 484 | expected.put("bottomleft", "u1x0esywtpxb"); 485 | expected.put("topleft_top", "u1x0esywtpxg"); 486 | expected.put("topleft_top_left", "u1x0esywtpxe"); 487 | expected.put("topleft_left", "u1x0esywtpxd"); 488 | expected.put("top_top", "u1x0esywtr85"); 489 | expected.put("topright_top", "u1x0esywtr87"); 490 | expected.put("topright_right", "u1x0esywtr8d"); 491 | expected.put("topright_top_right", "u1x0esywtr8e"); 492 | expected.put("right_right", "u1x0esywtr89"); 493 | expected.put("bottomright_right", "u1x0esywtr88"); 494 | expected.put("bottomright_bottom", "u1x0esywtr2r"); 495 | expected.put("bottomright_bottom_right", "u1x0esywtr2x"); 496 | expected.put("bottom_bottom", "u1x0esywtr2p"); 497 | expected.put("bottomleft_bottom", "u1x0esywtprz"); 498 | expected.put("bottomleft_bottom_left", "u1x0esywtprx"); 499 | expected.put("bottomleft_left", "u1x0esywtpx8"); 500 | expected.put("left_left", "u1x0esywtpx9"); 501 | for (Entry entry : actual.entrySet()) 502 | { 503 | assertEquals(expected.get(entry.getKey()), actual.get(entry.getKey())); 504 | } 505 | } 506 | 507 | /** 508 | * Test method for {@link GeoHashExtensions} 509 | */ 510 | @Test(expectedExceptions = { BeanTestException.class, ObjectCreationException.class }) 511 | public void testWithBeanTester() 512 | { 513 | final BeanTester beanTester = new BeanTester(); 514 | beanTester.testBean(GeoHashExtensions.class); 515 | } 516 | } 517 | -------------------------------------------------------------------------------- /jgeohash-core/src/main/java/de/alpharogroup/jgeohash/GeoHashExtensions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Asterios Raptis 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 de.alpharogroup.jgeohash; 17 | 18 | import java.util.ArrayList; 19 | import java.util.HashMap; 20 | import java.util.LinkedHashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | import de.alpharogroup.jgeohash.model.FirstAndSecondRingRegion; 25 | import de.alpharogroup.jgeohash.model.FirstRingRegion; 26 | import lombok.experimental.UtilityClass; 27 | 28 | /** 29 | * The class {@link GeoHashExtensions}. This class is based on http://en.wikipedia.org/wiki/Geohash. 30 | */ 31 | @UtilityClass 32 | public final class GeoHashExtensions 33 | { 34 | 35 | /** 36 | * The Constant char map BASE_32. 37 | */ 38 | private final static char[] BASE_32 = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'b', 39 | 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 40 | 'w', 'x', 'y', 'z' }; 41 | 42 | /** The Constant DECODE_MAP. */ 43 | private final static Map DECODE_MAP = new HashMap<>(); 44 | static 45 | { 46 | int counter = 0; 47 | for (final char c : BASE_32) 48 | { 49 | DECODE_MAP.put(c, counter++); 50 | } 51 | } 52 | 53 | /** The precision. */ 54 | private static final int precision = 12; 55 | 56 | /** The bits. */ 57 | private static final int[] bits = { 16, 8, 4, 2, 1 }; 58 | 59 | /** 60 | * Decode the given geohash into a latitude and longitude. 61 | * 62 | * @param geohash 63 | * the geohash 64 | * @return the double[] 65 | */ 66 | public static double[] decode(final String geohash) 67 | { 68 | if ((geohash == null) || geohash.isEmpty()) 69 | { 70 | throw new IllegalArgumentException("Argument geohash should not be null."); 71 | } 72 | 73 | boolean even = true; 74 | double latitudeError = 90.0; 75 | double longitudeError = 180.0; 76 | double latitude; 77 | double longitude; 78 | final double[] latitudeInterval = { -90.0, 90.0 }; 79 | final double[] longitudeInterval = { -180.0, 180.0 }; 80 | for (int i = 0; i < geohash.length(); i++) 81 | { 82 | 83 | final int cd = DECODE_MAP.get(geohash.charAt(i)); 84 | 85 | for (int j = 0; j < bits.length; j++) 86 | { 87 | final int mask = bits[j]; 88 | if (even) 89 | { 90 | longitudeError /= 2; 91 | if ((cd & mask) != 0) 92 | { 93 | longitudeInterval[0] = (longitudeInterval[0] + longitudeInterval[1]) / 2D; 94 | } 95 | else 96 | { 97 | longitudeInterval[1] = (longitudeInterval[0] + longitudeInterval[1]) / 2D; 98 | } 99 | 100 | } 101 | else 102 | { 103 | latitudeError /= 2; 104 | 105 | if ((cd & mask) != 0) 106 | { 107 | latitudeInterval[0] = (latitudeInterval[0] + latitudeInterval[1]) / 2D; 108 | } 109 | else 110 | { 111 | latitudeInterval[1] = (latitudeInterval[0] + latitudeInterval[1]) / 2D; 112 | } 113 | } 114 | 115 | even = !even; 116 | } 117 | 118 | } 119 | latitude = (latitudeInterval[0] + latitudeInterval[1]) / 2D; 120 | longitude = (longitudeInterval[0] + longitudeInterval[1]) / 2D; 121 | 122 | return new double[] { latitude, longitude, latitudeError, longitudeError }; 123 | } 124 | 125 | /** 126 | * Decodes the given geohash into a latitude and longitude. 127 | * 128 | * @param geohash 129 | * the geohash 130 | * @return the double[] 131 | */ 132 | public static double[] decodeAndRound(final String geohash) 133 | { 134 | final double[] ge = decode(geohash); 135 | double latitude = ge[0]; 136 | double longitude = ge[1]; 137 | final double latitudeError = ge[2]; 138 | final double longitudeError = ge[3]; 139 | 140 | final double latitudePrecision = Math.max(1, Math.round(-Math.log10(latitudeError))) - 1; 141 | final double longitudePrecision = Math.max(1, Math.round(-Math.log10(longitudeError))) - 1; 142 | 143 | latitude = getPrecision(latitude, latitudePrecision); 144 | longitude = getPrecision(longitude, longitudePrecision); 145 | 146 | return new double[] { latitude, longitude }; 147 | } 148 | 149 | /** 150 | * Encodes the given latitude and longitude into a geohash code. 151 | * 152 | * @param latitude 153 | * the latitude 154 | * @param longitude 155 | * the longitude 156 | * @return The generated geohash from the given latitude and longitude. 157 | */ 158 | public static String encode(final double latitude, final double longitude) 159 | { 160 | final StringBuilder geohash = new StringBuilder(); 161 | boolean even = true; 162 | int bit = 0; 163 | int ch = 0; 164 | 165 | final double[] latitudeInterval = { -90.0, 90.0 }; 166 | final double[] longitudeInterval = { -180.0, 180.0 }; 167 | 168 | while (geohash.length() < precision) 169 | { 170 | double mid = 0.0; 171 | if (even) 172 | { 173 | mid = (longitudeInterval[0] + longitudeInterval[1]) / 2D; 174 | if (longitude > mid) 175 | { 176 | ch |= bits[bit]; 177 | longitudeInterval[0] = mid; 178 | } 179 | else 180 | { 181 | longitudeInterval[1] = mid; 182 | } 183 | 184 | } 185 | else 186 | { 187 | mid = (latitudeInterval[0] + latitudeInterval[1]) / 2D; 188 | if (latitude > mid) 189 | { 190 | ch |= bits[bit]; 191 | latitudeInterval[0] = mid; 192 | } 193 | else 194 | { 195 | latitudeInterval[1] = mid; 196 | } 197 | } 198 | 199 | even = !even; 200 | 201 | if (bit < 4) 202 | { 203 | bit++; 204 | } 205 | else 206 | { 207 | geohash.append(BASE_32[ch]); 208 | bit = 0; 209 | ch = 0; 210 | } 211 | } 212 | 213 | return geohash.toString(); 214 | } 215 | 216 | /** 217 | * Gets the adjacent from the given direction. For instance if direction is 'top' then the top 218 | * adjacent geohash code will be returned. 219 | * 220 | * @param geohash 221 | * the geohash 222 | * @param direction 223 | * the direction 224 | * @return the geohash code for the adjacent from the given direction. 225 | */ 226 | public static String getAdjacent(final String geohash, final String direction) 227 | { 228 | if ((geohash == null) || geohash.isEmpty()) 229 | { 230 | throw new IllegalArgumentException("Argument geohash should not be null or empty."); 231 | } 232 | if ((direction == null) || direction.isEmpty()) 233 | { 234 | throw new IllegalArgumentException("Argument direction should not be null or empty."); 235 | } 236 | final String lowerCaseGeohash = geohash.toLowerCase(); 237 | final char lastChar = lowerCaseGeohash.charAt(lowerCaseGeohash.length() - 1); 238 | final int modulo = lowerCaseGeohash.length() % 2; 239 | final String type = modulo == 0 ? Adjacent.ODD : Adjacent.EVEN; 240 | String base = lowerCaseGeohash.substring(0, lowerCaseGeohash.length() - 1); 241 | final Map borderDirection = Adjacent.Borders.borders.get(direction); 242 | final String borderDirectionType = borderDirection.get(type); 243 | final int indexOfLastChar = borderDirectionType.indexOf(lastChar); 244 | if ((indexOfLastChar != -1) && !base.isEmpty()) 245 | { 246 | base = getAdjacent(base, direction); 247 | } 248 | final Map neighborsDirection = Adjacent.Neighbors.neighbors.get(direction); 249 | final String neighborsDirectionType = neighborsDirection.get(type); 250 | final int i = neighborsDirectionType.indexOf(lastChar); 251 | final char r = BASE_32[i]; 252 | return base + r; 253 | } 254 | 255 | /** 256 | * Gets the adjacent from the given directions. For instance if directions is 'top' and 'feft' 257 | * then the topleft adjacent geohash code will be returned. 258 | * 259 | * @param geohash 260 | * the geohash 261 | * @param directions 262 | * the directions 263 | * @return the geohash code for the adjacent from the given directions. 264 | */ 265 | public static String getAdjacent(final String geohash, final String... directions) 266 | { 267 | String geohashresult = geohash; 268 | for (final String direction : directions) 269 | { 270 | geohashresult = getAdjacent(geohashresult, direction); 271 | } 272 | return geohashresult; 273 | } 274 | 275 | /** 276 | * Gets the all adjacent areas list. 277 | * 278 | * @param geohash 279 | * the geohash 280 | * @return the all adjacent areas list 281 | */ 282 | public static List getAllAdjacentAreasList(final String geohash) 283 | { 284 | if ((geohash == null) || geohash.isEmpty()) 285 | { 286 | throw new IllegalArgumentException("Argument geohash should not be null."); 287 | } 288 | 289 | final List adjacentAreas = new ArrayList<>(); 290 | final String top = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP); 291 | final String bottom = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM); 292 | final String right = GeoHashExtensions.getAdjacent(geohash, Adjacent.RIGHT); 293 | final String left = GeoHashExtensions.getAdjacent(geohash, Adjacent.LEFT); 294 | final String topleft = GeoHashExtensions.getAdjacent(left, Adjacent.TOP); 295 | final String topright = GeoHashExtensions.getAdjacent(right, Adjacent.TOP); 296 | final String bottomright = GeoHashExtensions.getAdjacent(right, Adjacent.BOTTOM); 297 | final String bottomleft = GeoHashExtensions.getAdjacent(left, Adjacent.BOTTOM); 298 | adjacentAreas.add(geohash); 299 | adjacentAreas.add(top); 300 | adjacentAreas.add(topright); 301 | adjacentAreas.add(right); 302 | adjacentAreas.add(bottomright); 303 | adjacentAreas.add(bottom); 304 | adjacentAreas.add(bottomleft); 305 | adjacentAreas.add(left); 306 | adjacentAreas.add(topleft); 307 | return adjacentAreas; 308 | } 309 | 310 | /** 311 | * Gets the geohash cells around the given geohash cell. With other words it gets eight cells 312 | * around the given geohash cell so the first ring inclusive the given geohash cell. 313 | * 314 | * @param geohash 315 | * the geohash 316 | * @return all geohash cells around the given geohash cell. 317 | */ 318 | public static Map getAllAdjacentAreasMap(final String geohash) 319 | { 320 | if ((geohash == null) || geohash.isEmpty()) 321 | { 322 | throw new IllegalArgumentException("Argument geohash should not be null."); 323 | } 324 | 325 | final String top = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP); 326 | final String bottom = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM); 327 | final String right = GeoHashExtensions.getAdjacent(geohash, Adjacent.RIGHT); 328 | final String left = GeoHashExtensions.getAdjacent(geohash, Adjacent.LEFT); 329 | final String topleft = GeoHashExtensions.getAdjacent(left, Adjacent.TOP); 330 | final String topright = GeoHashExtensions.getAdjacent(right, Adjacent.TOP); 331 | final String bottomright = GeoHashExtensions.getAdjacent(right, Adjacent.BOTTOM); 332 | final String bottomleft = GeoHashExtensions.getAdjacent(left, Adjacent.BOTTOM); 333 | 334 | final Map adjacentAreas = new LinkedHashMap<>(); 335 | adjacentAreas.put(Adjacent.CENTER, geohash); 336 | adjacentAreas.put(Adjacent.TOP, top); 337 | adjacentAreas.put(Adjacent.BOTTOM, bottom); 338 | adjacentAreas.put(Adjacent.RIGHT, right); 339 | adjacentAreas.put(Adjacent.LEFT, left); 340 | adjacentAreas.put(Adjacent.TOP_LEFT, topleft); 341 | adjacentAreas.put(Adjacent.TOP_RIGHT, topright); 342 | adjacentAreas.put(Adjacent.BOTTOM_RIGHT, bottomright); 343 | adjacentAreas.put(Adjacent.BOTTOM_LEFT, bottomleft); 344 | 345 | return adjacentAreas; 346 | } 347 | 348 | /** 349 | * Gets the geohash cells of the first and second ring region around the given geohash cell as a 350 | * {@link FirstAndSecondRingRegion} object. 351 | * 352 | * @param geohash 353 | * the geohash cell. 354 | * @return the {@link FirstAndSecondRingRegion} that encapsulates the cells of the first and 355 | * second ring region around the given geohash cell. 356 | */ 357 | public static FirstAndSecondRingRegion getFirstAndSecondRingRegion(final String geohash) 358 | { 359 | return new FirstAndSecondRingRegion(geohash); 360 | } 361 | 362 | /** 363 | * Gets the geohash cells around the given geohash cell as a {@link FirstRingRegion} object. 364 | * 365 | * @param geohash 366 | * the geohash cell. 367 | * @return the {@link FirstRingRegion} object calculated from the given geohash value. 368 | */ 369 | public static FirstRingRegion getFirstRingRegion(final String geohash) 370 | { 371 | return new FirstRingRegion(geohash); 372 | } 373 | 374 | /** 375 | * Gets the latitude from the given geohash value. 376 | * 377 | * @param geohash 378 | * the geohash 379 | * @return the latitude 380 | */ 381 | public static double getLatitude(final String geohash) 382 | { 383 | return decodeAndRound(geohash)[0]; 384 | } 385 | 386 | /** 387 | * Gets the longitude from the given geohash value. 388 | * 389 | * @param geohash 390 | * the geohash 391 | * @return the longitude 392 | */ 393 | public static double getLongitude(final String geohash) 394 | { 395 | return decodeAndRound(geohash)[1]; 396 | } 397 | 398 | /** 399 | * Gets the precision. 400 | * 401 | * @param x 402 | * the x 403 | * @param precision 404 | * the precision 405 | * @return the precision 406 | */ 407 | private static double getPrecision(final double x, final double precision) 408 | { 409 | final double base = Math.pow(10, -precision); 410 | final double diff = x % base; 411 | return x - diff; 412 | } 413 | 414 | /** 415 | * Gets the eight cells around the given geohash cell so the first ring inclusive the given 416 | * geohash cell and cells from the second ring. The result is 24 cells plus the given geohash 417 | * cell. 418 | * 419 | * @param geohash 420 | * the geohash 421 | * @return the eight cells around the given geohash cell so the first ring inclusive the given 422 | * geohash cell and cells from the second ring. 423 | */ 424 | public static Map getTwentyFiveAreasMap(final String geohash) 425 | { 426 | final Map adjacentAreas = getAllAdjacentAreasMap(geohash); 427 | 428 | final String topTop = GeoHashExtensions.getAdjacent(adjacentAreas.get(Adjacent.TOP), 429 | Adjacent.TOP); 430 | final String topLeftTop = GeoHashExtensions 431 | .getAdjacent(adjacentAreas.get(Adjacent.TOP_LEFT), Adjacent.TOP); 432 | final String topLeftTopLeft = GeoHashExtensions.getAdjacent(topLeftTop, Adjacent.LEFT); 433 | final String topLeftLeft = GeoHashExtensions 434 | .getAdjacent(adjacentAreas.get(Adjacent.TOP_LEFT), Adjacent.LEFT); 435 | final String topRightTop = GeoHashExtensions 436 | .getAdjacent(adjacentAreas.get(Adjacent.TOP_RIGHT), Adjacent.TOP); 437 | final String topRightTopRight = GeoHashExtensions.getAdjacent(topRightTop, Adjacent.RIGHT); 438 | final String topRightRight = GeoHashExtensions 439 | .getAdjacent(adjacentAreas.get(Adjacent.TOP_RIGHT), Adjacent.RIGHT); 440 | final String rightRight = GeoHashExtensions.getAdjacent(adjacentAreas.get(Adjacent.RIGHT), 441 | Adjacent.RIGHT); 442 | final String bottomRightRight = GeoHashExtensions 443 | .getAdjacent(adjacentAreas.get(Adjacent.BOTTOM_RIGHT), Adjacent.RIGHT); 444 | final String bottomRightBottom = GeoHashExtensions 445 | .getAdjacent(adjacentAreas.get(Adjacent.BOTTOM_RIGHT), Adjacent.BOTTOM); 446 | final String bottomRightBottomRight = GeoHashExtensions.getAdjacent(bottomRightBottom, 447 | Adjacent.RIGHT); 448 | final String bottomBottom = GeoHashExtensions 449 | .getAdjacent(adjacentAreas.get(Adjacent.BOTTOM), Adjacent.BOTTOM); 450 | final String bottomLeftBottom = GeoHashExtensions 451 | .getAdjacent(adjacentAreas.get(Adjacent.BOTTOM_LEFT), Adjacent.BOTTOM); 452 | final String bottomLeftBottomLeft = GeoHashExtensions.getAdjacent(bottomLeftBottom, 453 | Adjacent.LEFT); 454 | final String bottomLeftLeft = GeoHashExtensions 455 | .getAdjacent(adjacentAreas.get(Adjacent.BOTTOM_LEFT), Adjacent.LEFT); 456 | final String leftLeft = GeoHashExtensions.getAdjacent(adjacentAreas.get(Adjacent.LEFT), 457 | Adjacent.LEFT); 458 | 459 | adjacentAreas.put(Adjacent.TOP_LEFT_TOP, topLeftTop); 460 | adjacentAreas.put(Adjacent.TOP_LEFT_TOP_LEFT, topLeftTopLeft); 461 | adjacentAreas.put(Adjacent.TOP_LEFT_LEFT, topLeftLeft); 462 | adjacentAreas.put(Adjacent.TOP_TOP, topTop); 463 | adjacentAreas.put(Adjacent.TOP_RIGHT_TOP, topRightTop); 464 | adjacentAreas.put(Adjacent.TOP_RIGHT_RIGHT, topRightRight); 465 | adjacentAreas.put(Adjacent.TOP_RIGHT_TOP_RIGHT, topRightTopRight); 466 | adjacentAreas.put(Adjacent.RIGHT_RIGHT, rightRight); 467 | adjacentAreas.put(Adjacent.BOTTOM_RIGHT_RIGHT, bottomRightRight); 468 | adjacentAreas.put(Adjacent.BOTTOM_RIGHT_BOTTOM, bottomRightBottom); 469 | adjacentAreas.put(Adjacent.BOTTOM_RIGHT_BOTTOM_RIGHT, bottomRightBottomRight); 470 | adjacentAreas.put(Adjacent.BOTTOM_BOTTOM, bottomBottom); 471 | adjacentAreas.put(Adjacent.BOTTOM_LEFT_BOTTOM, bottomLeftBottom); 472 | adjacentAreas.put(Adjacent.BOTTOM_LEFT_BOTTOM_LEFT, bottomLeftBottomLeft); 473 | adjacentAreas.put(Adjacent.BOTTOM_LEFT_LEFT, bottomLeftLeft); 474 | adjacentAreas.put(Adjacent.LEFT_LEFT, leftLeft); 475 | 476 | return adjacentAreas; 477 | } 478 | 479 | } 480 | --------------------------------------------------------------------------------