Give much needed attention to our EnumSet implementations.

Fix HugeEnumSet iterator.remove() bug
  Our iterator used a single index variable to track both the most recently returned element and the next element. When these disagreed, remove was broken. Added a test case for this.

Fix HugeEnumSet concurrency bug
  The old code used of fields to track the intermediate values bitsIndex, elementIndex, and oldIndex. This meant that concurrent reads were not thread safe, even if the EnumSet was never modified after construction.

Fix retainAll bug
  Calling retainAll() on an empty enum set would return true when the passed in argument was also an enum set.

Replace "collection.size() == 0" with "collection.isEmpty()"
  This is inefficient for ConcurrentHashMap, which must do a full iteration.

Remove no-op arrays.fill() in HugeEnumSet constructor
  Newly allocated arrays are initialized with 0s, this was a no-op.

Throw on clone failure
  Previously we swept an impossible clone failure under the rug by returning null. This can't happen; we should throw AssertionErrors if it does.

Improve type safety
  Remove use of raw types. Move warning suppressions to single lines and document why the suppressions are safe.

Increase internal implementation consistency
  The new structure of add/addAll, remove/removeAll, retainAll is consistent across all: for each method, calculate the newBits. Compare old and new bits and if they disagree, update size and return true.

Improve readability
  Flip "if (null == foo)" to "if (foo == null)" etc.

Investigate performance benefits of mod+divide vs. mask+shift
  On both DRLVM and the RI's VM, mod & divide by a constant factor performed no worse than mask & shift. I'll investigate how Dalvik behaves on a device; I may later change this code to use mask+shift.

git-svn-id: https://svn.apache.org/repos/asf/harmony/enhanced/classlib/trunk@888752 13f79535-47bb-0310-9956-ffa450edef68
4 files changed