/*
 * Copyright (c) 2017 D3adspace
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package de.d3adspace.skylla.commons.protocol;

import de.d3adspace.skylla.commons.protocol.packet.SkyllaPacket;
import de.d3adspace.skylla.commons.protocol.packet.SkyllaPacketMeta;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Felix 'SasukeKawaii' Klauke
 */
class PacketMetaContainer {
	
	private final Map<Class<?>, SkyllaPacketMeta> metadata;
	
	private PacketMetaContainer(
		Map<Class<?>, SkyllaPacketMeta> metadata) {
		this.metadata = metadata;
	}
	
	PacketMetaContainer() {
		this(new HashMap<>());
	}
	
	SkyllaPacketMeta getPacketMeta(SkyllaPacket skyllaPacket) {
		return this.getPacketMeta(skyllaPacket.getClass());
	}
	
	SkyllaPacketMeta getPacketMeta(Class<?> packetClazz) {
		return this.metadata
			.computeIfAbsent(packetClazz, k -> packetClazz.getAnnotation(SkyllaPacketMeta.class));
	}
	
	void registerPacketMeta(Class<?> packetClazz, SkyllaPacketMeta meta) {
		this.metadata.put(packetClazz, meta);
	}
}

@@ -1339,16 +1339,74 @@
 p;%0A%0A/**%0A
+ * Container for meta to prevent lazy loading of meta.%0A *%0A
  * @auth
@@ -1436,16 +1436,16 @@
  Klauke%0A
-
  */%0Aclas
@@ -1470,16 +1470,49 @@
 ner %7B%0A%09%0A
+%09/**%0A%09 * The underlying Map%0A%09 */%0A
 %09private
@@ -1562,16 +1562,120 @@
 data;%0A%09%0A
+%09/**%0A%09 * Create a new container by a map of known meta data.%0A%09 *%0A%09 * @param metadata The metadata.%0A%09 */%0A
 %09private
@@ -1775,16 +1775,56 @@
 a;%0A%09%7D%0A%09%0A
+%09/**%0A%09 * Create an empty container%0A%09 */%0A
 %09PacketM
@@ -1862,32 +1862,151 @@
 hMap%3C%3E());%0A%09%7D%0A%09%0A
+%09/**%0A%09 * Retrieve packet meta by a packet instance.%0A%09 *%0A%09 * @param skyllaPacket The packet.%0A%09 * @return The meta.%0A%09 */%0A
 %09SkyllaPacketMet
@@ -2109,16 +2109,125 @@
 );%0A%09%7D%0A%09%0A
+%09/**%0A%09 * Get meta by a packet class.%0A%09 *%0A%09 * @param packetClazz The packet class.%0A%09 * @return The meta.%0A%09 */%0A
 %09SkyllaP
@@ -2390,18 +2390,143 @@
 s));%0A%09%7D%0A
-
 %09%0A
+%09/**%0A%09 * Presave a meta to prevent lazy loading.%0A%09 *%0A%09 * @param packetClazz The packet class.%0A%09 * @param meta The meta.%0A%09 */%0A
 %09void re

document meta container