Skip to content

Commit

Permalink
more code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasstarsz committed Jul 27, 2024
1 parent 1e2f583 commit cc962f1
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/io/github/lucasstarsz/fxdex/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExecutorService> DexThreadHandler = new SimpleObjectProperty<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -35,4 +38,39 @@ public List<String> getEggGroups() {
public Map<String, String> 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();
}
}
32 changes: 32 additions & 0 deletions src/main/java/io/github/lucasstarsz/fxdex/model/JsonDexItem.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
requires com.google.guice;
// required for Guice to function.
requires jakarta.inject;
requires org.apache.commons.lang3;
}

0 comments on commit cc962f1

Please sign in to comment.