/*
 * Copyright 2012-2020 the original author or authors.
 *
 * 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
 *
 *      https://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.springframework.boot.autoconfigure.cache;

import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;

import org.springframework.util.Assert;

/**
 * Mappings between {@link CacheType} and {@code @Configuration}.
 *
 * @author Phillip Webb
 * @author Eddú Meléndez
 */
@SuppressWarnings("deprecation")
final class CacheConfigurations {

	private static final Map<CacheType, Class<?>> MAPPINGS;

	static {
		Map<CacheType, Class<?>> mappings = new EnumMap<>(CacheType.class);
		mappings.put(CacheType.GENERIC, GenericCacheConfiguration.class);
		mappings.put(CacheType.EHCACHE, EhCacheCacheConfiguration.class);
		mappings.put(CacheType.HAZELCAST, HazelcastCacheConfiguration.class);
		mappings.put(CacheType.INFINISPAN, InfinispanCacheConfiguration.class);
		mappings.put(CacheType.JCACHE, JCacheCacheConfiguration.class);
		mappings.put(CacheType.COUCHBASE, CouchbaseCacheConfiguration.class);
		mappings.put(CacheType.REDIS, RedisCacheConfiguration.class);
		mappings.put(CacheType.CAFFEINE, CaffeineCacheConfiguration.class);
		mappings.put(CacheType.SIMPLE, SimpleCacheConfiguration.class);
		mappings.put(CacheType.NONE, NoOpCacheConfiguration.class);
		MAPPINGS = Collections.unmodifiableMap(mappings);
	}

	private CacheConfigurations() {
	}

	static String getConfigurationClass(CacheType cacheType) {
		Class<?> configurationClass = MAPPINGS.get(cacheType);
		Assert.state(configurationClass != null, () -> "Unknown cache type " + cacheType);
		return configurationClass.getName();
	}

	static CacheType getType(String configurationClassName) {
		for (Map.Entry<CacheType, Class<?>> entry : MAPPINGS.entrySet()) {
			if (entry.getValue().getName().equals(configurationClassName)) {
				return entry.getKey();
			}
		}
		throw new IllegalStateException("Unknown configuration class " + configurationClassName);
	}

}

@@ -17,17 +17,17 @@
 2012-202
-0
+1
  the ori
@@ -913,16 +913,45 @@
 el%C3%A9ndez%0A
+ * @author Sebastien Deleuze%0A
  */%0A@Sup
@@ -1051,24 +1051,22 @@
 heType, 
-Class%3C?%3E
+String
 %3E MAPPIN
@@ -1097,24 +1097,22 @@
 heType, 
-Class%3C?%3E
+String
 %3E mappin
@@ -1205,32 +1205,42 @@
 figuration.class
+.getName()
 );%0A%09%09mappings.pu
@@ -1283,32 +1283,42 @@
 figuration.class
+.getName()
 );%0A%09%09mappings.pu
@@ -1365,32 +1365,42 @@
 figuration.class
+.getName()
 );%0A%09%09mappings.pu
@@ -1449,32 +1449,42 @@
 figuration.class
+.getName()
 );%0A%09%09mappings.pu
@@ -1525,32 +1525,42 @@
 figuration.class
+.getName()
 );%0A%09%09mappings.pu
@@ -1607,32 +1607,42 @@
 figuration.class
+.getName()
 );%0A%09%09mappings.pu
@@ -1681,32 +1681,42 @@
 figuration.class
+.getName()
 );%0A%09%09mappings.pu
@@ -1761,32 +1761,42 @@
 figuration.class
+.getName()
 );%0A%09%09mappings.pu
@@ -1841,24 +1841,34 @@
 ration.class
+.getName()
 );%0A%09%09mapping
@@ -1913,24 +1913,34 @@
 ration.class
+.getName()
 );%0A%09%09MAPPING
@@ -2085,24 +2085,22 @@
 pe) %7B%0A%09%09
-Class%3C?%3E
+String
  configu
@@ -2110,16 +2110,20 @@
 ionClass
+Name
  = MAPPI
@@ -2175,16 +2175,20 @@
 ionClass
+Name
  != null
@@ -2258,26 +2258,20 @@
 ionClass
-.get
 Name
-()
 ;%0A%09%7D%0A%0A%09s
@@ -2359,16 +2359,14 @@
 pe, 
-Class%3C?%3E
+String
 %3E en
@@ -2422,18 +2422,8 @@
 e().
-getName().
 equa

Refactor CacheConfigurations to avoid storing configuration classes