Iterator.remove();

K

karl wettin

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
 
A

Adam Maass

karl wettin said:
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
 
F

Frederik Coppens

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.
 
K

karl wettin

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
 
A

Adam Maass

karl wettin said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top