Remove null usage for subscriber absence in SettingImpl
@@ -86,6 +86,8 @@ public SettingImpl(Class<T> valueClass, SimpleUri id, T defaultValue, SettingVal
this.defaultValue = defaultValue;
this.value = this.defaultValue;
this.valueClass = valueClass;
+
+ this.subscribers = Sets.newHashSet();
}
private String formatWarning(String s) {
@@ -97,12 +99,10 @@ private void logWarning(String warningMessage) {
}
private void dispatchChangedEvent(PropertyChangeEvent event) {
- if (subscribers != null) {
for (PropertyChangeListener subscriber : subscribers) {
subscriber.propertyChange(event);
}
}
- }
private boolean validate(T valueToValidate) {
return validator == null || validator.validate(valueToValidate);
@@ -113,10 +113,6 @@ private boolean validate(T valueToValidate) {
*/
@Override
public boolean subscribe(PropertyChangeListener listener) {
- if (subscribers == null) {
- subscribers = Sets.newHashSet();
- }
-
if (listener == null) {
logWarning("A null subscriber cannot be added.");
@@ -145,10 +141,6 @@ public boolean unsubscribe(PropertyChangeListener listener) {
subscribers.remove(listener);
- if (subscribers.size() <= 0) {
- subscribers = null;
- }
-
return true;
}
@@ -157,7 +149,7 @@ public boolean unsubscribe(PropertyChangeListener listener) {
*/
@Override
public boolean hasSubscribers() {
- return subscribers != null;
+ return subscribers.size() > 0;
}
/**
