@SuppressWarnings("unchecked") @Override public <T> T get(IClientConfigKey<T> key) { Object obj = getProperty(key.key()); if (obj == null) { return null; } Class<T> type = key.type(); if (type.isInstance(obj)) { return type.cast(obj); } else { if (obj instanceof String) { String stringValue = (String) obj; if (Integer.class.equals(type)) { return (T) Integer.valueOf(stringValue); } else if (Boolean.class.equals(type)) { return (T) Boolean.valueOf(stringValue); } else if (Float.class.equals(type)) { return (T) Float.valueOf(stringValue); } else if (Long.class.equals(type)) { return (T) Long.valueOf(stringValue); } else if (Double.class.equals(type)) { return (T) Double.valueOf(stringValue); } else if (TimeUnit.class.equals(type)) { return (T) TimeUnit.valueOf(stringValue); } throw new IllegalArgumentException( "Unable to convert string value to desired type " + type); } throw new IllegalArgumentException("Unable to convert value to desired type " + type); } }
public static Object getProperty( Map<String, Object> config, IClientConfigKey key, Object defaultVal) { Object val = config.get(key.key()); if (val == null) { return defaultVal; } return val; }
@Override public String toString() { final StringBuilder sb = new StringBuilder(); String separator = ""; sb.append("ClientConfig:"); for (IClientConfigKey key : CommonClientConfigKey.values()) { final Object value = getProperty(key); sb.append(separator); separator = ", "; sb.append(key).append(":"); if (key.key().endsWith("Password") && value instanceof String) { sb.append(Strings.repeat("*", ((String) value).length())); } else { sb.append(value); } } return sb.toString(); }
@Override public <T> DefaultClientConfigImpl set(IClientConfigKey<T> key, T value) { properties.put(key.key(), value); return this; }
public String getInstancePropName(String restClientName, IClientConfigKey configKey) { return getInstancePropName(restClientName, configKey.key()); }
/* (non-Javadoc) * @see com.netflix.niws.client.CliengConfig#getProperty(com.netflix.niws.client.ClientConfigKey) */ @Override public Object getProperty(IClientConfigKey key) { String propName = key.key(); Object value = getProperty(propName); return value; }
/* (non-Javadoc) * @see com.netflix.niws.client.CliengConfig#setProperty(com.netflix.niws.client.ClientConfigKey, java.lang.Object) */ @Override public void setProperty(IClientConfigKey key, Object value) { setPropertyInternal(key.key(), value); }
public String getDefaultPropName(IClientConfigKey propName) { return getDefaultPropName(propName.key()); }
protected void setPropertyInternal(IClientConfigKey propName, Object value) { setPropertyInternal(propName.key(), value); }