Commit 093ca0a6 authored by igor-suhorukov's avatar igor-suhorukov Committed by Phillip Webb

Use EnumMap whenever possible

Replace regular Map instances with EnumMap to reduce memory consumption.

Closes gh-11760
parent ab6ad6aa
...@@ -20,7 +20,7 @@ import java.lang.annotation.Annotation; ...@@ -20,7 +20,7 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
...@@ -50,7 +50,8 @@ abstract class DiscoveredOperationsFactory<O extends Operation> { ...@@ -50,7 +50,8 @@ abstract class DiscoveredOperationsFactory<O extends Operation> {
private static final Map<OperationType, Class<? extends Annotation>> OPERATION_TYPES; private static final Map<OperationType, Class<? extends Annotation>> OPERATION_TYPES;
static { static {
Map<OperationType, Class<? extends Annotation>> operationTypes = new LinkedHashMap<>(); Map<OperationType, Class<? extends Annotation>> operationTypes = new EnumMap<>(
OperationType.class);
operationTypes.put(OperationType.READ, ReadOperation.class); operationTypes.put(OperationType.READ, ReadOperation.class);
operationTypes.put(OperationType.WRITE, WriteOperation.class); operationTypes.put(OperationType.WRITE, WriteOperation.class);
operationTypes.put(OperationType.DELETE, DeleteOperation.class); operationTypes.put(OperationType.DELETE, DeleteOperation.class);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
package org.springframework.boot.autoconfigure.cache; package org.springframework.boot.autoconfigure.cache;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import org.springframework.util.Assert; import org.springframework.util.Assert;
...@@ -33,7 +33,7 @@ final class CacheConfigurations { ...@@ -33,7 +33,7 @@ final class CacheConfigurations {
private static final Map<CacheType, Class<?>> MAPPINGS; private static final Map<CacheType, Class<?>> MAPPINGS;
static { static {
Map<CacheType, Class<?>> mappings = new HashMap<>(); Map<CacheType, Class<?>> mappings = new EnumMap<>(CacheType.class);
mappings.put(CacheType.GENERIC, GenericCacheConfiguration.class); mappings.put(CacheType.GENERIC, GenericCacheConfiguration.class);
mappings.put(CacheType.EHCACHE, EhCacheCacheConfiguration.class); mappings.put(CacheType.EHCACHE, EhCacheCacheConfiguration.class);
mappings.put(CacheType.HAZELCAST, HazelcastCacheConfiguration.class); mappings.put(CacheType.HAZELCAST, HazelcastCacheConfiguration.class);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
package org.springframework.boot.autoconfigure.jackson; package org.springframework.boot.autoconfigure.jackson;
import java.util.HashMap; import java.util.EnumMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
...@@ -63,27 +63,31 @@ public class JacksonProperties { ...@@ -63,27 +63,31 @@ public class JacksonProperties {
/** /**
* Jackson on/off features that affect the way Java objects are serialized. * 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. * 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. * 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. * 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. * 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 * Controls the inclusion of properties during serialization. Configured with one of
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
package org.springframework.boot.autoconfigure.jooq; package org.springframework.boot.autoconfigure.jooq;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import javax.sql.DataSource; import javax.sql.DataSource;
...@@ -42,7 +42,7 @@ final class SqlDialectLookup { ...@@ -42,7 +42,7 @@ final class SqlDialectLookup {
private static final Map<DatabaseDriver, SQLDialect> LOOKUP; private static final Map<DatabaseDriver, SQLDialect> LOOKUP;
static { static {
Map<DatabaseDriver, SQLDialect> map = new HashMap<>(); Map<DatabaseDriver, SQLDialect> map = new EnumMap<>(DatabaseDriver.class);
map.put(DatabaseDriver.DERBY, SQLDialect.DERBY); map.put(DatabaseDriver.DERBY, SQLDialect.DERBY);
map.put(DatabaseDriver.H2, SQLDialect.H2); map.put(DatabaseDriver.H2, SQLDialect.H2);
map.put(DatabaseDriver.HSQLDB, SQLDialect.HSQLDB); map.put(DatabaseDriver.HSQLDB, SQLDialect.HSQLDB);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
package org.springframework.boot.autoconfigure.orm.jpa; package org.springframework.boot.autoconfigure.orm.jpa;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import javax.sql.DataSource; import javax.sql.DataSource;
...@@ -43,7 +43,7 @@ final class DatabaseLookup { ...@@ -43,7 +43,7 @@ final class DatabaseLookup {
private static final Map<DatabaseDriver, Database> LOOKUP; private static final Map<DatabaseDriver, Database> LOOKUP;
static { static {
Map<DatabaseDriver, Database> map = new HashMap<>(); Map<DatabaseDriver, Database> map = new EnumMap<>(DatabaseDriver.class);
map.put(DatabaseDriver.DERBY, Database.DERBY); map.put(DatabaseDriver.DERBY, Database.DERBY);
map.put(DatabaseDriver.H2, Database.H2); map.put(DatabaseDriver.H2, Database.H2);
map.put(DatabaseDriver.HSQLDB, Database.HSQL); map.put(DatabaseDriver.HSQLDB, Database.HSQL);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
package org.springframework.boot.autoconfigure.session; package org.springframework.boot.autoconfigure.session;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import org.springframework.boot.WebApplicationType; import org.springframework.boot.WebApplicationType;
...@@ -34,7 +34,8 @@ final class SessionStoreMappings { ...@@ -34,7 +34,8 @@ final class SessionStoreMappings {
private static final Map<StoreType, Map<WebApplicationType, Class<?>>> MAPPINGS; private static final Map<StoreType, Map<WebApplicationType, Class<?>>> MAPPINGS;
static { 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, mappings.put(StoreType.REDIS, createMapping(RedisSessionConfiguration.class,
RedisReactiveSessionConfiguration.class)); RedisReactiveSessionConfiguration.class));
mappings.put(StoreType.MONGODB, createMapping(MongoSessionConfiguration.class, mappings.put(StoreType.MONGODB, createMapping(MongoSessionConfiguration.class,
...@@ -54,7 +55,8 @@ final class SessionStoreMappings { ...@@ -54,7 +55,8 @@ final class SessionStoreMappings {
static Map<WebApplicationType, Class<?>> createMapping(Class<?> servletConfiguration, static Map<WebApplicationType, Class<?>> createMapping(Class<?> servletConfiguration,
Class<?> reactiveConfiguration) { Class<?> reactiveConfiguration) {
Map<WebApplicationType, Class<?>> mapping = new HashMap<>(); Map<WebApplicationType, Class<?>> mapping = new EnumMap<>(
WebApplicationType.class);
mapping.put(WebApplicationType.SERVLET, servletConfiguration); mapping.put(WebApplicationType.SERVLET, servletConfiguration);
if (reactiveConfiguration != null) { if (reactiveConfiguration != null) {
mapping.put(WebApplicationType.REACTIVE, reactiveConfiguration); mapping.put(WebApplicationType.REACTIVE, reactiveConfiguration);
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
package org.springframework.boot.autoconfigure.web.reactive.error; package org.springframework.boot.autoconfigure.web.reactive.error;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.EnumMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -79,7 +79,7 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa ...@@ -79,7 +79,7 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa
.getLog(DefaultErrorWebExceptionHandler.class); .getLog(DefaultErrorWebExceptionHandler.class);
static { 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.CLIENT_ERROR, "4xx");
views.put(HttpStatus.Series.SERVER_ERROR, "5xx"); views.put(HttpStatus.Series.SERVER_ERROR, "5xx");
SERIES_VIEWS = Collections.unmodifiableMap(views); SERIES_VIEWS = Collections.unmodifiableMap(views);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
package org.springframework.boot.autoconfigure.web.servlet.error; package org.springframework.boot.autoconfigure.web.servlet.error;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -60,7 +60,7 @@ public class DefaultErrorViewResolver implements ErrorViewResolver, Ordered { ...@@ -60,7 +60,7 @@ public class DefaultErrorViewResolver implements ErrorViewResolver, Ordered {
private static final Map<Series, String> SERIES_VIEWS; private static final Map<Series, String> SERIES_VIEWS;
static { static {
Map<Series, String> views = new HashMap<>(); Map<Series, String> views = new EnumMap<>(Series.class);
views.put(Series.CLIENT_ERROR, "4xx"); views.put(Series.CLIENT_ERROR, "4xx");
views.put(Series.SERVER_ERROR, "5xx"); views.put(Series.SERVER_ERROR, "5xx");
SERIES_VIEWS = Collections.unmodifiableMap(views); SERIES_VIEWS = Collections.unmodifiableMap(views);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -25,7 +25,7 @@ import java.net.URI; ...@@ -25,7 +25,7 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
...@@ -61,7 +61,8 @@ public class ClassPathChangeUploader ...@@ -61,7 +61,8 @@ public class ClassPathChangeUploader
private static final Map<ChangedFile.Type, ClassLoaderFile.Kind> TYPE_MAPPINGS; private static final Map<ChangedFile.Type, ClassLoaderFile.Kind> TYPE_MAPPINGS;
static { static {
Map<ChangedFile.Type, ClassLoaderFile.Kind> map = new HashMap<>(); Map<ChangedFile.Type, ClassLoaderFile.Kind> map = new EnumMap<>(
ChangedFile.Type.class);
map.put(ChangedFile.Type.ADD, ClassLoaderFile.Kind.ADDED); map.put(ChangedFile.Type.ADD, ClassLoaderFile.Kind.ADDED);
map.put(ChangedFile.Type.DELETE, ClassLoaderFile.Kind.DELETED); map.put(ChangedFile.Type.DELETE, ClassLoaderFile.Kind.DELETED);
map.put(ChangedFile.Type.MODIFY, ClassLoaderFile.Kind.MODIFIED); map.put(ChangedFile.Type.MODIFY, ClassLoaderFile.Kind.MODIFIED);
......
...@@ -18,6 +18,7 @@ package org.springframework.boot.configurationprocessor; ...@@ -18,6 +18,7 @@ package org.springframework.boot.configurationprocessor;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -45,7 +46,7 @@ class TypeUtils { ...@@ -45,7 +46,7 @@ class TypeUtils {
private static final Map<TypeKind, Class<?>> PRIMITIVE_WRAPPERS; private static final Map<TypeKind, Class<?>> PRIMITIVE_WRAPPERS;
static { static {
Map<TypeKind, Class<?>> wrappers = new HashMap<>(); Map<TypeKind, Class<?>> wrappers = new EnumMap<>(TypeKind.class);
wrappers.put(TypeKind.BOOLEAN, Boolean.class); wrappers.put(TypeKind.BOOLEAN, Boolean.class);
wrappers.put(TypeKind.BYTE, Byte.class); wrappers.put(TypeKind.BYTE, Byte.class);
wrappers.put(TypeKind.CHAR, Character.class); wrappers.put(TypeKind.CHAR, Character.class);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -19,7 +19,7 @@ package org.springframework.boot.ansi; ...@@ -19,7 +19,7 @@ package org.springframework.boot.ansi;
import java.awt.Color; import java.awt.Color;
import java.awt.color.ColorSpace; import java.awt.color.ColorSpace;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
...@@ -39,7 +39,7 @@ public final class AnsiColors { ...@@ -39,7 +39,7 @@ public final class AnsiColors {
private static final Map<AnsiColor, LabColor> ANSI_COLOR_MAP; private static final Map<AnsiColor, LabColor> ANSI_COLOR_MAP;
static { static {
Map<AnsiColor, LabColor> colorMap = new LinkedHashMap<>(); Map<AnsiColor, LabColor> colorMap = new EnumMap<>(AnsiColor.class);
colorMap.put(AnsiColor.BLACK, new LabColor(0x000000)); colorMap.put(AnsiColor.BLACK, new LabColor(0x000000));
colorMap.put(AnsiColor.RED, new LabColor(0xAA0000)); colorMap.put(AnsiColor.RED, new LabColor(0xAA0000));
colorMap.put(AnsiColor.GREEN, new LabColor(0x00AA00)); colorMap.put(AnsiColor.GREEN, new LabColor(0x00AA00));
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package org.springframework.boot.logging; package org.springframework.boot.logging;
import java.util.Comparator; import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
...@@ -194,7 +195,7 @@ public abstract class AbstractLoggingSystem extends LoggingSystem { ...@@ -194,7 +195,7 @@ public abstract class AbstractLoggingSystem extends LoggingSystem {
private final Map<T, LogLevel> nativeToSystem; private final Map<T, LogLevel> nativeToSystem;
public LogLevels() { public LogLevels() {
this.systemToNative = new HashMap<>(); this.systemToNative = new EnumMap<>(LogLevel.class);
this.nativeToSystem = new HashMap<>(); this.nativeToSystem = new HashMap<>();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment