|
| 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 | +/** |
| 20 | + * Created by {@link StructureModifierIterator} iterator access to a {@link StructureModifier} |
| 21 | + * |
| 22 | + * @param <T> Type of the fields in the {@link StructureModifier} |
| 23 | + * @author BradBot_1 |
| 24 | + */ |
| 25 | +public class StructureModifierIntermediate<T> { |
| 26 | + |
| 27 | + protected final StructureModifier<T> structure; |
| 28 | + protected final int index; |
| 29 | + |
| 30 | + /** |
| 31 | + * @param structure - {@link StructureModifier} to operate on. |
| 32 | + * @param index - index to access. |
| 33 | + * |
| 34 | + * @apiNote Must be public, else extending it would not work properly. |
| 35 | + */ |
| 36 | + public StructureModifierIntermediate(final StructureModifier<T> structure, final int index) { |
| 37 | + this.structure = structure; |
| 38 | + this.index = index; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @return Object at index. |
| 43 | + */ |
| 44 | + public T get() { |
| 45 | + return this.structure.read(this.index); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Overwrites the existing value at the index in the structure. |
| 50 | + * |
| 51 | + * @param toWrite - Object to overwrite the existing one. |
| 52 | + */ |
| 53 | + public void set(final T toWrite) { |
| 54 | + this.structure.write(index, toWrite); |
| 55 | + } |
| 56 | + |
| 57 | +} |
0 commit comments