Closed Marcono1234 closed 5 years ago
compareTo
should throw an exception when comparing incompatible types. See #27.
But why is Comparable
needed on Tag level anyways? Would there be any problems when moving it the respective classes (except compatibility)?
I just saw that i forgot to add a ListTag#sort()
for which this was originally intended. In this case it makes sense to have every tag (or their abstract parent class, like ArrayTag or NumberTag) implement Comparable
.
This should also be possible using sort(Comparator.naturalOrder())
, but would of course be more to type.
For sort(Comparator.naturalOrder()
to work i would need to implement Comparable
for every tag anyway.
Or is your point to have some tags not comparable at all, because it might not make much sense (e.g. comparing CompoundTag
)?
Using sort(Comparator.naturalOrder())
would only require that the currently used element type implements Comparable
.
My goals are to
Comparable
where it does not make sense or will only be useful for a very specific use case (CompoundTag
)compareTo
more type-safe and prevent comparing incompatible types at compile timeSee #27
Comparable
is only implemented by Tags that need it. Implementing Comparable
for EndTag
didn't really make sense :)
I am still not sure if the implementations for the array, list and compound tags are not too specific and tailored to a specific use case only. But this is definitely better, thanks!
It might be good to implement
Comparable
only where needed and not for allTag
s. Currently the behavior is also a little bit inconsistent since some implementations can throw exceptions while others, such asCompoundTag
just return 0.