T - the accessed typepublic final class Meta<T>
extends java.lang.Object
Provides a basic meta-method builder for common Object method implementations.
Example that builds equals, hashCode and toString methods using the id, name and dateOfBirth properties:
import uk.kludje.Meta;
import java.time.LocalDate;
import static uk.kludje.Meta.meta;
public class PersonPojo {
private static final Meta<PersonPojo> META = meta(PersonPojo.class)
. longs($ -> $.id).objects($ -> $.name, $ -> $.dateOfBirth);
private final long id;
private final String name;
private final LocalDate dateOfBirth;
public PersonPojo(long id, String name, LocalDate dateOfBirth) {
this.id = id;
this.name = name;
this.dateOfBirth = dateOfBirth;
}
public String getName() {
return name;
}
public LocalDate getDateOfBirth() {
return dateOfBirth;
}
public boolean equals(Object obj) {
return META.equals(this, obj);
}
public int hashCode() {
return META.hashCode(this);
}
public String toString() {
return META.toString(this);
}
}
Note: arrays are treated as objects; use a decorator to provide alternative equals/hashCode/toString behaviour.
For example, Google Guava's Bytes.asList(byte...).
Instances of this type are immutable and thread safe.
| Modifier and Type | Class and Description |
|---|---|
static interface |
Meta.BooleanGetter<T> |
static interface |
Meta.ByteGetter<T> |
static interface |
Meta.CharGetter<T> |
static interface |
Meta.DoubleGetter<T> |
static interface |
Meta.FloatGetter<T> |
static interface |
Meta.Getter<T>
A functional interface for reading a property value.
|
static interface |
Meta.IntGetter<T> |
static interface |
Meta.LongGetter<T> |
static interface |
Meta.ShortGetter<T> |
| Modifier and Type | Method and Description |
|---|---|
Meta<T> |
booleans(Meta.BooleanGetter<T>... getters) |
Meta<T> |
bytes(Meta.ByteGetter<T>... getters) |
Meta<T> |
chars(Meta.CharGetter<T>... getters) |
Meta<T> |
doubles(Meta.DoubleGetter<T>... getters) |
boolean |
equals(T t,
java.lang.Object any)
any is equal to t if it is of type T
and all the properties defined by this type are equal. |
Meta<T> |
floats(Meta.FloatGetter<T>... getters) |
int |
hashCode(T t)
Creates a hash of all values defined by the properties provided to this instance.
|
Meta<T> |
ints(Meta.IntGetter<T>... getters) |
Meta<T> |
longs(Meta.LongGetter<T>... getters) |
static <T> Meta<T> |
meta() |
Meta<T> |
objects(Meta.Getter<T>... getters)
Use to specify properties of type object that should be considered by this type.
|
Meta<T> |
shorts(Meta.ShortGetter<T>... getters) |
java.lang.String |
toString(T t)
Creates a string form of the type for debugging purposes.
|
public static <T> Meta<T> meta()
T - the type of class@SafeVarargs public final Meta<T> objects(Meta.Getter<T>... getters)
getters - a vararg array of non-null getters@SafeVarargs public final Meta<T> booleans(Meta.BooleanGetter<T>... getters)
@SafeVarargs public final Meta<T> chars(Meta.CharGetter<T>... getters)
@SafeVarargs public final Meta<T> bytes(Meta.ByteGetter<T>... getters)
@SafeVarargs public final Meta<T> shorts(Meta.ShortGetter<T>... getters)
@SafeVarargs public final Meta<T> ints(Meta.IntGetter<T>... getters)
@SafeVarargs public final Meta<T> longs(Meta.LongGetter<T>... getters)
@SafeVarargs public final Meta<T> floats(Meta.FloatGetter<T>... getters)
@SafeVarargs public final Meta<T> doubles(Meta.DoubleGetter<T>... getters)
public boolean equals(T t, java.lang.Object any)
any is equal to t if it is of type T
and all the properties defined by this type are equal.t - a non-null instance of type Tany - any object, including nullpublic int hashCode(T t)
t - the non-null instance to create a hash forpublic java.lang.String toString(T t)
t - the non-null instance to create a string form of