1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */1819package org.apache.giraph.utils;
2021import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
22import org.apache.hadoop.io.WritableComparable;
2324/**25 * Common implementation for VertexIdEdgeIterator, VertexIdMessageIterator26 * and VertexIdMessageBytesIterator.27 *28 * @param <I> Vertex id29 */30publicabstractclass ByteStructVertexIdIterator<I extends WritableComparable>
31implements VertexIdIterator<I> {
32/** Reader of the serialized edges */33protectedfinalExtendedDataInput extendedDataInput;
3435/** Current vertex id */36protected I vertexId;
3738/**39 * Constructor.40 *41 * @param extendedDataOutput Extended data output42 * @param conf Configuration43 */44publicByteStructVertexIdIterator(
45ExtendedDataOutput extendedDataOutput,
46 ImmutableClassesGiraphConfiguration<I, ?, ?> conf) {
47if (extendedDataOutput != null && conf != null) {
48 extendedDataInput = conf.createExtendedDataInput(extendedDataOutput);
49 } else {
50thrownew IllegalStateException("Cannot instantiate vertexIdIterator " +
51"with null arguments");
52 }
53 }
5455 @Override
56publicboolean hasNext() {
57return !extendedDataInput.endOfInput();
58 }
5960 @Override
61public I getCurrentVertexId() {
62return vertexId;
63 }
6465 @Override
66public I releaseCurrentVertexId() {
67 I releasedVertexId = vertexId;
68 vertexId = null;
69return releasedVertexId;
70 }
71 }