From cc962f169b652c51136345968d25f8fe346aaa56 Mon Sep 17 00:00:00 2001 From: lucasstarsz Date: Sat, 27 Jul 2024 13:48:50 -0400 Subject: [PATCH] more code cleanup --- .../java/io/github/lucasstarsz/fxdex/App.java | 2 +- .../fxdex/model/JsonDexEntryItem.java | 38 +++++++++++++++++++ .../lucasstarsz/fxdex/model/JsonDexItem.java | 32 ++++++++++++++++ .../fxdex/model/JsonDexListItem.java | 32 ++++++++++++++++ .../lucasstarsz/fxdex/service/UiService.java | 2 +- .../fxdex/vmodel/DexEntryViewModel.java | 2 +- src/main/java/module-info.java | 1 + 7 files changed, 106 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/lucasstarsz/fxdex/App.java b/src/main/java/io/github/lucasstarsz/fxdex/App.java index 77fbfe8..36e1b01 100644 --- a/src/main/java/io/github/lucasstarsz/fxdex/App.java +++ b/src/main/java/io/github/lucasstarsz/fxdex/App.java @@ -40,7 +40,7 @@ public class App extends Application { private static final VBox DefaultParent = new VBox(); - public static final StringProperty PokedexEntry = new SimpleStringProperty(); + public static final StringProperty CurrentDexEntry = new SimpleStringProperty(); public static final StringProperty CurrentScene = new SimpleStringProperty(); public static final Property DexThreadHandler = new SimpleObjectProperty<>(); diff --git a/src/main/java/io/github/lucasstarsz/fxdex/model/JsonDexEntryItem.java b/src/main/java/io/github/lucasstarsz/fxdex/model/JsonDexEntryItem.java index 29cdd8c..23b34d2 100644 --- a/src/main/java/io/github/lucasstarsz/fxdex/model/JsonDexEntryItem.java +++ b/src/main/java/io/github/lucasstarsz/fxdex/model/JsonDexEntryItem.java @@ -1,6 +1,9 @@ package io.github.lucasstarsz.fxdex.model; import io.github.lucasstarsz.fxdex.service.JsonParserService; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; import org.json.JSONObject; import java.util.List; @@ -35,4 +38,39 @@ public List getEggGroups() { public Map getFlavorTexts() { return flavorTexts; } + + @Override + public boolean equals(Object other) { + if (this == other) return true; + if (other == null || getClass() != other.getClass()) return false; + + JsonDexEntryItem dexEntryItem = (JsonDexEntryItem) other; + + return new EqualsBuilder() + .append(genus, dexEntryItem.genus) + .append(generation, dexEntryItem.generation) + .append(eggGroups, dexEntryItem.eggGroups) + .append(flavorTexts, dexEntryItem.flavorTexts) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder() + .append(genus) + .append(generation) + .append(eggGroups) + .append(flavorTexts) + .toHashCode(); + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("genus", genus) + .append("generation", generation) + .append("eggGroups", eggGroups) + .append("flavorTexts", flavorTexts) + .toString(); + } } diff --git a/src/main/java/io/github/lucasstarsz/fxdex/model/JsonDexItem.java b/src/main/java/io/github/lucasstarsz/fxdex/model/JsonDexItem.java index b2ff4a2..0dd1acf 100644 --- a/src/main/java/io/github/lucasstarsz/fxdex/model/JsonDexItem.java +++ b/src/main/java/io/github/lucasstarsz/fxdex/model/JsonDexItem.java @@ -1,5 +1,8 @@ package io.github.lucasstarsz.fxdex.model; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; import org.json.JSONObject; public class JsonDexItem { @@ -19,4 +22,33 @@ public String getApiPokedexName() { public String getApiPokedexUrl() { return apiPokedexUrl; } + + @Override + public boolean equals(Object other) { + if (this == other) return true; + if (other == null || getClass() != other.getClass()) return false; + + JsonDexItem dexItem = (JsonDexItem) other; + + return new EqualsBuilder() + .append(apiPokedexName, dexItem.apiPokedexName) + .append(apiPokedexUrl, dexItem.apiPokedexUrl) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder() + .append(apiPokedexName) + .append(apiPokedexUrl) + .toHashCode(); + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("apiPokedexName", apiPokedexName) + .append("apiPokedexUrl", apiPokedexUrl) + .toString(); + } } diff --git a/src/main/java/io/github/lucasstarsz/fxdex/model/JsonDexListItem.java b/src/main/java/io/github/lucasstarsz/fxdex/model/JsonDexListItem.java index 29cd3a1..5e653df 100644 --- a/src/main/java/io/github/lucasstarsz/fxdex/model/JsonDexListItem.java +++ b/src/main/java/io/github/lucasstarsz/fxdex/model/JsonDexListItem.java @@ -1,5 +1,8 @@ package io.github.lucasstarsz.fxdex.model; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; import org.json.JSONObject; public class JsonDexListItem { @@ -19,4 +22,33 @@ public int getDexNumber() { public String getApiPokemonName() { return apiPokemonName; } + + @Override + public boolean equals(Object other) { + if (this == other) return true; + if (other == null || getClass() != other.getClass()) return false; + + JsonDexListItem dexListItem = (JsonDexListItem) other; + + return new EqualsBuilder() + .append(dexNumber, dexListItem.dexNumber) + .append(apiPokemonName, dexListItem.apiPokemonName) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder() + .append(dexNumber) + .append(apiPokemonName) + .toHashCode(); + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("dexNumber", dexNumber) + .append("apiPokemonName", apiPokemonName) + .toString(); + } } diff --git a/src/main/java/io/github/lucasstarsz/fxdex/service/UiService.java b/src/main/java/io/github/lucasstarsz/fxdex/service/UiService.java index 68c4a27..9c42286 100644 --- a/src/main/java/io/github/lucasstarsz/fxdex/service/UiService.java +++ b/src/main/java/io/github/lucasstarsz/fxdex/service/UiService.java @@ -40,7 +40,7 @@ default Label createPokedexListItem(int pokemonDigitCount, JsonDexListItem dexEn Label pokemonLabel = new Label(dexNumberString + ": " + pokemonName); pokemonLabel.onMousePressedProperty().set((event) -> { - App.PokedexEntry.set(dexEntryFromList.getApiPokemonName()); + App.CurrentDexEntry.set(dexEntryFromList.getApiPokemonName()); App.CurrentScene.set("pokedexEntry.fxml"); }); diff --git a/src/main/java/io/github/lucasstarsz/fxdex/vmodel/DexEntryViewModel.java b/src/main/java/io/github/lucasstarsz/fxdex/vmodel/DexEntryViewModel.java index 8002e63..8eaa1dc 100644 --- a/src/main/java/io/github/lucasstarsz/fxdex/vmodel/DexEntryViewModel.java +++ b/src/main/java/io/github/lucasstarsz/fxdex/vmodel/DexEntryViewModel.java @@ -44,7 +44,7 @@ public DexEntryViewModel(DexService dexService) { this.dexService = dexService; currentDexEntryName = new SimpleStringProperty(); - currentDexEntryName.bind(App.PokedexEntry); + currentDexEntryName.bind(App.CurrentDexEntry); dexEntriesList = new SimpleListProperty<>(FXCollections.observableArrayList()); } diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index ce9761f..dad0485 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -30,4 +30,5 @@ requires com.google.guice; // required for Guice to function. requires jakarta.inject; + requires org.apache.commons.lang3; }