Closed Mandemus closed 6 years ago
elementOf
is a default method in an interface. It always has one parameter but there are many overloads: BigInteger, BitSet, Collection, Enum, long
When you pass an EnumBitSet
it will pass the call to the actual EnumSet
. Both RegularEnumSet
and JumboEnumSet
will use bit operations. So what exactly would be the issue here?
IntelliJ is saying something different. When following it through it dropped right to collection.contains() which iterated over the collection elements.
default boolean elementOf(Collection<E> collection) {
return ((Collection)Objects.requireNonNull(collection)).contains(this);
}
That's the override it's using, at line 42.
To be more precise:
You call WRITE.elementOf(permissions)
and permissions is some collection. So it's elementOf(Collection<E>)
. That will just call permissions.contains(WRITE)
.
Then that is permissions.bitset.contains(WRITE)
. Which might be this:
java.util.JumboEnumSet.contains(Object)
and that's basically return (elements[eOrdinal >>> 6] & (1L << eOrdinal)) != 0;
.
In the example it's obviously just a regular enum set.
I've just tested this in Eclipse:
Ok thank you for the clarification. It was deceiving seeing it drop through all the overrides surrounding it.
Great library. It's cleaned up the bitvector code immensely in our 120k line project.
I'm amazed that anyone is using my code. I wrote this when I was a student. And I'm glad it works outside of Eclipse. There's a Java 10 branch, if you ever want to switch to a newer Version of Java.
When declaring my bit vector as an EnumBitSet according to the examples, elementOf() appears to internally use the collection.contains() method not bitwise math or get(ordinal) as a comparison. Sort of defeats one of the reasons for using a bitvector.