1
0

[HUDI-1254] TypedProperties can not get values by initializing an existing properties (#2059)

This commit is contained in:
linshan-ma
2020-09-09 23:42:41 +08:00
committed by GitHub
parent fec7cd3c97
commit 063a98fc2b
2 changed files with 100 additions and 7 deletions

View File

@@ -22,6 +22,7 @@ import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -38,22 +39,30 @@ public class TypedProperties extends Properties implements Serializable {
}
private void checkKey(String property) {
if (!containsKey(property)) {
if (!keyExists(property)) {
throw new IllegalArgumentException("Property " + property + " not found");
}
}
private boolean keyExists(String property) {
Set<String> keys = super.stringPropertyNames();
if (keys.contains(property)) {
return true;
}
return false;
}
public String getString(String property) {
checkKey(property);
return getProperty(property);
}
public String getString(String property, String defaultValue) {
return containsKey(property) ? getProperty(property) : defaultValue;
return keyExists(property) ? getProperty(property) : defaultValue;
}
public List<String> getStringList(String property, String delimiter, List<String> defaultVal) {
if (!containsKey(property)) {
if (!keyExists(property)) {
return defaultVal;
}
return Arrays.stream(getProperty(property).split(delimiter)).map(String::trim).collect(Collectors.toList());
@@ -65,7 +74,7 @@ public class TypedProperties extends Properties implements Serializable {
}
public int getInteger(String property, int defaultValue) {
return containsKey(property) ? Integer.parseInt(getProperty(property)) : defaultValue;
return keyExists(property) ? Integer.parseInt(getProperty(property)) : defaultValue;
}
public long getLong(String property) {
@@ -74,7 +83,7 @@ public class TypedProperties extends Properties implements Serializable {
}
public long getLong(String property, long defaultValue) {
return containsKey(property) ? Long.parseLong(getProperty(property)) : defaultValue;
return keyExists(property) ? Long.parseLong(getProperty(property)) : defaultValue;
}
public boolean getBoolean(String property) {
@@ -83,7 +92,7 @@ public class TypedProperties extends Properties implements Serializable {
}
public boolean getBoolean(String property, boolean defaultValue) {
return containsKey(property) ? Boolean.parseBoolean(getProperty(property)) : defaultValue;
return keyExists(property) ? Boolean.parseBoolean(getProperty(property)) : defaultValue;
}
public double getDouble(String property) {
@@ -92,6 +101,6 @@ public class TypedProperties extends Properties implements Serializable {
}
public double getDouble(String property, double defaultValue) {
return containsKey(property) ? Double.parseDouble(getProperty(property)) : defaultValue;
return keyExists(property) ? Double.parseDouble(getProperty(property)) : defaultValue;
}
}