|
| 1 | +/* |
| 2 | + * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. |
| 3 | + * Copyright (C) 2012 Kristian S. Stangeland |
| 4 | + * |
| 5 | + * This program is free software; you can redistribute it and/or modify it under the terms of the |
| 6 | + * GNU General Public License as published by the Free Software Foundation; either version 2 of |
| 7 | + * the License, or (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 10 | + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | + * See the GNU General Public License for more details. |
| 12 | + * |
| 13 | + * You should have received a copy of the GNU General Public License along with this program; |
| 14 | + * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 15 | + * 02111-1307 USA |
| 16 | + */ |
| 17 | +package com.comphenix.protocol.reflect; |
| 18 | + |
| 19 | +import java.util.Iterator; |
| 20 | + |
| 21 | +/** |
| 22 | + * Provides iterator access to a {@link StructureModifier} |
| 23 | + * |
| 24 | + * @param <T> Type of the fields in the {@link StructureModifier} |
| 25 | + * @author BradBot_1 |
| 26 | + */ |
| 27 | +class StructureModifierIterator<T> implements Iterator<T> { |
| 28 | + |
| 29 | + private final StructureModifier<T> structure; |
| 30 | + private int index = 0; |
| 31 | + |
| 32 | + /** |
| 33 | + * @param structure - {@link StructureModifier} to operate on. |
| 34 | + */ |
| 35 | + StructureModifierIterator(final StructureModifier<T> structure) { |
| 36 | + this.structure = structure; |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * {@inheritDoc} |
| 41 | + */ |
| 42 | + @Override |
| 43 | + public final boolean hasNext() { |
| 44 | + return this.index < this.structure.size(); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * {@inheritDoc} |
| 49 | + */ |
| 50 | + @Override |
| 51 | + public final T next() { |
| 52 | + if (!this.hasNext()) return null; |
| 53 | + return structure.read(index++); |
| 54 | + } |
| 55 | + |
| 56 | +} |
0 commit comments