@Override public boolean equals(Object obj) { if (!(obj instanceof MDIdentifier)) { return false; } MDIdentifier id = (MDIdentifier) obj; if (id.getCoordinates().length != this.coordinates.length) { return false; } for (int i = 0; i < this.coordinates.length; i++) { if (this.coordinates[i] != id.getCoordinate(i)) { return false; } } return true; }
@Override public Double distance(Identifier<Double> id) { MDIdentifier to = (MDIdentifier) id; if (this.idSpace.getDimensions() != to.getIdSpace().getDimensions()) { throw new RuntimeException( "Cannot compute a distance between MDIntentifiers in spaces with unequal dimensions"); } double temp; if (this.idSpace.getDistFunc() == DistanceMD.EUCLIDEAN) { double squarredResult = 0; for (int i = 0; i < this.idSpace.getDimensions(); i++) { if (this.idSpace.isWrapAround()) { temp = Math.min( Math.abs(this.coordinates[i] - to.getCoordinate(i)), Math.min( this.idSpace.getModulus(i) + this.coordinates[i] - to.getCoordinate(i), this.idSpace.getModulus(i) - this.coordinates[i] + to.getCoordinate(i))); } else { temp = Math.abs(this.coordinates[i] - to.getCoordinate(i)); } squarredResult += Math.pow(temp, 2); } return Math.sqrt(squarredResult); } if (this.idSpace.getDistFunc() == DistanceMD.MANHATTAN) { double result = 0; for (int i = 0; i < this.idSpace.getDimensions(); i++) { if (this.idSpace.isWrapAround()) { temp = Math.min( Math.abs(this.coordinates[i] - to.getCoordinate(i)), Math.min( this.idSpace.getModulus(i) + this.coordinates[i] - to.getCoordinate(i), this.idSpace.getModulus(i) - this.coordinates[i] + to.getCoordinate(i))); } else { temp = Math.abs(this.coordinates[i] - to.getCoordinate(i)); } result += temp; } return result; } return 0.0; }