T
- the accessed typepublic final class Meta<T> extends PropertyGetterList<T,Meta<T>>
Provides a basic meta-method builder for common Object
method implementations.
Example 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(pp -> pp.id)
.objects(pp -> pp.name, pp -> pp.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 by default; see MetaConfig.withShallowArraySupport()
.
If classes can be equal to subtypes use MetaConfig.withInstanceofEqualsTypeCheck()
.
Instances of this type are immutable and thread safe.
PropertyGetterList
Modifier and Type | Class and Description |
---|---|
static interface |
Meta.BooleanGetter<T>
Deprecated.
this type will be deleted in favour of the uk.kludje.property version
|
static interface |
Meta.ByteGetter<T>
Deprecated.
this type will be deleted in favour of the uk.kludje.property version
|
static interface |
Meta.CharGetter<T>
Deprecated.
this type will be deleted in favour of the uk.kludje.property version
|
static interface |
Meta.DoubleGetter<T>
Deprecated.
this type will be deleted in favour of the uk.kludje.property version
|
static interface |
Meta.FloatGetter<T>
Deprecated.
this type will be deleted in favour of the uk.kludje.property version
|
static interface |
Meta.Getter<T>
Deprecated.
this type will be deleted in favour of the uk.kludje.property version
|
static interface |
Meta.IntGetter<T>
Deprecated.
this type will be deleted in favour of the uk.kludje.property version
|
static interface |
Meta.LongGetter<T>
Deprecated.
this type will be deleted in favour of the uk.kludje.property version
|
static interface |
Meta.ShortGetter<T>
Deprecated.
this type will be deleted in favour of the uk.kludje.property version
|
Modifier and Type | Method and Description |
---|---|
Meta<T> |
configure(MetaConfig config)
Some aspects of the provided methods are caller-configurable.
|
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. |
int |
hashCode(T t)
Creates a hash of all values defined by the properties provided to this instance.
|
static <T> Meta<T> |
meta()
WARNING: when this method is used a subclass can never be equal to a parent type.
|
static <T> Meta<T> |
meta(java.lang.Class<T> type) |
java.lang.String |
nameAt(int index) |
protected Meta<T> |
newInstance(Meta<T> old,
java.lang.String name,
TypedProperty getter) |
TypedProperty |
propertyAt(int index) |
int |
size() |
java.lang.String |
toString(T t)
Creates a string form of the type for debugging purposes.
|
booleans, bytes, chars, doubles, floats, ints, longs, namedBoolean, namedByte, namedChar, namedDouble, namedFloat, namedInt, namedLong, namedObject, namedShort, objects, shorts
protected Meta<T> newInstance(Meta<T> old, java.lang.String name, TypedProperty getter)
newInstance
in class PropertyGetterList<T,Meta<T>>
public static <T> Meta<T> meta(java.lang.Class<T> type)
T
- the typetype
- the class of type Tpublic static <T> Meta<T> meta()
T
- the type of classpublic Meta<T> configure(MetaConfig config)
If meta()
was used to instantiate the instance any changes to MetaConfig.ObjectEqualsPolicy
will result in an error. Use meta(Class)
instead.
config
- the new configuration; must not be nullpublic 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 ofpublic int size()
size
in class PropertyGetterList<T,Meta<T>>
public TypedProperty propertyAt(int index)
propertyAt
in class PropertyGetterList<T,Meta<T>>
index
- the getter to returnGetter
,
BooleanGetter
,
ByteGetter
,
ShortGetter
,
IntGetter
,
LongGetter
,
FloatGetter
,
DoubleGetter
,
CharGetter
,
PropertyType
public java.lang.String nameAt(int index)
nameAt
in class PropertyGetterList<T,Meta<T>>
index
- the name index