Commit a0308f8d by Jason Song

Merge pull request #219 from yiming187/client_update

Add get array property interface in client
parents 9dfb8dcc 8abbac63
......@@ -5,19 +5,20 @@ package com.ctrip.framework.apollo;
*/
public interface Config {
/**
* Return the property value with the given key, or
* {@code defaultValue} if the key doesn't exist.
* Return the property value with the given key, or {@code defaultValue} if the key doesn't exist.
*
* @param key the property name
* @param defaultValue the default value is key is not found
* @param defaultValue the default value when key is not found
* @return the property value
*/
public String getProperty(String key, String defaultValue);
/**
* Return the integer property value with the given key, or
* {@code defaultValue} if the key doesn't exist.
* Return the integer property value with the given key, or {@code defaultValue} if the key
* doesn't exist.
*
* @param key the property name
* @param defaultValue the default value is key is not found
* @param defaultValue the default value when key is not found
* @return the property value as integer
*
* @throws NumberFormatException if the property value is invalid
......@@ -25,10 +26,11 @@ public interface Config {
public Integer getIntProperty(String key, Integer defaultValue);
/**
* Return the long property value with the given key, or
* {@code defaultValue} if the key doesn't exist.
* Return the long property value with the given key, or {@code defaultValue} if the key doesn't
* exist.
*
* @param key the property name
* @param defaultValue the default value is key is not found
* @param defaultValue the default value when key is not found
* @return the property value as long
*
* @throws NumberFormatException if the property value is invalid
......@@ -36,10 +38,11 @@ public interface Config {
public Long getLongProperty(String key, Long defaultValue);
/**
* Return the short property value with the given key, or
* {@code defaultValue} if the key doesn't exist.
* Return the short property value with the given key, or {@code defaultValue} if the key doesn't
* exist.
*
* @param key the property name
* @param defaultValue the default value is key is not found
* @param defaultValue the default value when key is not found
* @return the property value as short
*
* @throws NumberFormatException if the property value is invalid
......@@ -47,10 +50,11 @@ public interface Config {
public Short getShortProperty(String key, Short defaultValue);
/**
* Return the float property value with the given key, or
* {@code defaultValue} if the key doesn't exist.
* Return the float property value with the given key, or {@code defaultValue} if the key doesn't
* exist.
*
* @param key the property name
* @param defaultValue the default value is key is not found
* @param defaultValue the default value when key is not found
* @return the property value as float
*
* @throws NumberFormatException if the property value is invalid
......@@ -58,10 +62,11 @@ public interface Config {
public Float getFloatProperty(String key, Float defaultValue);
/**
* Return the double property value with the given key, or
* {@code defaultValue} if the key doesn't exist.
* Return the double property value with the given key, or {@code defaultValue} if the key doesn't
* exist.
*
* @param key the property name
* @param defaultValue the default value is key is not found
* @param defaultValue the default value when key is not found
* @return the property value as double
*
* @throws NumberFormatException if the property value is invalid
......@@ -69,10 +74,11 @@ public interface Config {
public Double getDoubleProperty(String key, Double defaultValue);
/**
* Return the byte property value with the given key, or
* {@code defaultValue} if the key doesn't exist.
* Return the byte property value with the given key, or {@code defaultValue} if the key doesn't
* exist.
*
* @param key the property name
* @param defaultValue the default value is key is not found
* @param defaultValue the default value when key is not found
* @return the property value as byte
*
* @throws NumberFormatException if the property value is invalid
......@@ -80,16 +86,29 @@ public interface Config {
public Byte getByteProperty(String key, Byte defaultValue);
/**
* Return the boolean property value with the given key, or
* {@code defaultValue} if the key doesn't exist.
* Return the boolean property value with the given key, or {@code defaultValue} if the key
* doesn't exist.
*
* @param key the property name
* @param defaultValue the default value is key is not found
* @param defaultValue the default value when key is not found
* @return the property value as boolean
*/
public Boolean getBooleanProperty(String key, Boolean defaultValue);
/**
* Return the array property value with the given key, or {@code defaultValue} if the key doesn't
* exist.
*
* @param key the property name
* @param delimiter
* @param defaultValue the default value when key is not found
* @return
*/
public String[] getArrayProperty(String key, String delimiter, String[] defaultValue);
/**
* Add change listener to this config instance.
*
* @param listener the config change listener
*/
public void addChangeListener(ConfigChangeListener listener);
......
......@@ -74,6 +74,12 @@ public abstract class AbstractConfig implements Config {
return value == null ? defaultValue : Boolean.parseBoolean(value);
}
@Override
public String[] getArrayProperty(String key, String delimiter, String[] defaultValue) {
String value = getProperty(key, null);
return value == null ? defaultValue : value.split(delimiter);
}
protected void fireConfigChange(ConfigChangeEvent changeEvent) {
for (ConfigChangeListener listener : m_listeners) {
try {
......@@ -85,9 +91,8 @@ public abstract class AbstractConfig implements Config {
}
}
List<ConfigChange> calcPropertyChanges(String namespace,
Properties previous,
Properties current) {
List<ConfigChange> calcPropertyChanges(String namespace, Properties previous,
Properties current) {
if (previous == null) {
previous = new Properties();
}
......@@ -106,9 +111,8 @@ public abstract class AbstractConfig implements Config {
List<ConfigChange> changes = Lists.newArrayList();
for (String newKey : newKeys) {
changes
.add(new ConfigChange(namespace, newKey, null, current.getProperty(newKey),
PropertyChangeType.ADDED));
changes.add(new ConfigChange(namespace, newKey, null, current.getProperty(newKey),
PropertyChangeType.ADDED));
}
for (String removedKey : removedKeys) {
......@@ -122,8 +126,8 @@ public abstract class AbstractConfig implements Config {
if (Objects.equal(previousValue, currentValue)) {
continue;
}
changes.add(new ConfigChange(namespace, commonKey, previousValue,
currentValue, PropertyChangeType.MODIFIED));
changes.add(new ConfigChange(namespace, commonKey, previousValue, currentValue,
PropertyChangeType.MODIFIED));
}
return changes;
......
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