Package ch.njol.yggdrasil
Class Fields
java.lang.Object
ch.njol.yggdrasil.Fields
- All Implemented Interfaces:
Iterable<Fields.FieldContext>
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Holds a field's name and value, and throwsStreamCorruptedException
s if primitives or objects are used incorrectly. -
Constructor Summary
ConstructorDescriptionFields()
Creates an empty Fields object.Creates a fields object and initialises it with all non-transient and non-static fields of the given class and its superclasses.Creates a fields object and initialises it with all non-transient and non-static fields of the given object.Creates a fields object and initialises it with all non-transient and non-static fields of the given object. -
Method Summary
Modifier and TypeMethodDescriptionboolean
<T> @Nullable T
getAndRemoveObject(String field, Class<T> expectedType)
<T> T
getAndRemovePrimitive(String field, Class<T> expectedType)
static Collection<Field>
Gets all serialisable fields of the provided class, including superclasses.@Nullable Object
<T> @Nullable T
getPrimitive(String fieldID)
<T> T
getPrimitive(String fieldID, Class<T> expectedType)
boolean
iterator()
void
void
putPrimitive(String fieldID, Object value)
boolean
removeField(String fieldID)
Removes a field and its value from this Fields object.void
Sets all fields of the given Object to the values stored in this Fields object.void
Deprecated.int
size()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Fields
public Fields()Creates an empty Fields object. -
Fields
-
Fields
Creates a fields object and initialises it with all non-transient and non-static fields of the given class and its superclasses.- Parameters:
c
- Some class- Throws:
NotSerializableException
- If a field occurs more than once (i.e. if a class has a field with the same name as a field in one of its superclasses)
-
Fields
Creates a fields object and initialises it with all non-transient and non-static fields of the given object.- Parameters:
o
- Some object- Throws:
NotSerializableException
- If a field occurs more than once (i.e. if a class has a field with the same name as a field in one of its superclasses)
-
Fields
Creates a fields object and initialises it with all non-transient and non-static fields of the given object.- Parameters:
o
- Some object- Throws:
NotSerializableException
- If a field occurs more than once (i.e. if a class has a field with the same name as a field in one of its superclasses)
-
-
Method Details
-
getFields
Gets all serialisable fields of the provided class, including superclasses.- Parameters:
c
- The class to get the fields of- Returns:
- All non-static and non-transient fields of the given class and its superclasses
- Throws:
NotSerializableException
- If a field occurs more than once (i.e. if a class has a field with the same name as a field in one of its superclasses)
-
setFields
Sets all fields of the given Object to the values stored in this Fields object.- Parameters:
o
- The object whose fields should be set- Throws:
StreamCorruptedException
NotSerializableException
YggdrasilException
- If this was called on a Fields object not created by Yggdrasil itself
-
setFields
@Deprecated public void setFields(Object o, Yggdrasil y) throws StreamCorruptedException, NotSerializableExceptionDeprecated. -
size
public int size()- Returns:
- The number of fields defined
-
putObject
-
putPrimitive
-
contains
- Parameters:
fieldID
- A field's id- Returns:
- Whether the field is defined
-
hasField
-
getObject
- Throws:
StreamCorruptedException
-
getObject
public <T> @Nullable T getObject(String fieldID, Class<T> expectedType) throws StreamCorruptedException- Throws:
StreamCorruptedException
-
getPrimitive
- Throws:
StreamCorruptedException
-
getPrimitive
- Throws:
StreamCorruptedException
-
getAndRemoveObject
public <T> @Nullable T getAndRemoveObject(String field, Class<T> expectedType) throws StreamCorruptedException- Throws:
StreamCorruptedException
-
getAndRemovePrimitive
public <T> T getAndRemovePrimitive(String field, Class<T> expectedType) throws StreamCorruptedException- Throws:
StreamCorruptedException
-
removeField
Removes a field and its value from this Fields object.- Parameters:
fieldID
- The id of the field to remove- Returns:
- Whether a field with the given name was actually defined
-
iterator
- Specified by:
iterator
in interfaceIterable<Fields.FieldContext>
-