/*
 * Copyright 2005 The Apache Software Foundation.
 *
 * 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 org.apache.jcs.yajcache.core;

import org.apache.jcs.yajcache.soft.SoftRefCache;
import org.apache.jcs.yajcache.soft.SoftRefFileCache;

import org.apache.jcs.yajcache.lang.annotation.*;

/**
 * Cache Type.
 *
 * @author Hanson Char
 */
// @CopyRightApache
// http://www.netbeans.org/issues/show_bug.cgi?id=53704
public enum CacheType {
    SOFT_REFERENCE,
    SOFT_REFERENCE_SAFE,
    SOFT_REFERENCE_FILE,
    SOFT_REFERENCE_FILE_SAFE;

    <V> ICache<V> createCache(String name, @NonNullable Class<V> valueType)
    {
        switch(this) {
            case SOFT_REFERENCE:
                return new SoftRefCache<V>(name, valueType);
            case SOFT_REFERENCE_SAFE:
                return new SafeCacheWrapper<V>(new SoftRefCache<V>(name, valueType));
            case SOFT_REFERENCE_FILE:
                return new SoftRefFileCache<V>(name, valueType);
            case SOFT_REFERENCE_FILE_SAFE:
                return new SafeCacheWrapper<V>(new SoftRefFileCache<V>(name, valueType));
        }
        throw new AssertionError(this);
    }
    <V> ICacheSafe<V> createSafeCache(String name, @NonNullable Class<V> valueType)
    {
        switch(this) {
            case SOFT_REFERENCE_SAFE:
                return new SafeCacheWrapper<V>(new SoftRefCache<V>(name, valueType));
            case SOFT_REFERENCE_FILE_SAFE:
                return new SafeCacheWrapper<V>(new SoftRefFileCache<V>(name, valueType));
        }
        throw new UnsupportedOperationException("");
    }
}

@@ -1053,16 +1053,97 @@
 _SAFE;%0A%0A
+    /** Instantiates and returns a new instance of cache of the current type. */%0A
     %3CV%3E 
@@ -1202,32 +1202,32 @@
 s%3CV%3E valueType)%0A
-
     %7B%0A        sw
@@ -1745,24 +1745,110 @@
 his);%0A    %7D%0A
+    /** Instantiates and returns a new instance of safe cache of the current type. */%0A
     %3CV%3E ICac
@@ -2207,32 +2207,32 @@
 pe));%0A        %7D%0A
-
         throw ne
@@ -2274,10 +2274,1031 @@
 ;%0A    %7D%0A
+    /** %0A     * Returns true if cache of the given cache type can be used as%0A     * cache of the current cache type;%0A     * false otherwise.%0A     */%0A    public boolean isAsssignableFrom(CacheType from) %7B%0A        switch(this) %7B%0A            case SOFT_REFERENCE:%0A                return true;%0A            case SOFT_REFERENCE_SAFE:%0A                switch(from) %7B%0A                    case SOFT_REFERENCE_SAFE:%0A                    case SOFT_REFERENCE_FILE_SAFE:%0A                        return true;%0A                    default:%0A                        return false;%0A                %7D%0A            case SOFT_REFERENCE_FILE:%0A                switch(from) %7B%0A                    case SOFT_REFERENCE_FILE:%0A                    case SOFT_REFERENCE_FILE_SAFE:%0A                        return true;%0A                    default:%0A                        return false;%0A                %7D%0A            case SOFT_REFERENCE_FILE_SAFE:%0A                return from == SOFT_REFERENCE_FILE_SAFE;%0A        %7D%0A        throw new AssertionError(this);%0A    %7D%0A
 %7D%0A

add isAssignableFrom