Closed Querz closed 5 years ago
The last commit removes the typeID from ListTag and changes the TagFactory to work with this.
ListTag only uses the type class now. We can also look into using it with an Optional
. I don't mind using it, i just didn't have the time for it yet.
Maybe an unchecked (and therefore empty) list should always be equal to any other empty list, but then hashCode must not include the type class anymore when the list is empty.
If not then at least an unchecked list should be equal to another unchecked list.
Behaviour now is that ListTag#equals()
will return true if both ListTag
s are either empty AND untyped or empty and with the same type or not empty, with the same type and same values in the same order.
ListTag#hashCode()
matches this behaviour by including the type of the ListTag
.
Another thing i noticed which is not very important but i'd like to change is the way ListTag#toString()
prints the values by using the full #toString()
on each tag, which includes the type of each tag. This information is redundant as their type is already printed in the "type" field.
The result of ListTag#toString()
should be something like this:
{
"type": "ListTag",
"value": {
"list": [
-128,
0,
127
],
"type": "ByteTag"
}
}
See #14
ListTag
should remember its type when cleared.The current solution makes the no-args constructor of
ListTag
protected so deserialisation can still create an instance without knowing the type of theListTag
. Everything from outside creating a new instance ofListTag
will need to useListTag(Class<T extends Tag>)
.I also modified
ListTag#getTypeID()
andListTag#getTypeClass()
to match the old behaviour and be consistent with serialisation. Another reason for this is that these methods cannot be consistent with each other when theListTag
is empty. Example:can only set the type class of the
ListTag
, but not the type id. Setting the type id occurs when adding the first element to the newListTag
. ThereforeListTag#getTypeID()
will return0
andListTag#getTypeClass()
returnsEndTag.class
when theListTag
is empty.Other cases that will fail now but worked before:
The behaviour of
ListTag#asTypedList(Class<? extends Tag>)
also matches the new behaviour.All Unit Tests have been adjusted.