add equals and hashcode to coordinate class

This commit is contained in:
SemvdH
2025-11-10 19:42:21 +01:00
parent 1aa6a9f374
commit c56fe10564
8 changed files with 40 additions and 6 deletions

View File

@@ -1 +0,0 @@
/home/sem/Development/Minecraft/mc-ic-server/ic_plugin/src/main/java/nl/interestingcorner/coordinates/db/Coordinate.java

View File

@@ -1 +0,0 @@
/home/sem/Development/Minecraft/mc-ic-server/ic_plugin/src/main/java/nl/interestingcorner/coordinates/db/DatabaseManager.java

View File

@@ -1 +0,0 @@
/home/sem/Development/Minecraft/mc-ic-server/ic_plugin/src/main/java/nl/interestingcorner/coordinates/db/MinecraftColor.java

View File

@@ -9,7 +9,6 @@
<packaging>jar</packaging>
<name>ic_plugin_coordinates</name>
<!-- FIXME change it to the project's website -->
<url>https://interesting-corner.nl</url>
<properties>

View File

@@ -24,6 +24,7 @@ import nl.interestingcorner.core.MinecraftColor;
* Class to represent a coordinate to teleport to
*/
public class Coordinate {
private final int HASH_PRIME = 31;
/**
* auto-generated ID
*/
@@ -108,4 +109,37 @@ public class Coordinate {
.append(" }");
return sb.toString();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
{
return true;
}
if (obj == null || getClass() != obj.getClass())
{
return false;
}
Coordinate other = (Coordinate) obj;
return id == other.id &&
nether == other.nether &&
name.equals(other.name) &&
description.equals(other.description) &&
position.equals(other.position) &&
world.equals(other.world) &&
color == other.color;
}
@Override
public int hashCode() {
int result = Integer.hashCode(id);
result = HASH_PRIME * result + Boolean.hashCode(nether);
result = HASH_PRIME * result + (name != null ? name.hashCode() : 0);
result = HASH_PRIME * result + (description != null ? description.hashCode() : 0);
result = HASH_PRIME * result + (position != null ? position.hashCode() : 0);
result = HASH_PRIME * result + (world != null ? world.hashCode() : 0);
result = HASH_PRIME * result + (color != null ? color.hashCode() : 0);
return result;
}
}

View File

@@ -120,6 +120,11 @@ public enum CoordinatesDatabaseManager implements nl.interestingcorner.core.db.D
return true;
}
public boolean addCoordinate(Coordinate coordinate) {
return addCoordinate(coordinate.name, coordinate.description, coordinate.position, coordinate.nether,
coordinate.world, coordinate.color);
}
/**
* initializes the tables for the database.
*

View File

@@ -9,7 +9,6 @@
<packaging>jar</packaging>
<name>ic_plugin_core</name>
<!-- FIXME change it to the project's website -->
<url>https://interesting-corner.nl</url>
<properties>

View File

@@ -40,7 +40,7 @@ public enum DatabaseManager {
}
/**
* Closes the connectino to the database
* Closes the connection to the database
*
* @return true if the connection closed succesfully, false if not.
*/