KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > util > iterator > AtomicObjectIterator


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.util.iterator;
19
20 import java.util.Iterator JavaDoc;
21 import java.util.NoSuchElementException JavaDoc;
22
23 import org.apache.beehive.netui.util.Bundle;
24
25 /**
26  */

27 public class AtomicObjectIterator
28     implements Iterator JavaDoc {
29
30     /**
31      * The object that should be wrapped in the iterator
32      */

33     private Object JavaDoc _object;
34
35     /**
36      * A boolean to track if the single object in this iterator has been returned
37      */

38     private boolean _nextCalled = false;
39
40     AtomicObjectIterator(Object JavaDoc object) {
41         _object = object;
42     }
43
44     public boolean hasNext() {
45         if(_nextCalled || _object == null)
46             return false;
47         else return true;
48     }
49
50     public Object JavaDoc next() {
51         if(!_nextCalled && _object != null) {
52             _nextCalled = true;
53             return _object;
54         }
55         else throw new NoSuchElementException JavaDoc(Bundle.getErrorString("IteratorFactory_Iterator_noSuchElement"));
56     }
57
58     public void remove() {
59         throw new UnsupportedOperationException JavaDoc(Bundle.getErrorString("IteratorFactory_Iterator_removeUnsupported", new Object JavaDoc[]{this.getClass().getName()}));
60     }
61 }
62
Popular Tags