Skip to content

Commit

Permalink
Merge pull request #6 from tomaytotomato/2-binarise-data
Browse files Browse the repository at this point in the history
2- Binarise location4j data
  • Loading branch information
tomaytotomato authored Aug 9, 2024
2 parents f1eedc9 + 981c4f7 commit 7335d75
Show file tree
Hide file tree
Showing 42 changed files with 230 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: mvn versions:set -DnewVersion=${{ env.RELEASE_VERSION }} && mvn package -DskipTests

- name: Deploy Github and Maven Central
run: mvn deploy
run: mvn deploy -Prelease
env:
GITHUB_USERNAME: ${{ secrets.GITHUB_ACTOR }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions library/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.tomaytotomato</groupId>
<artifactId>location4j</artifactId>
<version>1.0.0</version>
</parent>

<artifactId>library</artifactId>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.tomaytotomato.loader;

import com.tomaytotomato.model.Country;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DefaultCountriesDataLoaderImpl implements CountriesDataLoader {

private static final String DEFAULT_FILE = "location4j.bin";
private final List<Country> countries = new ArrayList<>();

/**
* Loads a list of {@link Country} from the location4j.bin file.
*/
public DefaultCountriesDataLoaderImpl() {
var logger = Logger.getLogger(this.getClass().getName());
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(DEFAULT_FILE)) {
logger.info("Attempting to load countries from " + DEFAULT_FILE);
if (inputStream == null) {
throw new IllegalArgumentException("File not found: " + DEFAULT_FILE);
}

loadLocationsFromBinary(inputStream, logger);
} catch (IOException | ClassNotFoundException e) {
logger.log(Level.SEVERE, "Failed to load countries file: " + e.getMessage(), e);
}
}

private void loadLocationsFromBinary(InputStream inputStream, Logger logger)
throws IOException, ClassNotFoundException {
try (var objectInputStream = new ObjectInputStream(inputStream)) {
// Read the list of countries from the binary file
List<Country> loadedCountries = (List<Country>) objectInputStream.readObject();
this.countries.addAll(loadedCountries);
logger.info("Successfully loaded countries binary file");
} catch (IOException | ClassNotFoundException e) {
logger.log(Level.SEVERE, "Failed to parse countries file: " + e.getMessage(), e);
}
}

@Override
public List<Country> getCountries() {
return countries;
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
package com.tomaytotomato.model;


import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Objects;

public class City {
public class City implements Serializable {

private static final long serialVersionUID = 1L;

private Integer id;
@JsonIgnore
private Integer countryId;
@JsonIgnore
private String countryName;
@JsonIgnore
private String countryIso2Code;
@JsonIgnore
private String countryIso3Code;
@JsonIgnore
private Integer stateId;
@JsonIgnore
private String stateName;
@JsonIgnore
private String stateCode;
private String name;
private BigDecimal latitude;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
package com.tomaytotomato.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class Country {
public class Country implements Serializable {

private static final long serialVersionUID = 1L;

private Integer id;
private String name;
private String iso3;
private String iso2;
private String zoneName;
@JsonProperty("phone_code")
private String phoneCode;
@JsonProperty("numeric_code")
private String numericCode;
private String capital;
private String currency;
@JsonProperty("currency_name")
private String currencyName;
@JsonProperty("currency_symbol")
private String currencySymbol;
private String tld;
@JsonProperty("native")
private String nativeName;
private String region;
@JsonProperty("region_id")
private String regionId;
private String subregion;
@JsonProperty("subregion_id")
private String subregionId;
private List<State> states;
private String nationality;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.tomaytotomato.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonCreator.Mode;
import java.math.BigDecimal;

public class Location {
Expand All @@ -22,7 +20,6 @@ public class Location {
public Location() {
}

@JsonCreator(mode = Mode.DISABLED)
public Location(String countryName, Integer countryId, String countryIso2Code,
String countryIso3Code, String state, Integer stateId, String stateCode, String stateName, String city,
Integer cityId, BigDecimal latitude, BigDecimal longitude) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
package com.tomaytotomato.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonCreator.Mode;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

public class State {
public class State implements Serializable {

private static final long serialVersionUID = 1L;

private Integer id;
@JsonIgnore
private Integer countryId;
@JsonIgnore
private String countryName;
@JsonIgnore
private String countryIso2Code;
@JsonIgnore
private String countryIso3Code;

private String name;
private String type;
@JsonProperty("state_code")
private String stateCode;
private List<City> cities;
private BigDecimal latitude;
private BigDecimal longitude;

State() {}

@JsonCreator(mode = Mode.DISABLED)
public State(Integer id, Integer countryId, String countryName, String countryIso2Code,
String countryIso3Code, String name, String type, String stateCode, List<City> cities,
BigDecimal latitude, BigDecimal longitude) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.tomaytotomato.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonCreator.Mode;
import java.io.Serializable;
import java.util.Objects;

public class TimeZone {
public class TimeZone implements Serializable {

private static final long serialVersionUID = 1L;

private String zoneName;
private String abbreviation;
private String tzName;
private Integer gmtOffset;
private String gmtOffsetName;

TimeZone() { }
TimeZone() {
}

@JsonCreator(mode = Mode.DISABLED)
public TimeZone(String zoneName, String abbreviation, String tzName, Integer gmtOffset,
String gmtOffsetName) {
this.zoneName = zoneName;
Expand Down
Binary file added library/src/main/resources/location4j.bin
Binary file not shown.
36 changes: 19 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@

<groupId>com.tomaytotomato</groupId>
<artifactId>location4j</artifactId>
<version>1.0.0</version> <!-- this version is overridden by Github Action check release.yml !-->
<version>1.0.0</version>
<packaging>pom</packaging> <!-- this version is overridden by Github Action check release.yml !-->
<description>A location service for Java, identify a city, state or country by multiple terms.
</description>
<modules>
<module>tools</module>
<module>library</module>
</modules>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit-jupiter.version>5.10.3</junit-jupiter.version>
<assertj-core.version>3.26.3</assertj-core.version>
<jackson-core.version>2.17.2</jackson-core.version>
<maven-surefire-plugin.version>3.3.1</maven-surefire-plugin.version>
<jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>
<sonar.organization>tomaytotomato</sonar.organization>
Expand Down Expand Up @@ -66,21 +70,6 @@
</scm>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-core.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-core.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson-core.version}</version>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -194,4 +183,17 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>release</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<modules>
<module>library</module>
</modules>
</profile>
</profiles>

</project>
8 changes: 4 additions & 4 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ sonar.issue.ignore.multicriteria=e1
sonar.issue.ignore.multicriteria.e1.ruleKey=squid:S00122 # Replace with the specific rule key for duplication
sonar.issue.ignore.multicriteria.e1.resourceKey=src/main/java/com/tomaytotomato/model/**

# Include for Sonar checks
sonar.sources=src/main/java
# Include only the library module for Sonar checks
sonar.sources=library/src/main/java

# Exclude from Sonar checks
sonar.exclusions=pom.xml, src/test/java/**
# Exclude certain files or directories from Sonar checks
sonar.exclusions=**/pom.xml, **/src/test/java/**, **/tools/**

This file was deleted.

Loading

0 comments on commit 7335d75

Please sign in to comment.