Use EnumMap whenever possible

Replace regular Map instances with EnumMap to reduce memory consumption.

Closes gh-11760
This commit is contained in:
igor-suhorukov
2018-01-25 01:56:23 +03:00
committed by Phillip Webb
parent ab6ad6aa4b
commit 093ca0a687
12 changed files with 46 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -17,7 +17,7 @@
package org.springframework.boot.autoconfigure.cache;
import java.util.Collections;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;
import org.springframework.util.Assert;
@@ -33,7 +33,7 @@ final class CacheConfigurations {
private static final Map<CacheType, Class<?>> MAPPINGS;
static {
Map<CacheType, Class<?>> mappings = new HashMap<>();
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);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -16,7 +16,7 @@
package org.springframework.boot.autoconfigure.jackson;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
@@ -63,27 +63,31 @@ public class JacksonProperties {
/**
* Jackson on/off features that affect the way Java objects are serialized.
*/
private Map<SerializationFeature, Boolean> serialization = new HashMap<>();
private Map<SerializationFeature, Boolean> serialization = new EnumMap<>(
SerializationFeature.class);
/**
* Jackson on/off features that affect the way Java objects are deserialized.
*/
private Map<DeserializationFeature, Boolean> deserialization = new HashMap<>();
private Map<DeserializationFeature, Boolean> deserialization = new EnumMap<>(
DeserializationFeature.class);
/**
* Jackson general purpose on/off features.
*/
private Map<MapperFeature, Boolean> mapper = new HashMap<>();
private Map<MapperFeature, Boolean> mapper = new EnumMap<>(MapperFeature.class);
/**
* Jackson on/off features for parsers.
*/
private Map<JsonParser.Feature, Boolean> parser = new HashMap<>();
private Map<JsonParser.Feature, Boolean> parser = new EnumMap<>(
JsonParser.Feature.class);
/**
* Jackson on/off features for generators.
*/
private Map<JsonGenerator.Feature, Boolean> generator = new HashMap<>();
private Map<JsonGenerator.Feature, Boolean> generator = new EnumMap<>(
JsonGenerator.Feature.class);
/**
* Controls the inclusion of properties during serialization. Configured with one of

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -17,7 +17,7 @@
package org.springframework.boot.autoconfigure.jooq;
import java.util.Collections;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;
import javax.sql.DataSource;
@@ -42,7 +42,7 @@ final class SqlDialectLookup {
private static final Map<DatabaseDriver, SQLDialect> LOOKUP;
static {
Map<DatabaseDriver, SQLDialect> map = new HashMap<>();
Map<DatabaseDriver, SQLDialect> map = new EnumMap<>(DatabaseDriver.class);
map.put(DatabaseDriver.DERBY, SQLDialect.DERBY);
map.put(DatabaseDriver.H2, SQLDialect.H2);
map.put(DatabaseDriver.HSQLDB, SQLDialect.HSQLDB);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -17,7 +17,7 @@
package org.springframework.boot.autoconfigure.orm.jpa;
import java.util.Collections;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;
import javax.sql.DataSource;
@@ -43,7 +43,7 @@ final class DatabaseLookup {
private static final Map<DatabaseDriver, Database> LOOKUP;
static {
Map<DatabaseDriver, Database> map = new HashMap<>();
Map<DatabaseDriver, Database> map = new EnumMap<>(DatabaseDriver.class);
map.put(DatabaseDriver.DERBY, Database.DERBY);
map.put(DatabaseDriver.H2, Database.H2);
map.put(DatabaseDriver.HSQLDB, Database.HSQL);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -17,7 +17,7 @@
package org.springframework.boot.autoconfigure.session;
import java.util.Collections;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;
import org.springframework.boot.WebApplicationType;
@@ -34,7 +34,8 @@ final class SessionStoreMappings {
private static final Map<StoreType, Map<WebApplicationType, Class<?>>> MAPPINGS;
static {
Map<StoreType, Map<WebApplicationType, Class<?>>> mappings = new HashMap<>();
Map<StoreType, Map<WebApplicationType, Class<?>>> mappings = new EnumMap<>(
StoreType.class);
mappings.put(StoreType.REDIS, createMapping(RedisSessionConfiguration.class,
RedisReactiveSessionConfiguration.class));
mappings.put(StoreType.MONGODB, createMapping(MongoSessionConfiguration.class,
@@ -54,7 +55,8 @@ final class SessionStoreMappings {
static Map<WebApplicationType, Class<?>> createMapping(Class<?> servletConfiguration,
Class<?> reactiveConfiguration) {
Map<WebApplicationType, Class<?>> mapping = new HashMap<>();
Map<WebApplicationType, Class<?>> mapping = new EnumMap<>(
WebApplicationType.class);
mapping.put(WebApplicationType.SERVLET, servletConfiguration);
if (reactiveConfiguration != null) {
mapping.put(WebApplicationType.REACTIVE, reactiveConfiguration);

View File

@@ -17,7 +17,7 @@
package org.springframework.boot.autoconfigure.web.reactive.error;
import java.util.Collections;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
@@ -79,7 +79,7 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa
.getLog(DefaultErrorWebExceptionHandler.class);
static {
Map<HttpStatus.Series, String> views = new HashMap<>();
Map<HttpStatus.Series, String> views = new EnumMap<>(HttpStatus.Series.class);
views.put(HttpStatus.Series.CLIENT_ERROR, "4xx");
views.put(HttpStatus.Series.SERVER_ERROR, "5xx");
SERIES_VIEWS = Collections.unmodifiableMap(views);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -17,7 +17,7 @@
package org.springframework.boot.autoconfigure.web.servlet.error;
import java.util.Collections;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
@@ -60,7 +60,7 @@ public class DefaultErrorViewResolver implements ErrorViewResolver, Ordered {
private static final Map<Series, String> SERIES_VIEWS;
static {
Map<Series, String> views = new HashMap<>();
Map<Series, String> views = new EnumMap<>(Series.class);
views.put(Series.CLIENT_ERROR, "4xx");
views.put(Series.SERVER_ERROR, "5xx");
SERIES_VIEWS = Collections.unmodifiableMap(views);