mirror of
https://github.com/ViaVersion/ViaNBT.git
synced 2024-11-22 11:35:16 +01:00
Add extra utilities to CompoundTag and ListTag
This commit is contained in:
parent
7f7acc4193
commit
0f8c9e0a59
@ -11,7 +11,7 @@ import java.util.Map.Entry;
|
||||
/**
|
||||
* A compound tag containing other tags.
|
||||
*/
|
||||
public class CompoundTag extends Tag {
|
||||
public class CompoundTag extends Tag implements Iterable<Tag> {
|
||||
|
||||
private Map<String, Tag> value;
|
||||
|
||||
@ -40,6 +40,25 @@ public class CompoundTag extends Tag {
|
||||
return new LinkedHashMap<String, Tag>(this.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the compound tag is empty.
|
||||
*
|
||||
* @return Whether the compound tag is empty.
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return this.value.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the compound tag contains a tag with the specified name.
|
||||
*
|
||||
* @param tagName Name of the tag to check for.
|
||||
* @return Whether the compound tag contains a tag with the specified name.
|
||||
*/
|
||||
public boolean contains(String tagName) {
|
||||
return this.value.containsKey(tagName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tag with the specified name.
|
||||
*
|
||||
@ -104,6 +123,11 @@ public class CompoundTag extends Tag {
|
||||
this.value.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Tag> iterator() {
|
||||
return this.values().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 10;
|
||||
|
@ -14,8 +14,8 @@ import java.util.List;
|
||||
*/
|
||||
public class ListTag<T extends Tag> extends Tag implements Iterable<T> {
|
||||
|
||||
private Class<T> type;
|
||||
private List<T> value;
|
||||
private Class<T> type;
|
||||
|
||||
/**
|
||||
* Creates a tag with the specified name.
|
||||
@ -46,8 +46,8 @@ public class ListTag<T extends Tag> extends Tag implements Iterable<T> {
|
||||
*/
|
||||
public ListTag(String name, Class<T> type, List<T> value) {
|
||||
super(name);
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,6 +55,15 @@ public class ListTag<T extends Tag> extends Tag implements Iterable<T> {
|
||||
return new ArrayList<T>(this.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the element type of the ListTag.
|
||||
*
|
||||
* @return The ListTag's element type.
|
||||
*/
|
||||
public Class<T> getElementType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a tag to this list tag.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user