Iterator.remove();

Discussion in 'Java' started by karl wettin, Aug 27, 2003.

  1. karl wettin

    karl wettin Guest

    I have a class wrapping an array[]. This class contains an Iterator.

    If the array contains non-primitives, remove() sets array=null;

    What about then the array contains primitive classes? I could either set
    the value to the system default (i.e. short/int/long/float/byte...=0x0,
    boolean=false) or throw a new Error("primitives can't be removed!");

    Or should I spend days to change my logics so that the array wrapper
    contains an Enumerator instead of Iterator?



    karl
     
    karl wettin, Aug 27, 2003
    #1
    1. Advertising

  2. karl wettin

    Adam Maass Guest

    "karl wettin" <> wrote:
    >
    > I have a class wrapping an array[]. This class contains an Iterator.
    >
    > If the array contains non-primitives, remove() sets array=null;
    >
    > What about then the array contains primitive classes? I could either set
    > the value to the system default (i.e. short/int/long/float/byte...=0x0,
    > boolean=false) or throw a new Error("primitives can't be removed!");
    >
    > Or should I spend days to change my logics so that the array wrapper
    > contains an Enumerator instead of Iterator?
    >


    throw OperationNotSupportedException.

    In fact, the Iterator over Object[] should probably throw
    OperationNotSupportedException on remove rather than setting the element to
    null.


    -- Adam Maass
     
    Adam Maass, Aug 27, 2003
    #2
    1. Advertising

  3. You could represent primitives by their wrapper classes, then the solution
    with null would work. Or you could use a second boolean array with true for
    positions that are filled and false for those that aren't. Admittedly, both
    solutions would increase the time and space needed by the algorithm.

    "karl wettin" <> wrote in message
    news:...
    >
    > I have a class wrapping an array[]. This class contains an Iterator.
    >
    > If the array contains non-primitives, remove() sets array=null;
    >
    > What about then the array contains primitive classes? I could either set
    > the value to the system default (i.e. short/int/long/float/byte...=0x0,
    > boolean=false) or throw a new Error("primitives can't be removed!");
    >
    > Or should I spend days to change my logics so that the array wrapper
    > contains an Enumerator instead of Iterator?
    >
    >
    >
    > karl
    >
    >
     
    Frederik Coppens, Aug 27, 2003
    #3
  4. karl wettin

    karl wettin Guest

    On Wed, 27 Aug 2003 07:10:37 -0700
    "Adam Maass" <> wrote:

    > > What about then the array contains primitive classes? I could either set
    > > the value to the system default (i.e. short/int/long/float/byte...=0x0,
    > > boolean=false) or throw a new Error("primitives can't be removed!");
    > >
    > > Or should I spend days to change my logics so that the array wrapper
    > > contains an Enumerator instead of Iterator?
    > >

    >
    > throw OperationNotSupportedException.
    >
    > In fact, the Iterator over Object[] should probably throw
    > OperationNotSupportedException on remove rather than setting the element to
    > null.


    Is Enumeration totaly out of the loop?



    karl

    --
    http://sf.net/projects/silvertejp/

    [Human]<|--+--[Woman]<>-- +mother +child {0..*} --[Human]
    \--[Man]<>-- +father +child {0..*} --[Human]

    "arghhh .. its all in geek" - objectmonkey.com
     
    karl wettin, Aug 27, 2003
    #4
  5. karl wettin

    Adam Maass Guest

    "karl wettin" <> wrote:
    > On Wed, 27 Aug 2003 07:10:37 -0700
    > "Adam Maass" <> wrote:
    >
    > > > What about then the array contains primitive classes? I could either

    set
    > > > the value to the system default (i.e.

    short/int/long/float/byte...=0x0,
    > > > boolean=false) or throw a new Error("primitives can't be removed!");
    > > >
    > > > Or should I spend days to change my logics so that the array wrapper
    > > > contains an Enumerator instead of Iterator?
    > > >

    > >
    > > throw OperationNotSupportedException.
    > >
    > > In fact, the Iterator over Object[] should probably throw
    > > OperationNotSupportedException on remove rather than setting the element

    to
    > > null.

    >
    > Is Enumeration totaly out of the loop?
    >
    >


    Well, no, except that Enumeration is the older interface. Depends on your
    audience.

    -- Adam Maass
     
    Adam Maass, Aug 28, 2003
    #5
    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. Hendrik Maryns
    Replies:
    18
    Views:
    1,430
  2. greg
    Replies:
    6
    Views:
    460
    Dietmar Kuehl
    Jul 17, 2003
  3. Replies:
    6
    Views:
    653
    Jim Langston
    Oct 30, 2005
  4. Steven D'Aprano

    What makes an iterator an iterator?

    Steven D'Aprano, Apr 18, 2007, in forum: Python
    Replies:
    28
    Views:
    1,173
    Steven D'Aprano
    Apr 20, 2007
  5. David Bilsby
    Replies:
    5
    Views:
    2,052
    David Bilsby
    Oct 9, 2007
Loading...

Share This Page