Package ch.njol.yggdrasil
Class Fields
java.lang.Object
ch.njol.yggdrasil.Fields
- All Implemented Interfaces:
Iterable<Fields.FieldContext>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classHolds a field's name and value, and throwsStreamCorruptedExceptions if primitives or objects are used incorrectly. -
Constructor Summary
ConstructorsConstructorDescriptionFields()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> TgetAndRemoveObject(String field, Class<T> expectedType) <T> TgetAndRemovePrimitive(String field, Class<T> expectedType) static Collection<Field> Gets all serializable fields of the provided class, including superclasses.@Nullable Object<T> TgetPrimitive(String fieldID) <T> TgetPrimitive(String fieldID, Class<T> expectedType) booleaniterator()voidvoidputPrimitive(String fieldID, Object value) booleanremoveField(String fieldID) Removes a field and its value from this Fields object.voidSets all fields of the given Object to the values stored in this Fields object.voidDeprecated, for removal: This API element is subject to removal in a future version.intsize()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
type- 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:
object- 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
public Fields(Object object, @Nullable @Nullable Yggdrasil yggdrasil) throws NotSerializableException Creates a fields object and initialises it with all non-transient and non-static fields of the given object.- Parameters:
object- 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 serializable fields of the provided class, including superclasses.- Parameters:
type- 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:
object- The object whose fields should be set- Throws:
YggdrasilException- If this was called on a Fields object not created by Yggdrasil itselfStreamCorruptedExceptionNotSerializableException
-
setFields
@Deprecated(since="2.3.0", forRemoval=true) public void setFields(Object object, Yggdrasil yggdrasil) throws StreamCorruptedException, NotSerializableException Deprecated, for removal: This API element is subject to removal in a future version. -
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
@Nullable public <T> T getObject(String fieldID, Class<T> expectedType) throws StreamCorruptedException - Throws:
StreamCorruptedException
-
getPrimitive
- Throws:
StreamCorruptedException
-
getPrimitive
- Throws:
StreamCorruptedException
-
getAndRemoveObject
@Nullable public <T> 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:
iteratorin interfaceIterable<Fields.FieldContext>
-