public class Fields extends Object
Unsafe
.Modifier and Type | Class and Description |
---|---|
static interface |
Fields.ObjectTransformer
Function enabling an object field value to be replaced with another value when being copied
within
copy(Object, Object, ObjectTransformer) . |
Modifier and Type | Field and Description |
---|---|
private Class<?>[] |
declaringClasses |
private String[] |
names
The names of the fields.
|
protected long[] |
offsets
Offsets used with
Unsafe to access the fields. |
private Class<?>[] |
types
The types of the fields.
|
Constructor and Description |
---|
Fields(ArrayList<? extends FieldsScanner.FieldInfo> fields) |
Modifier and Type | Method and Description |
---|---|
void |
appendFields(StringBuilder sb) |
private boolean |
checkAssignableFrom(Object object,
int index,
Object value)
Checks that a given field is assignable from a given value.
|
void |
copy(Object from,
Object to)
Copies fields from
from to to , both of which must be of the same type. |
void |
copy(Object from,
Object to,
Fields.ObjectTransformer trans)
Copies fields from
from to to , both of which must be of the same type. |
static Fields |
forClass(Class<?> clazz,
Class<?> endClazz,
boolean includeTransient,
FieldsScanner.CalcOffset calcOffset) |
Object |
get(Object object,
int index)
Gets the value of a field for a given object.
|
boolean |
getBoolean(Object n,
int i) |
byte |
getByte(Object n,
int i) |
char |
getChar(Object n,
int i) |
int |
getCount()
Gets the number of fields represented by this object.
|
Class<?> |
getDeclaringClass(int index) |
double |
getDouble(Object n,
int i) |
float |
getFloat(Object n,
int i) |
int |
getInt(Object n,
int i) |
long |
getLong(Object n,
int i) |
String |
getName(int index)
Gets the name of a field.
|
Object |
getObject(Object object,
int i) |
long[] |
getOffsets() |
long |
getRawPrimitive(Object object,
int index)
Gets the value of a field for a given object.
|
short |
getShort(Object n,
int i) |
Class<?> |
getType(int index)
Gets the type of a field.
|
boolean |
isSame(Fields other,
int index)
Determines if a field in the domain of this object is the same as the field denoted by the
same index in another
Fields object. |
void |
putObject(Object object,
int i,
Object value) |
void |
set(Object object,
int index,
Object value) |
void |
setRawPrimitive(Object object,
int index,
long value) |
String |
toString() |
static void |
translateInto(Fields fields,
ArrayList<FieldsScanner.FieldInfo> infos) |
protected final long[] offsets
Unsafe
to access the fields.private final Class<?>[] declaringClasses
public Fields(ArrayList<? extends FieldsScanner.FieldInfo> fields)
public static Fields forClass(Class<?> clazz, Class<?> endClazz, boolean includeTransient, FieldsScanner.CalcOffset calcOffset)
public int getCount()
public static void translateInto(Fields fields, ArrayList<FieldsScanner.FieldInfo> infos)
public void copy(Object from, Object to)
from
to to
, both of which must be of the same type.from
- the object from which the fields should be copiedto
- the object to which the fields should be copiedpublic void copy(Object from, Object to, Fields.ObjectTransformer trans)
from
to to
, both of which must be of the same type.from
- the object from which the fields should be copiedto
- the object to which the fields should be copiedtrans
- function to applied to object field values as they are copied. If null
,
the value is copied unchanged.public Object get(Object object, int index)
object
- the object whose field is to be readindex
- the index of the field (between 0 and getCount()
)public long getRawPrimitive(Object object, int index)
object
- the object whose field is to be readindex
- the index of the field (between 0 and getCount()
)public boolean isSame(Fields other, int index)
Fields
object.public long[] getOffsets()
public String getName(int index)
index
- index of a fieldpublic Class<?> getType(int index)
index
- index of a fieldpublic Class<?> getDeclaringClass(int index)
private boolean checkAssignableFrom(Object object, int index, Object value)
index
- the index of the field to checkvalue
- a value that will be assigned to the fieldpublic void setRawPrimitive(Object object, int index, long value)
public void appendFields(StringBuilder sb)
public boolean getBoolean(Object n, int i)