From 877105ee19dfa81645ea8658b242617fd83ecc2b Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 12 Mar 2013 12:32:05 -0700 Subject: [PATCH] no need for specific time / empty based classes, just as final fields --- .../cluster/settings/DynamicSettings.java | 4 ++-- .../cluster/settings/Validator.java | 24 +++++-------------- .../settings/IndexDynamicSettingsModule.java | 2 +- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/elasticsearch/cluster/settings/DynamicSettings.java b/src/main/java/org/elasticsearch/cluster/settings/DynamicSettings.java index cdb758b0fe4..460b74c0126 100644 --- a/src/main/java/org/elasticsearch/cluster/settings/DynamicSettings.java +++ b/src/main/java/org/elasticsearch/cluster/settings/DynamicSettings.java @@ -56,14 +56,14 @@ public class DynamicSettings { } public synchronized void addDynamicSetting(String setting) { - addDynamicSetting(setting, Validator.EmptyValidator.INSTANCE); + addDynamicSetting(setting, Validator.EMPTY); } public synchronized void addDynamicSettings(String... settings) { MapBuilder updatedSettings = MapBuilder.newMapBuilder(dynamicSettings); for (String setting : settings) { - updatedSettings.put(setting, Validator.EmptyValidator.INSTANCE); + updatedSettings.put(setting, Validator.EMPTY); } dynamicSettings = updatedSettings.immutableMap(); } diff --git a/src/main/java/org/elasticsearch/cluster/settings/Validator.java b/src/main/java/org/elasticsearch/cluster/settings/Validator.java index dc62eb8f93f..cf56239f412 100644 --- a/src/main/java/org/elasticsearch/cluster/settings/Validator.java +++ b/src/main/java/org/elasticsearch/cluster/settings/Validator.java @@ -23,32 +23,20 @@ import org.elasticsearch.ElasticSearchParseException; import org.elasticsearch.common.unit.TimeValue; /** + * Validates a setting, returning a failure message if applicable. */ public interface Validator { + String validate(String setting, String value); - public static class EmptyValidator implements Validator { - - public static final EmptyValidator INSTANCE = new EmptyValidator(); - - private EmptyValidator() { - - } - + public static final Validator EMPTY = new Validator() { @Override public String validate(String setting, String value) { return null; } - } - - public static class TimeValueValidator implements Validator { - - public static final TimeValueValidator INSTANCE = new TimeValueValidator(); - - private TimeValueValidator() { - - } + }; + public static final Validator TIME = new Validator() { @Override public String validate(String setting, String value) { try { @@ -60,5 +48,5 @@ public interface Validator { } return null; } - } + }; } diff --git a/src/main/java/org/elasticsearch/index/settings/IndexDynamicSettingsModule.java b/src/main/java/org/elasticsearch/index/settings/IndexDynamicSettingsModule.java index 1de8724e459..d9b85e6798a 100644 --- a/src/main/java/org/elasticsearch/index/settings/IndexDynamicSettingsModule.java +++ b/src/main/java/org/elasticsearch/index/settings/IndexDynamicSettingsModule.java @@ -63,7 +63,7 @@ public class IndexDynamicSettingsModule extends AbstractModule { indexDynamicSettings.addDynamicSetting(IndexMetaData.SETTING_BLOCKS_METADATA); indexDynamicSettings.addDynamicSetting(IndexShardGatewayService.INDEX_GATEWAY_SNAPSHOT_INTERVAL); indexDynamicSettings.addDynamicSetting(IndicesTTLService.INDEX_TTL_DISABLE_PURGE); - indexDynamicSettings.addDynamicSetting(InternalIndexShard.INDEX_REFRESH_INTERVAL, Validator.TimeValueValidator.INSTANCE); + indexDynamicSettings.addDynamicSetting(InternalIndexShard.INDEX_REFRESH_INTERVAL, Validator.TIME); indexDynamicSettings.addDynamicSetting(LocalGatewayAllocator.INDEX_RECOVERY_INITIAL_SHARDS); indexDynamicSettings.addDynamicSetting(LogByteSizeMergePolicyProvider.INDEX_MERGE_POLICY_MIN_MERGE_SIZE); indexDynamicSettings.addDynamicSetting(LogByteSizeMergePolicyProvider.INDEX_MERGE_POLICY_MAX_MERGE_SIZE);