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 */
017package net.tridentsdk.meta.component;
018
019import net.tridentsdk.base.Substance;
020
021import javax.annotation.concurrent.ThreadSafe;
022
023/**
024 * Represents an abstract metadata value which can be possessed by items, entities, blocks, among others
025 *
026 * @author The TridentSDK Team
027 * @since 0.4-alpha
028 */
029@ThreadSafe
030public interface Meta<T> {
031    /**
032     * Creates a new meta value containing the decoded data provided
033     *
034     * @param instance the data owner which the value will be applied upon
035     * @param data     the data
036     */
037    Meta<T> decodeMeta(T instance, byte[] data);
038
039    /**
040     * Transforms the data into a byte which can be represented in a block data byte
041     *
042     * @return the byte data
043     */
044    byte[] encodeMeta();
045
046    /**
047     * Make a new instance of this meta object
048     *
049     * @return the new instance
050     */
051    Meta<T> make();
052
053    /**
054     * Invoked to register the meta tag
055     *
056     * @param collection the collection which will be used to hold this meta type
057     * @return the substances to apply to
058     */
059    Substance[] applyTo(MetaCollection collection);
060}