All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.g2forge.alexandria.java.identity.IIdentity Maven / Gradle / Ivy

There is a newer version: 0.0.18
Show newest version
package com.g2forge.alexandria.java.identity;

/**
 * Abstract encapsulation of the concept of a type's identity. This is particularly useful when you want to use objects of that type in a map or collection, but
 * you want to define the {@link #equals(Object, Object)} and {@link #hashCode(Object)} objects in a way that differs from the type's default. Objects returned
 * from {@link #of(Object)} will wrap values of the specified type T and use the identity methods from this {@link IIdentity}.
 */
public interface IIdentity {
	public static IIdentity same() {
		return SameIdentity.create();
	}

	public static IIdentity standard() {
		return StandardIdentity.create();
	}

	public boolean equals(T _this, Object that);

	public int hashCode(T _this);

	public default Identified of(T value) {
		return new Identified<>(value, this);
	}
}