Rename getInteger -> getInt in NBT library and add putType(...) methods.

This commit is contained in:
sk89q 2014-07-15 11:55:28 -07:00
parent bf7185d173
commit cf6fa98525
3 changed files with 127 additions and 20 deletions

View File

@ -196,13 +196,13 @@ public final class CompoundTag extends Tag {
/**
* Get a {@code int[]} named with the given key.
*
* <p>If the key does not exist or its value is not an integer array tag,
* <p>If the key does not exist or its value is not an int array tag,
* then an empty array will be returned.</p>
*
* @param key the key
* @return an integer array
* @return an int array
*/
public int[] getIntegerArray(String key) {
public int[] getIntArray(String key) {
Tag tag = value.get(key);
if (tag instanceof IntArrayTag) {
return ((IntArrayTag) tag).getValue();
@ -212,15 +212,15 @@ public final class CompoundTag extends Tag {
}
/**
* Get an integer named with the given key.
* Get an int named with the given key.
*
* <p>If the key does not exist or its value is not an integer tag,
* <p>If the key does not exist or its value is not an int tag,
* then {@code 0} will be returned.</p>
*
* @param key the key
* @return an integer
* @return an int
*/
public int getInteger(String key) {
public int getInt(String key) {
Tag tag = value.get(key);
if (tag instanceof IntTag) {
return ((IntTag) tag).getValue();
@ -230,16 +230,16 @@ public final class CompoundTag extends Tag {
}
/**
* Get an integer named with the given key, even if it's another
* Get an int named with the given key, even if it's another
* type of number.
*
* <p>If the key does not exist or its value is not a number,
* then {@code 0} will be returned.</p>
*
* @param key the key
* @return an integer
* @return an int
*/
public int asInteger(String key) {
public int asInt(String key) {
Tag tag = value.get(key);
if (tag instanceof ByteTag) {
return ((ByteTag) tag).getValue();

View File

@ -62,6 +62,113 @@ public class CompoundTagBuilder {
return this;
}
/**
* Put the given key and value into the compound tag as a
* {@code ByteArrayTag}.
*
* @param key they key
* @param value the value
* @return this object
*/
public CompoundTagBuilder putByteArray(String key, byte[] value) {
return put(key, new ByteArrayTag(key, value));
}
/**
* Put the given key and value into the compound tag as a
* {@code ByteTag}.
*
* @param key they key
* @param value the value
* @return this object
*/
public CompoundTagBuilder putByte(String key, byte value) {
return put(key, new ByteTag(key, value));
}
/**
* Put the given key and value into the compound tag as a
* {@code DoubleTag}.
*
* @param key they key
* @param value the value
* @return this object
*/
public CompoundTagBuilder putDouble(String key, double value) {
return put(key, new DoubleTag(key, value));
}
/**
* Put the given key and value into the compound tag as a
* {@code FloatTag}.
*
* @param key they key
* @param value the value
* @return this object
*/
public CompoundTagBuilder putFloat(String key, float value) {
return put(key, new FloatTag(key, value));
}
/**
* Put the given key and value into the compound tag as a
* {@code IntArrayTag}.
*
* @param key they key
* @param value the value
* @return this object
*/
public CompoundTagBuilder putIntArray(String key, int[] value) {
return put(key, new IntArrayTag(key, value));
}
/**
* Put the given key and value into the compound tag as an {@code IntTag}.
*
* @param key they key
* @param value the value
* @return this object
*/
public CompoundTagBuilder putInt(String key, int value) {
return put(key, new IntTag(key, value));
}
/**
* Put the given key and value into the compound tag as a
* {@code LongTag}.
*
* @param key they key
* @param value the value
* @return this object
*/
public CompoundTagBuilder putLong(String key, long value) {
return put(key, new LongTag(key, value));
}
/**
* Put the given key and value into the compound tag as a
* {@code ShortTag}.
*
* @param key they key
* @param value the value
* @return this object
*/
public CompoundTagBuilder putShort(String key, short value) {
return put(key, new ShortTag(key, value));
}
/**
* Put the given key and value into the compound tag as a
* {@code StringTag}.
*
* @param key they key
* @param value the value
* @return this object
*/
public CompoundTagBuilder putString(String key, String value) {
return put(key, new StringTag(key, value));
}
/**
* Put all the entries from the given map into this map.
*

View File

@ -210,13 +210,13 @@ public final class ListTag extends Tag {
/**
* Get a {@code int[]} named with the given index.
*
* <p>If the index does not exist or its value is not an integer array tag,
* <p>If the index does not exist or its value is not an int array tag,
* then an empty array will be returned.</p>
*
* @param index the index
* @return an integer array
* @return an int array
*/
public int[] getIntegerArray(int index) {
public int[] getIntArray(int index) {
Tag tag = getIfExists(index);
if (tag instanceof IntArrayTag) {
return ((IntArrayTag) tag).getValue();
@ -226,15 +226,15 @@ public final class ListTag extends Tag {
}
/**
* Get an integer named with the given index.
* Get an int named with the given index.
*
* <p>If the index does not exist or its value is not an integer tag,
* <p>If the index does not exist or its value is not an int tag,
* then {@code 0} will be returned.</p>
*
* @param index the index
* @return an integer
* @return an int
*/
public int getInteger(int index) {
public int getInt(int index) {
Tag tag = getIfExists(index);
if (tag instanceof IntTag) {
return ((IntTag) tag).getValue();
@ -244,16 +244,16 @@ public final class ListTag extends Tag {
}
/**
* Get an integer named with the given index, even if it's another
* Get an int named with the given index, even if it's another
* type of number.
*
* <p>If the index does not exist or its value is not a number,
* then {@code 0} will be returned.</p>
*
* @param index the index
* @return an integer
* @return an int
*/
public int asInteger(int index) {
public int asInt(int index) {
Tag tag = getIfExists(index);
if (tag instanceof ByteTag) {
return ((ByteTag) tag).getValue();