Make fields private where possible

This commit is contained in:
Phillip Webb
2014-01-21 16:21:00 -08:00
parent 0160760568
commit 43e54d38f7
169 changed files with 280 additions and 280 deletions

View File

@@ -32,7 +32,7 @@ public class InMemoryAuditEventRepository implements AuditEventRepository {
private int capacity = 100;
private Map<String, List<AuditEvent>> events = new HashMap<String, List<AuditEvent>>();
private final Map<String, List<AuditEvent>> events = new HashMap<String, List<AuditEvent>>();
/**
* @param capacity the capacity to set

View File

@@ -30,7 +30,7 @@ import org.springframework.util.Assert;
*/
public class AuditApplicationEvent extends ApplicationEvent {
private AuditEvent auditEvent;
private final AuditEvent auditEvent;
/**
* Create a new {@link AuditApplicationEvent} that wraps a newly created

View File

@@ -38,7 +38,7 @@ import org.springframework.context.annotation.Configuration;
public class AuditAutoConfiguration {
@Autowired(required = false)
private AuditEventRepository auditEventRepository = new InMemoryAuditEventRepository();
private final AuditEventRepository auditEventRepository = new InMemoryAuditEventRepository();
@Bean
public AuditListener auditListener() throws Exception {

View File

@@ -340,9 +340,9 @@ public class CrshAutoConfiguration {
private static class BeanFactoryFilteringPluginDiscovery extends
ServiceLoaderDiscovery {
private ListableBeanFactory beanFactory;
private final ListableBeanFactory beanFactory;
private String[] disabledPlugins;
private final String[] disabledPlugins;
public BeanFactoryFilteringPluginDiscovery(ClassLoader classLoader,
ListableBeanFactory beanFactory, String[] disabledPlugins)
@@ -409,7 +409,7 @@ public class CrshAutoConfiguration {
*/
private static class SimpleFileSystemDriver extends AbstractFSDriver<ResourceHandle> {
private ResourceHandle root;
private final ResourceHandle root;
public SimpleFileSystemDriver(ResourceHandle handle) {
this.root = handle;
@@ -463,7 +463,7 @@ public class CrshAutoConfiguration {
*/
private abstract static class ResourceHandle {
private String name;
private final String name;
public ResourceHandle(String name) {
this.name = name;
@@ -480,7 +480,7 @@ public class CrshAutoConfiguration {
*/
private static class DirectoryHandle extends ResourceHandle {
private ResourcePatternResolver resourceLoader;
private final ResourcePatternResolver resourceLoader;
public DirectoryHandle(String name, ResourcePatternResolver resourceLoader) {
super(name);
@@ -505,7 +505,7 @@ public class CrshAutoConfiguration {
*/
private static class FileHandle extends ResourceHandle {
private Resource resource;
private final Resource resource;
public FileHandle(String name, Resource resource) {
super(name);

View File

@@ -78,13 +78,13 @@ public class EndpointAutoConfiguration {
private InfoPropertiesConfiguration properties;
@Autowired(required = false)
private MetricReader metricRepository = new InMemoryMetricRepository();
private final MetricReader metricRepository = new InMemoryMetricRepository();
@Autowired(required = false)
private PublicMetrics metrics;
@Autowired(required = false)
private TraceRepository traceRepository = new InMemoryTraceRepository();
private final TraceRepository traceRepository = new InMemoryTraceRepository();
@Bean
@ConditionalOnMissingBean
@@ -170,7 +170,7 @@ public class EndpointAutoConfiguration {
protected static class InfoPropertiesConfiguration {
@Autowired
private ConfigurableEnvironment environment = new StandardEnvironment();
private final ConfigurableEnvironment environment = new StandardEnvironment();
@Value("${spring.git.properties:classpath:git.properties}")
private Resource gitProperties;
@@ -198,7 +198,7 @@ public class EndpointAutoConfiguration {
public static class GitInfo {
private String branch;
private Commit commit = new Commit();
private final Commit commit = new Commit();
public String getBranch() {
return this.branch;

View File

@@ -89,7 +89,7 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
@Conditional(ErrorTemplateMissingCondition.class)
protected static class WhitelabelErrorViewConfiguration {
private SpelView defaultErrorView = new SpelView(
private final SpelView defaultErrorView = new SpelView(
"<html><body><h1>Whitelabel Error Page</h1>"
+ "<p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p>"
+ "<div id='created'>${timestamp}</div>"

View File

@@ -123,7 +123,7 @@ public class MetricRepositoryAutoConfiguration {
@Autowired(required = false)
@Qualifier("metricsExecutor")
private Executor executor = Executors.newSingleThreadExecutor();
private final Executor executor = Executors.newSingleThreadExecutor();
@Bean
@ConditionalOnMissingBean(name = "metricsChannel")

View File

@@ -39,9 +39,9 @@ import org.springframework.core.env.Environment;
public class BeansEndpoint extends AbstractEndpoint<List<Object>> implements
ApplicationContextAware {
private LiveBeansView liveBeansView = new LiveBeansView();
private final LiveBeansView liveBeansView = new LiveBeansView();
private JsonParser parser = JsonParserFactory.getJsonParser();
private final JsonParser parser = JsonParserFactory.getJsonParser();
public BeansEndpoint() {
super("beans");

View File

@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
@ConfigurationProperties(name = "endpoints.health", ignoreUnknownFields = false)
public class HealthEndpoint<T> extends AbstractEndpoint<T> {
private HealthIndicator<? extends T> indicator;
private final HealthIndicator<? extends T> indicator;
/**
* Create a new {@link HealthIndicator} instance.

View File

@@ -31,7 +31,7 @@ import org.springframework.util.Assert;
@ConfigurationProperties(name = "endpoints.info", ignoreUnknownFields = false)
public class InfoEndpoint extends AbstractEndpoint<Map<String, Object>> {
private Map<String, ? extends Object> info;
private final Map<String, ? extends Object> info;
/**
* Create a new {@link InfoEndpoint} instance.

View File

@@ -31,7 +31,7 @@ import org.springframework.util.Assert;
@ConfigurationProperties(name = "endpoints.metrics", ignoreUnknownFields = false)
public class MetricsEndpoint extends AbstractEndpoint<Map<String, Object>> {
private PublicMetrics metrics;
private final PublicMetrics metrics;
/**
* Create a new {@link MetricsEndpoint} instance.

View File

@@ -31,7 +31,7 @@ import org.springframework.util.Assert;
@ConfigurationProperties(name = "endpoints.trace", ignoreUnknownFields = false)
public class TraceEndpoint extends AbstractEndpoint<List<Trace>> {
private TraceRepository repository;
private final TraceRepository repository;
/**
* Create a new {@link TraceEndpoint} instance.

View File

@@ -31,7 +31,7 @@ import org.springframework.util.Assert;
*/
public class VanillaPublicMetrics implements PublicMetrics {
private MetricReader reader;
private final MetricReader reader;
public VanillaPublicMetrics(MetricReader reader) {
Assert.notNull(reader, "MetricReader must not be null");

View File

@@ -35,9 +35,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@ManagedResource
public class EndpointMBean {
private Endpoint<?> endpoint;
private final Endpoint<?> endpoint;
private ObjectMapper mapper = new ObjectMapper();
private final ObjectMapper mapper = new ObjectMapper();
public EndpointMBean(String beanName, Endpoint<?> endpoint) {
Assert.notNull(beanName, "BeanName must not be null");

View File

@@ -66,7 +66,7 @@ public class EndpointMBeanExporter extends MBeanExporter implements SmartLifecyc
private final MetadataNamingStrategy defaultNamingStrategy = new MetadataNamingStrategy(
this.attributeSource);
private Set<Endpoint<?>> registeredEndpoints = new HashSet<Endpoint<?>>();
private final Set<Endpoint<?>> registeredEndpoints = new HashSet<Endpoint<?>>();
private volatile boolean autoStartup = true;

View File

@@ -50,7 +50,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
public class EndpointHandlerMapping extends RequestMappingHandlerMapping implements
ApplicationContextAware {
private Set<? extends MvcEndpoint> endpoints;
private final Set<? extends MvcEndpoint> endpoints;
private String prefix = "";

View File

@@ -54,7 +54,7 @@ public class JolokiaMvcEndpoint implements MvcEndpoint, InitializingBean,
private boolean enabled = true;
private ServletWrappingController controller = new ServletWrappingController();
private final ServletWrappingController controller = new ServletWrappingController();
public JolokiaMvcEndpoint() {
this.path = "/jolokia";
@@ -123,7 +123,7 @@ public class JolokiaMvcEndpoint implements MvcEndpoint, InitializingBean,
private static class PathStripper extends HttpServletRequestWrapper {
private String path;
private final String path;
public PathStripper(HttpServletRequest request, String path) {
super(request);

View File

@@ -39,7 +39,7 @@ public class MvcEndpoints implements ApplicationContextAware, InitializingBean {
private ApplicationContext applicationContext;
private Set<MvcEndpoint> endpoints = new HashSet<MvcEndpoint>();
private final Set<MvcEndpoint> endpoints = new HashSet<MvcEndpoint>();
private Set<Class<?>> customTypes;

View File

@@ -36,9 +36,9 @@ import org.springframework.boot.actuate.metrics.writer.Delta;
public class InMemoryMetricRepository implements MetricRepository, MultiMetricRepository,
PrefixMetricReader {
private SimpleInMemoryRepository<Metric<?>> metrics = new SimpleInMemoryRepository<Metric<?>>();
private final SimpleInMemoryRepository<Metric<?>> metrics = new SimpleInMemoryRepository<Metric<?>>();
private Collection<String> groups = new HashSet<String>();
private final Collection<String> groups = new HashSet<String>();
@Override
public void increment(Delta<?> delta) {

View File

@@ -47,11 +47,11 @@ public class RedisMetricRepository implements MetricRepository {
private String keys = this.prefix + "keys";
private BoundZSetOperations<String, String> zSetOperations;
private final BoundZSetOperations<String, String> zSetOperations;
private RedisOperations<String, String> redisOperations;
private final RedisOperations<String, String> redisOperations;
private ValueOperations<String, Long> longOperations;
private final ValueOperations<String, Long> longOperations;
public RedisMetricRepository(RedisConnectionFactory redisConnectionFactory) {
Assert.notNull(redisConnectionFactory, "RedisConnectionFactory must not be null");

View File

@@ -46,9 +46,9 @@ public class RedisMultiMetricRepository implements MultiMetricRepository {
private String keys = this.prefix + "keys";
private BoundZSetOperations<String, String> zSetOperations;
private final BoundZSetOperations<String, String> zSetOperations;
private RedisOperations<String, String> redisOperations;
private final RedisOperations<String, String> redisOperations;
public RedisMultiMetricRepository(RedisConnectionFactory redisConnectionFactory) {
Assert.notNull(redisConnectionFactory, "RedisConnectionFactory must not be null");

View File

@@ -32,7 +32,7 @@ import org.springframework.boot.actuate.metrics.writer.MetricWriter;
*/
public class InMemoryRichGaugeRepository implements RichGaugeRepository {
private SimpleInMemoryRepository<RichGauge> repository = new SimpleInMemoryRepository<RichGauge>();
private final SimpleInMemoryRepository<RichGauge> repository = new SimpleInMemoryRepository<RichGauge>();
@Override
public void increment(Delta<?> delta) {

View File

@@ -30,9 +30,9 @@ import java.util.concurrent.ConcurrentSkipListMap;
*/
public class SimpleInMemoryRepository<T> {
private ConcurrentNavigableMap<String, T> values = new ConcurrentSkipListMap<String, T>();
private final ConcurrentNavigableMap<String, T> values = new ConcurrentSkipListMap<String, T>();
private ConcurrentMap<String, Object> locks = new ConcurrentHashMap<String, Object>();
private final ConcurrentMap<String, Object> locks = new ConcurrentHashMap<String, Object>();
public static interface Callback<T> {
T modify(T current);

View File

@@ -29,7 +29,7 @@ import org.springframework.boot.actuate.metrics.Metric;
*/
public class CompositeMetricWriter implements MetricWriter {
private List<MetricWriter> writers = new ArrayList<MetricWriter>();
private final List<MetricWriter> writers = new ArrayList<MetricWriter>();
public CompositeMetricWriter(MetricWriter... writers) {
for (MetricWriter writer : writers) {

View File

@@ -31,7 +31,7 @@ public class MessageChannelMetricWriter implements MetricWriter {
private static final String METRIC_NAME = "metricName";
private String DELETE = "delete";
private final String DELETE = "delete";
private final MessageChannel channel;

View File

@@ -42,7 +42,7 @@ public class ManagementServerProperties implements SecurityPrequisite {
@NotNull
private String contextPath = "";
private Security security = maybeCreateSecurity();
private final Security security = maybeCreateSecurity();
/**
* Returns the management port or {@code null} if the

View File

@@ -57,9 +57,9 @@ public class ShellProperties {
private String[] disabledPlugins = new String[0];
private Ssh ssh = new Ssh();
private final Ssh ssh = new Ssh();
private Telnet telnet = new Telnet();
private final Telnet telnet = new Telnet();
public void setAuth(String auth) {
Assert.hasLength(auth, "Auth must not be empty");

View File

@@ -31,7 +31,7 @@ public class InMemoryTraceRepository implements TraceRepository {
private int capacity = 100;
private List<Trace> traces = new ArrayList<Trace>();
private final List<Trace> traces = new ArrayList<Trace>();
/**
* @param capacity the capacity to set

View File

@@ -29,9 +29,9 @@ import org.springframework.util.Assert;
*/
public final class Trace {
private Date timestamp;
private final Date timestamp;
private Map<String, Object> info;
private final Map<String, Object> info;
public Trace(Date timestamp, Map<String, Object> info) {
super();

View File

@@ -55,7 +55,7 @@ public class WebRequestTraceFilter implements Filter, Ordered {
private int order = Integer.MAX_VALUE;
private ObjectMapper objectMapper = new ObjectMapper();
private final ObjectMapper objectMapper = new ObjectMapper();
private BasicErrorController errorController;

View File

@@ -51,7 +51,7 @@ public class BasicErrorController implements ErrorController {
private static final String ERROR_KEY = "error";
private Log logger = LogFactory.getLog(BasicErrorController.class);
private final Log logger = LogFactory.getLog(BasicErrorController.class);
@Value("${error.path:/error}")
private String errorPath;

View File

@@ -29,7 +29,7 @@ import static org.junit.Assert.assertEquals;
*/
public class InMemoryAuditEventRepositoryTests {
private InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
private final InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
@Test
public void testAddToCapacity() throws Exception {

View File

@@ -56,7 +56,7 @@ import static org.junit.Assert.assertThat;
*/
public class EndpointWebMvcAutoConfigurationTests {
private AnnotationConfigEmbeddedWebApplicationContext applicationContext = new AnnotationConfigEmbeddedWebApplicationContext();
private final AnnotationConfigEmbeddedWebApplicationContext applicationContext = new AnnotationConfigEmbeddedWebApplicationContext();
@After
public void close() {

View File

@@ -44,7 +44,7 @@ import static org.junit.Assert.assertThat;
*/
public class EndpointHandlerMappingTests {
private StaticApplicationContext context = new StaticApplicationContext();
private final StaticApplicationContext context = new StaticApplicationContext();
private Method method;
@Before

View File

@@ -40,7 +40,7 @@ import static org.mockito.Mockito.when;
*/
public class SimpleHealthIndicatorTests {
private SimpleHealthIndicator indicator = new SimpleHealthIndicator();
private final SimpleHealthIndicator indicator = new SimpleHealthIndicator();
private DriverManagerDataSource dataSource;
@Before

View File

@@ -29,9 +29,9 @@ import static org.junit.Assert.assertEquals;
*/
public class MetricCopyExporterTests {
private InMemoryMetricRepository writer = new InMemoryMetricRepository();
private InMemoryMetricRepository reader = new InMemoryMetricRepository();
private MetricCopyExporter exporter = new MetricCopyExporter(this.reader, this.writer);
private final InMemoryMetricRepository writer = new InMemoryMetricRepository();
private final InMemoryMetricRepository reader = new InMemoryMetricRepository();
private final MetricCopyExporter exporter = new MetricCopyExporter(this.reader, this.writer);
@Test
public void export() {

View File

@@ -32,11 +32,11 @@ import static org.junit.Assert.assertEquals;
*/
public class PrefixMetricGroupExporterTests {
private InMemoryMetricRepository reader = new InMemoryMetricRepository();
private final InMemoryMetricRepository reader = new InMemoryMetricRepository();
private InMemoryMetricRepository writer = new InMemoryMetricRepository();
private final InMemoryMetricRepository writer = new InMemoryMetricRepository();
private PrefixMetricGroupExporter exporter = new PrefixMetricGroupExporter(
private final PrefixMetricGroupExporter exporter = new PrefixMetricGroupExporter(
this.reader, this.writer);
@Test

View File

@@ -29,9 +29,9 @@ import static org.junit.Assert.assertEquals;
*/
public class RichGaugeExporterTests {
private InMemoryRichGaugeRepository reader = new InMemoryRichGaugeRepository();
private InMemoryMetricRepository writer = new InMemoryMetricRepository();
private RichGaugeExporter exporter = new RichGaugeExporter(this.reader, this.writer);
private final InMemoryRichGaugeRepository reader = new InMemoryRichGaugeRepository();
private final InMemoryMetricRepository writer = new InMemoryMetricRepository();
private final RichGaugeExporter exporter = new RichGaugeExporter(this.reader, this.writer);
@Test
public void prefixedMetricsCopied() {

View File

@@ -29,7 +29,7 @@ import static org.junit.Assert.assertEquals;
*/
public class InMemoryMetricRepositoryTests {
private InMemoryMetricRepository repository = new InMemoryMetricRepository();
private final InMemoryMetricRepository repository = new InMemoryMetricRepository();
@Test
public void increment() {

View File

@@ -31,7 +31,7 @@ import static org.junit.Assert.assertTrue;
*/
public class InMemoryPrefixMetricRepositoryTests {
private InMemoryMetricRepository repository = new InMemoryMetricRepository();
private final InMemoryMetricRepository repository = new InMemoryMetricRepository();
@Test
public void registeredPrefixCounted() {

View File

@@ -38,7 +38,7 @@ public class RedisServer implements TestRule {
protected LettuceConnectionFactory resource;
private String resourceDescription = "Redis ConnectionFactory";
private final String resourceDescription = "Redis ConnectionFactory";
private static final Log logger = LogFactory.getLog(RedisServer.class);

View File

@@ -26,7 +26,7 @@ import static org.junit.Assert.assertEquals;
*/
public class InMemoryRichGaugeRepositoryTests {
private InMemoryRichGaugeRepository repository = new InMemoryRichGaugeRepository();
private final InMemoryRichGaugeRepository repository = new InMemoryRichGaugeRepository();
@Test
public void writeAndRead() {

View File

@@ -37,7 +37,7 @@ import static org.junit.Assert.assertTrue;
*/
public class InMemoryRepositoryTests {
private SimpleInMemoryRepository<String> repository = new SimpleInMemoryRepository<String>();
private final SimpleInMemoryRepository<String> repository = new SimpleInMemoryRepository<String>();
@Test
public void setAndGet() {

View File

@@ -29,8 +29,8 @@ import static org.junit.Assert.assertEquals;
*/
public class CodahaleMetricWriterTests {
private MetricRegistry registry = new MetricRegistry();
private CodahaleMetricWriter writer = new CodahaleMetricWriter(this.registry);
private final MetricRegistry registry = new MetricRegistry();
private final CodahaleMetricWriter writer = new CodahaleMetricWriter(this.registry);
@Test
public void incrementCounter() {

View File

@@ -28,9 +28,9 @@ import static org.mockito.Mockito.verify;
*/
public class DefaultCounterServiceTests {
private MetricWriter repository = mock(MetricWriter.class);
private final MetricWriter repository = mock(MetricWriter.class);
private DefaultCounterService service = new DefaultCounterService(this.repository);
private final DefaultCounterService service = new DefaultCounterService(this.repository);
@Test
public void incrementPrependsCounter() {

View File

@@ -29,9 +29,9 @@ import static org.mockito.Mockito.verify;
*/
public class DefaultGaugeServiceTests {
private MetricWriter repository = mock(MetricWriter.class);
private final MetricWriter repository = mock(MetricWriter.class);
private DefaultGaugeService service = new DefaultGaugeService(this.repository);
private final DefaultGaugeService service = new DefaultGaugeService(this.repository);
@Test
public void setPrependsGauge() {

View File

@@ -30,9 +30,9 @@ import static org.mockito.Mockito.verify;
*/
public class MessageChannelMetricWriterTests {
private MessageChannel channel = mock(MessageChannel.class);
private final MessageChannel channel = mock(MessageChannel.class);
private MessageChannelMetricWriter observer = new MessageChannelMetricWriter(
private final MessageChannelMetricWriter observer = new MessageChannelMetricWriter(
this.channel);
@Test

View File

@@ -37,9 +37,9 @@ import static org.mockito.Mockito.verify;
*/
public class AuthenticationAuditListenerTests {
private AuthenticationAuditListener listener = new AuthenticationAuditListener();
private final AuthenticationAuditListener listener = new AuthenticationAuditListener();
private ApplicationEventPublisher publisher = Mockito
private final ApplicationEventPublisher publisher = Mockito
.mock(ApplicationEventPublisher.class);
@Before

View File

@@ -37,9 +37,9 @@ import static org.mockito.Mockito.verify;
*/
public class AuthorizationAuditListenerTests {
private AuthorizationAuditListener listener = new AuthorizationAuditListener();
private final AuthorizationAuditListener listener = new AuthorizationAuditListener();
private ApplicationEventPublisher publisher = Mockito
private final ApplicationEventPublisher publisher = Mockito
.mock(ApplicationEventPublisher.class);
@Before

View File

@@ -30,7 +30,7 @@ import static org.junit.Assert.assertEquals;
*/
public class InMemoryTraceRepositoryTests {
private InMemoryTraceRepository repository = new InMemoryTraceRepository();
private final InMemoryTraceRepository repository = new InMemoryTraceRepository();
@Test
public void capacityLimited() {

View File

@@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals;
*/
public class WebRequestTraceFilterTests {
private WebRequestTraceFilter filter = new WebRequestTraceFilter(
private final WebRequestTraceFilter filter = new WebRequestTraceFilter(
new InMemoryTraceRepository());
@Test