Archiviert
13
0

Provide a remove method in NbtCompound. Discourage getValue().

Added a missing remove method in NbtCompound. In addition, the
getValue() method in NbtCompount has been depreciated. It is far better
to use the put and get methods in NbtCompound instead.
Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-02-17 02:32:14 +01:00
Ursprung 8c0a671078
Commit e919056f9b
3 geänderte Dateien mit 25 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -64,6 +64,9 @@ public interface NbtBase<TType> {
* Is either a primitive {@link java.lang.Number wrapper}, {@link java.lang.String String}, * Is either a primitive {@link java.lang.Number wrapper}, {@link java.lang.String String},
* {@link java.util.List List} or a {@link java.util.Map Map}. * {@link java.util.List List} or a {@link java.util.Map Map}.
* <p> * <p>
* Users are encouraged to cast an NBT compound to {@link NbtCompound} and use its put and get-methods
* instead of accessing its content from getValue().
* <p>
* All operations that modify collections directly, such as {@link java.util.List#add(Object) List.add(Object)} or * All operations that modify collections directly, such as {@link java.util.List#add(Object) List.add(Object)} or
* {@link java.util.Map#clear() Map.clear()}, are considered optional. This also include members in {@link java.util.Iterator Iterator} and * {@link java.util.Map#clear() Map.clear()}, are considered optional. This also include members in {@link java.util.Iterator Iterator} and
* {@link java.util.ListIterator ListIterator}. Operations that are not implemented throw a * {@link java.util.ListIterator ListIterator}. Operations that are not implemented throw a

Datei anzeigen

@ -16,6 +16,10 @@ import java.util.Set;
* @author Kristian * @author Kristian
*/ */
public interface NbtCompound extends NbtBase<Map<String, NbtBase<?>>>, Iterable<NbtBase<?>> { public interface NbtCompound extends NbtBase<Map<String, NbtBase<?>>>, Iterable<NbtBase<?>> {
@Override
@Deprecated()
public Map<String, NbtBase<?>> getValue();
/** /**
* Determine if an entry with the given key exists or not. * Determine if an entry with the given key exists or not.
* @param key - the key to lookup. * @param key - the key to lookup.
@ -304,6 +308,13 @@ public interface NbtCompound extends NbtBase<Map<String, NbtBase<?>>>, Iterable<
*/ */
public abstract <T> NbtCompound put(String key, Collection<? extends NbtBase<T>> list); public abstract <T> NbtCompound put(String key, Collection<? extends NbtBase<T>> list);
/**
* Remove the NBT element that is associated with the given key.
* @param key - the key of the element to remove.
* @return The removed element, or NULL if no such element was found.
*/
public abstract <T> NbtBase<?> remove(String key);
/** /**
* Retrieve an iterator view of the NBT tags stored in this compound. * Retrieve an iterator view of the NBT tags stored in this compound.
* @return The tags stored in this compound. * @return The tags stored in this compound.

Datei anzeigen

@ -215,6 +215,9 @@ class WrappedCompound implements NbtWrapper<Map<String, NbtBase<?>>>, Iterable<N
*/ */
@Override @Override
public <T> NbtCompound put(NbtBase<T> entry) { public <T> NbtCompound put(NbtBase<T> entry) {
if (entry == null)
throw new IllegalArgumentException("Entry cannot be NULL.");
getValue().put(entry.getName(), entry); getValue().put(entry.getName(), entry);
return this; return this;
} }
@ -565,6 +568,9 @@ class WrappedCompound implements NbtWrapper<Map<String, NbtBase<?>>>, Iterable<N
@Override @Override
public NbtCompound put(String key, NbtBase<?> entry) { public NbtCompound put(String key, NbtBase<?> entry) {
if (entry == null)
throw new IllegalArgumentException("Entry cannot be NULL.");
// Don't modify the original NBT // Don't modify the original NBT
NbtBase<?> clone = entry.deepClone(); NbtBase<?> clone = entry.deepClone();
@ -583,6 +589,11 @@ class WrappedCompound implements NbtWrapper<Map<String, NbtBase<?>>>, Iterable<N
return put(WrappedList.fromList(key, list)); return put(WrappedList.fromList(key, list));
} }
@Override
public <T> NbtBase<?> remove(String key) {
return getValue().remove(key);
}
@Override @Override
public void write(DataOutput destination) { public void write(DataOutput destination) {
NbtBinarySerializer.DEFAULT.serialize(container, destination); NbtBinarySerializer.DEFAULT.serialize(container, destination);