/**
 * Copyright (C) 2013-2014 VCNC Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package kr.co.vcnc.haeinsa;

import java.util.HashMap;

import javax.annotation.Nullable;

import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;

public class HaeinsaTransactionLocal<T> {

    public static <T> HaeinsaTransactionLocal<T> newLocal() {
        return new HaeinsaTransactionLocal<T>();
    }

    @Nullable
    public T get(HaeinsaTransaction tx) {
        Preconditions.checkNotNull(tx);
        return (T) tx.getLocals().get(this);
    }

    public void set(HaeinsaTransaction tx, T value) {
        Preconditions.checkNotNull(tx);
        Preconditions.checkNotNull(value);
        tx.getLocals().set(this, value);
    }

    public boolean isSet(HaeinsaTransaction tx) {
        Preconditions.checkNotNull(tx);
        return tx.getLocals().isSet(this);
    }

    public T remove(HaeinsaTransaction tx) {
        Preconditions.checkNotNull(tx);
        return (T) tx.getLocals().remove(this);
    }

    static class HaeinsaTransactionLocals {
        @SuppressWarnings("rawtypes")
        private final HashMap localMap;

        HaeinsaTransactionLocals() {
            localMap = Maps.newHashMap();
        }

        @SuppressWarnings("unchecked")
        public <T> T get(HaeinsaTransactionLocal<T> local) {
            return (T) localMap.get(local);
        }

        @SuppressWarnings("unchecked")
        public <T> void set(HaeinsaTransactionLocal<T> local, T value) {
            localMap.put(local, value);
        }

        public <T> boolean isSet(HaeinsaTransactionLocal<T> local) {
            return localMap.containsKey(local);
        }

        @SuppressWarnings("unchecked")
        public <T> T remove(HaeinsaTransactionLocal<T> local) {
            return (T) localMap.remove(local);
        }
    }
}

@@ -780,641 +780,2228 @@
 s;%0A%0A
-public class HaeinsaTransactionLocal%3CT%3E %7B%0A%0A    public static %3CT%3E HaeinsaTransactionLocal%3CT%3E newLocal() %7B%0A        return new HaeinsaTransactionLocal%3CT%3E();%0A    %7D%0A%0A    @Nullable%0A    public T get(HaeinsaTransaction tx) %7B%0A        Preconditions.checkNotNull(tx);%0A        return (T) tx.getLocals().get(this);%0A    %7D%0A%0A    public void set(HaeinsaTransaction tx, T value) %7B%0A        Preconditions.checkNotNull(tx);%0A        Preconditions.checkNotNull(value);%0A        tx.getLocals().set(this, value);%0A    %7D%0A%0A    public boolean isSet(HaeinsaTransaction tx) %7B%0A        Preconditions.checkNotNull(tx);%0A        return tx.getLocals().isSet(this);%0A    %7D%0A
+/**%0A * A HaeinsaTransactionLocal stores values associated with %7B@link HaeinsaTransaction%7D.%0A * %3Cp%3E%0A * You can create transaction local using %7B@link HaeinsaTransactionLocal#newLocal()%7D.%0A */%0Apublic final class HaeinsaTransactionLocal%3CT%3E %7B%0A    private HaeinsaTransactionLocal() %7B%7D%0A%0A    /*%0A     * Creates a transaction local variable.%0A     * @return a new transaction local variable%0A     */%0A    public static %3CT%3E HaeinsaTransactionLocal%3CT%3E newLocal() %7B%0A        return new HaeinsaTransactionLocal%3CT%3E();%0A    %7D%0A%0A    /*%0A     * Returns the value associated with the specified transaction.%0A     * If no value is set, returns %3Ccode%3Enull%3C/code%3E.%0A     * @param tx the transaction for which the variable it to be retrieved%0A     * @return the specified transaction's value of this transaction local,%0A     * or %3Ccode%3Enull%3C/code%3E if no value is set%0A     */%0A    @Nullable%0A    public T get(HaeinsaTransaction tx) %7B%0A        Preconditions.checkNotNull(tx);%0A        return (T) tx.getLocals().get(this);%0A    %7D%0A%0A    /*%0A     * Sets the value associated with the specified transaction.%0A     * Storing %3Ccode%3Enull%3C/code%3E as a value is not allowed.%0A     * @param tx the the transaction for which the value will be set%0A     * @param value the value to be associated with the transaction (cannot be %3Ccode%3Enull%3C/code%3E)%0A     */%0A    public void set(HaeinsaTransaction tx, T value) %7B%0A        Preconditions.checkNotNull(tx);%0A        Preconditions.checkNotNull(value);%0A        tx.getLocals().set(this, value);%0A    %7D%0A%0A    /*%0A     * Returns %3Ccode%3Etrue%3C/code%3E if this transaction local variable has the value associated with%0A     * the specified transaction.%0A     * @param tx the transaction for which the variable it to be retrieved%0A     * @return %3Ccode%3Etrue%3C/code%3E if this transaction local variable has the value associated with%0A     * the specified transaction%0A     */%0A    public boolean isSet(HaeinsaTransaction tx) %7B%0A        Preconditions.checkNotNull(tx);%0A        return tx.getLocals().isSet(this);%0A    %7D%0A%0A    /*%0A     * Removes the value associated with the specified transaction.%0A     * @param tx the the transaction for which the value will be removed%0A     * @return the previous value associated with transaction, or null if there was no value%0A     */
 %0A   

Add javadoc