Wednesday 15 September 2010

java - For each with my custom class won't work -


Oh all I'm working with Java.
That's why I'm writing a class named OrderedSet . This is a class that is cross between a set and a queue. In other words, this is a line without any duplicates. So I know that I have to implement the ineligible interface, and have to type an iterator method. To write the method, I must then implement the Iterator interface.

  package comp345; Import java.util.Iterator; Import java.util.NoSuchElementException; Class serializes the set of Iterable & lt; Object & gt; {Private Object [] queue; // It represents the ordord, an // queue private object counter; // Copy to keep track of the current status of the queue private int queue; // Keep track of queue; // Constructor Public Ordered Sets (Integer Size) {this.queue = New Object [Size]; This.counter = 0; This.queue size = size - 1; Instant for every object instance of object (for int i = 0; i & lt; queue.length; i ++) for the object array {q} [i] = new object (); }} / ** * This ensures that the element specified in this collection is if it is not already in the collection then it has been added behind the queue. * * @ Ultimate E * Element whose presence in this collection is being ensured * If true, then this collection has been changed as the result of the call * @ Threas tap pointer exception * If the specified element is empty / add boolean ( Object i) {if (i == queue [counter]) {return false; } And if (i == empty) throw new nullioner exception (); Else {// add the object behind the line queue [counter] = i; Back true; }} / ** * Deletes all elements from this collection. After this method return the collection will be * empty * / clear () (for (int i = 0; i & lt; qi.lamp; i ++) {q} [i] = null;}} / ** * True Return If there is no element in this collection * * @ Return if there is no element in this collection / / Boolean is empty () {If (Q [0] == faucet) back true; Second false return;} / * * * The blank * * * queue of this line, or empty if this queue is empty * / object peek {if (queue [counter]! = Null) return queue [counter ]; And tap return;} / ** * Removes the head of the queue and removes * * @ Behind the head of this queue * @ throw noschlement exception * if this queue is empty * / remove object () { If (queue [0]! = Null) {object temp = queue [0]; queue [0] = queue [1]; return temporary;} and neither throw a new nouselame exception ();} public class SetIterator Iterator & lt ; Object & gt; {Private Inter Counter; Public Setter () {this.counter = 0;} @OverWide Public Object Next () { R ++; if (Kyuijyug == counter) return null; if (row [counter]! = Null) return (object) queue [counter]; And neither do the new NSUELEMENT throw exceptions (); } @ Override in Public Boolean Next () {Counter ++; If (the queue size  

I can see at least one problem.
Take a closer look at your hasNext () method.

Do you really want the variable counter ?


1 comment: