EnumSet--what the...?

Discussion in 'Java' started by George Cherry, Jul 9, 2005.

  1. "Roedy Green" <> wrote in message
    news:eek:...
    > On Fri, 8 Jul 2005 14:16:46 -0400, "George Cherry"
    > <> wrote or quoted :
    >
    >>Yes, I said something similar (but not so well)
    >>in an earlier post to Roedy. Hey Roedy, Java's
    >>a high-level language; get your mind out of the
    >>bit gutter. : o )

    >
    > my background is math. I expect operations like union, intersection,
    > on something that calls itself a set, which map very nicely to what an
    > assembler programmer like me does with bitmaps. It turns out the
    > interesting methods of an EnumSet are way down in the AbstractSet
    > class.


    Okay, but Joshua Bloch's elegant Collections Framework
    gives you all the set operations--and they work between different
    Set implementations (including EnumSet) very conveniently.
    EnumSet implements the Collections Framework's root
    interface, Collection, and, of course, its subinterface, Set.
    It turns out that EnumSet's relevant bulk operations are
    way up in the Collection interface, and they are defined
    explicitly as set operations in the API for the Set interface.
    (Are interfaces neat or what?)

    Bloch's excellent tutorial on the Java Collections Framework
    is at

    http://java.sun.com/docs/books/tutorial/collections/

    The following is from the tutorial

    The bulk operations are particularly well suited to Sets; when applied to
    sets, they perform standard set-algebraic operations. Suppose s1 and s2 are
    Sets. Here's what the bulk operations do:
    a.. s1.containsAll(s2): Returns true if s2 is a subset of s1. (s2 is a
    subset of s1 if set s1 contains all the elements in s2.)
    b.. s1.addAll(s2): Transforms s1 into the union of s1 and s2. (The union
    of two sets is the set containing all the elements contained in either set.)
    c.. s1.retainAll(s2): Transforms s1 into the intersection of s1 and s2.
    (The intersection of two sets is the set containing only the elements that
    are common to both sets.)
    d.. s1.removeAll(s2): Transforms s1 into the (asymmetric) set difference
    of s1 and s2. (For example, the set difference of s1 - s2 is the set
    containing all the elements found in s1 but not in s2.)
    > There seems to be a heck of a lot of dithering compared with the way I
    > implemented such a feature in Abundance.


    Fooling around directly with bits is a heck of a lot of dithering compared
    with the way Bloch specified and implemented set operations in the
    Java Collections Framework--and you still get the efficiency of bit
    vector dithering, because the implementation of EnumSet uses bit
    vectors behind the high level scene.

    George W. Cherry
     
    George Cherry, Jul 9, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roedy Green

    EnumSet, what the ?

    Roedy Green, Jul 8, 2005, in forum: Java
    Replies:
    6
    Views:
    1,842
    George Cherry
    Jul 9, 2005
  2. Roedy Green

    EnumSet Generics puzzle

    Roedy Green, Aug 18, 2005, in forum: Java
    Replies:
    11
    Views:
    1,538
    Thomas Hawtin
    Aug 22, 2005
  3. Ulrich Scholz

    EnumSet + contains: strange behavior

    Ulrich Scholz, May 31, 2006, in forum: Java
    Replies:
    10
    Views:
    1,617
    Christian Kaufhold
    Jun 4, 2006
  4. Eric Smith
    Replies:
    19
    Views:
    2,365
    Eric Smith
    May 17, 2007
  5. Roedy Green

    Enumset

    Roedy Green, Aug 31, 2007, in forum: Java
    Replies:
    10
    Views:
    1,314
    Lasse Reichstein Nielsen
    Sep 1, 2007
Loading...

Share This Page