Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
IteratorToReaderWrapper |
|
| 1.3333333333333333;1.333 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, software | |
13 | * distributed under the License is distributed on an "AS IS" BASIS, | |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 | * See the License for the specific language governing permissions and | |
16 | * limitations under the License. | |
17 | */ | |
18 | ||
19 | package org.apache.giraph.io.iterables; | |
20 | ||
21 | import java.util.Iterator; | |
22 | ||
23 | /** | |
24 | * Wraps {@link Iterator} into object which provides iteration like in | |
25 | * {@link org.apache.giraph.io.VertexReader} or | |
26 | * {@link org.apache.giraph.io.EdgeReader} | |
27 | * | |
28 | * @param <T> | |
29 | */ | |
30 | public class IteratorToReaderWrapper<T> { | |
31 | /** Wrapped iterator */ | |
32 | private Iterator<T> iterator; | |
33 | /** Current object */ | |
34 | 0 | private T currentObject = null; |
35 | ||
36 | /** | |
37 | * Constructor | |
38 | * | |
39 | * @param iterator Iterator to wrap | |
40 | */ | |
41 | 0 | public IteratorToReaderWrapper(Iterator<T> iterator) { |
42 | 0 | this.iterator = iterator; |
43 | 0 | } |
44 | ||
45 | /** | |
46 | * Read next object | |
47 | * | |
48 | * @return False iff there are no more objects | |
49 | */ | |
50 | public boolean nextObject() { | |
51 | 0 | boolean hasNext = iterator.hasNext(); |
52 | 0 | if (hasNext) { |
53 | 0 | currentObject = iterator.next(); |
54 | } else { | |
55 | 0 | currentObject = null; |
56 | } | |
57 | 0 | return hasNext; |
58 | } | |
59 | ||
60 | /** | |
61 | * Get the current object | |
62 | * | |
63 | * @return Current object | |
64 | */ | |
65 | public T getCurrentObject() { | |
66 | 0 | return currentObject; |
67 | } | |
68 | } |