Querz / NBT

A java implementation of the NBT protocol, including a way to implement custom tags.
MIT License
183 stars 48 forks source link

Fix inconsistencies #27

Closed Querz closed 5 years ago

Querz commented 5 years ago

This pull request fixes some issues regarding inconsistency.

coveralls commented 5 years ago

Coverage Status

Coverage increased (+0.003%) to 98.955% when pulling 66ce5295931484b0d55722ca1c81b80a5131ad80 on inconsistencies-fix into 74e37d4986a27b66113abd2c59a9d78e6c9a4900 on master.

Marcono1234 commented 5 years ago

These points do not apply anymore

  • ListTag and CompoundTag should throw an exception when comparing them with incompatible types
  • ListTag and CompoundTag should always clear their values before deserialising data into them
  • Add ListTag#sort() to make use of the implementation of Comparable in each tag

And you could change NumberTag and ArrayTag to be type-safe for compareTo at the cost of a slightly more complicated signature:

public abstract class NumberTag<T extends Number & Comparable<T>, ThisTagType extends NumberTag<T, ?>> extends Tag<T> implements Comparable<ThisTagType> {

And then have subclasses add their own type as ThisTagType:

public class ByteTag extends NumberTag<Byte, ByteTag>

Though this makes using NumberTag more unpleasant. Maybe it would be best to just only have the subclasses (e.g. ByteTag) implement Comparable and not NumberTag.

Marcono1234 commented 5 years ago

The changes look good. Thank you very much!