001/* 002 * Trident - A Multithreaded Server Alternative 003 * Copyright 2014 The TridentSDK Team 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package net.tridentsdk.meta.nbt; 019 020import com.google.common.collect.Lists; 021 022import java.util.Collections; 023import java.util.LinkedHashMap; 024import java.util.List; 025import java.util.Map; 026 027/** 028 * @author The TridentSDK Team 029 * @since 0.3-alpha-DP 030 */ 031public class CompoundTag extends NBTTag implements TagContainer { 032 // Will work for now 033 final Map<String, NBTTag> tags = Collections.synchronizedMap(new LinkedHashMap<>()); //Hashmap for quick lookup with names 034 035 public CompoundTag(String name) { 036 super(name); 037 } 038 039 public List<NBTTag> listTags() { 040 return Lists.newArrayList(this.tags.values()); 041 } 042 043 public boolean containsTag(String name) { 044 return this.tags.containsKey(name); 045 } 046 047 public NBTTag getTag(String name) { 048 return this.tags.containsKey(name) ? this.tags.get(name) : new NullTag(name); 049 } 050 051 public <T extends NBTTag> T getTagAs(String name) { 052 return (T) getTag(name); 053 } 054 055 @Override 056 public void addTag(NBTTag tag) { 057 this.tags.put(tag.name(), tag); 058 } 059 060 public void removeTag(String name) { 061 this.tags.remove(name); 062 } 063 064 public void clearTags() { 065 this.tags.clear(); 066 } 067 068 /* (non-Javadoc) 069 * @see net.tridentsdk.meta.nbt.NBTTag#type() 070 */ 071 @Override 072 public TagType type() { 073 return TagType.COMPOUND; 074 } 075}