/** * @return {@code true} if the property has a non-default value, else {@code false}. */ public boolean hasKey(String key) { return getRawString(key).isPresent(); }
@Override protected Optional<String> get(String key) { String value = localProperties.get(key); if (value != null) { return Optional.of(value); } return parentSettings.getRawString(key); }
public Settings appendProperty(String key, @Nullable String value) { Optional<String> existingValue = getRawString(definitions.validKey(key)); String newValue; if (!existingValue.isPresent()) { newValue = trim(value); } else { newValue = existingValue.get() + "," + trim(value); } return setProperty(key, newValue); }
/** * The effective value of the specified property. Can return * {@code null} if the property is not set and has no * defined default value. * <p> * If the property is encrypted with a secret key, * then the returned value is decrypted. * </p> * * @throws IllegalStateException if value is encrypted but fails to be decrypted. */ @CheckForNull public String getString(String key) { String effectiveKey = definitions.validKey(key); Optional<String> value = getRawString(effectiveKey); if (!value.isPresent()) { // default values cannot be encrypted, so return value as-is. return getDefaultValue(effectiveKey); } if (encryption.isEncrypted(value.get())) { try { return encryption.decrypt(value.get()); } catch (Exception e) { throw new IllegalStateException("Fail to decrypt the property " + effectiveKey + ". Please check your secret key.", e); } } return value.get(); }
/** * @return {@code true} if the property has a non-default value, else {@code false}. */ public boolean hasKey(String key) { return getRawString(key).isPresent(); }
@Override protected Optional<String> get(String key) { String value = localProperties.get(key); if (value != null) { return Optional.of(value); } return parentSettings.getRawString(key); }
public Settings appendProperty(String key, @Nullable String value) { Optional<String> existingValue = getRawString(definitions.validKey(key)); String newValue; if (!existingValue.isPresent()) { newValue = trim(value); } else { newValue = existingValue.get() + "," + trim(value); } return setProperty(key, newValue); }
/** * The effective value of the specified property. Can return * {@code null} if the property is not set and has no * defined default value. * <p> * If the property is encrypted with a secret key, * then the returned value is decrypted. * </p> * * @throws IllegalStateException if value is encrypted but fails to be decrypted. */ @CheckForNull public String getString(String key) { String effectiveKey = definitions.validKey(key); Optional<String> value = getRawString(effectiveKey); if (!value.isPresent()) { // default values cannot be encrypted, so return value as-is. return getDefaultValue(effectiveKey); } if (encryption.isEncrypted(value.get())) { try { return encryption.decrypt(value.get()); } catch (Exception e) { throw new IllegalStateException("Fail to decrypt the property " + effectiveKey + ". Please check your secret key.", e); } } return value.get(); }