add equals and hashcode to coordinate class
This commit is contained in:
@@ -1 +0,0 @@
|
||||
/home/sem/Development/Minecraft/mc-ic-server/ic_plugin/src/main/java/nl/interestingcorner/coordinates/db/Coordinate.java
|
||||
@@ -1 +0,0 @@
|
||||
/home/sem/Development/Minecraft/mc-ic-server/ic_plugin/src/main/java/nl/interestingcorner/coordinates/db/DatabaseManager.java
|
||||
@@ -1 +0,0 @@
|
||||
/home/sem/Development/Minecraft/mc-ic-server/ic_plugin/src/main/java/nl/interestingcorner/coordinates/db/MinecraftColor.java
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user