Mark AD-SAL interfaces as deprecated
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / utils / MultiIterator.java
1 /*
2  * Copyright (c) 2012 Big Switch Networks, Inc.
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the
5  * "License"); you may not use this file except in compliance with the
6  * License. You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/legal/epl-v10.html
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
13  * implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  *
16  * This file incorporates work covered by the following copyright and
17  * permission notice:
18  *
19  *    Originally created by David Erickson, Stanford University
20  *
21  *    Licensed under the Apache License, Version 2.0 (the "License");
22  *    you may not use this file except in compliance with the
23  *    License. You may obtain a copy of the License at
24  *
25  *         http://www.apache.org/licenses/LICENSE-2.0
26  *
27  *    Unless required by applicable law or agreed to in writing,
28  *    software distributed under the License is distributed on an "AS
29  *    IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
30  *    express or implied. See the License for the specific language
31  *    governing permissions and limitations under the License.
32  */
33
34 package org.opendaylight.controller.sal.utils;
35
36 import java.util.Iterator;
37 import java.util.NoSuchElementException;
38
39 /**
40  * Iterator over all values in an iterator of iterators
41  *
42  * @param <T>
43  *            the type of elements returned by this iterator
44  */
45 @Deprecated
46 public class MultiIterator<T> implements Iterator<T> {
47     Iterator<Iterator<T>> subIterator;
48     Iterator<T> current = null;
49
50     public MultiIterator(Iterator<Iterator<T>> subIterator) {
51         super();
52         this.subIterator = subIterator;
53     }
54
55     @Override
56     public boolean hasNext() {
57         if (current == null) {
58             if (subIterator.hasNext()) {
59                 current = subIterator.next();
60             } else {
61                 return false;
62             }
63         }
64         while (!current.hasNext() && subIterator.hasNext()) {
65             current = subIterator.next();
66         }
67
68         return current.hasNext();
69     }
70
71     @Override
72     public T next() {
73         if (hasNext())
74             return current.next();
75         throw new NoSuchElementException();
76     }
77
78     @Override
79     public void remove() {
80         if (hasNext())
81             current.remove();
82         throw new NoSuchElementException();
83     }
84 }