Added a way to get an optional version of a property
Includes a StringUtils.isBlank() check
*/
package com.blackducksoftware.integration.hub.detect.configuration;
-import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -70,7 +69,7 @@ public class DetectConfiguration {
private void handleStandardProperty(final DetectProperty currentProperty) {
actuallySetValues.add(currentProperty);
- String value = detectPropertySource.getDetectProperty(currentProperty.getPropertyName(), currentProperty.getDefaultValue());
+ final String value = detectPropertySource.getDetectProperty(currentProperty.getPropertyName(), currentProperty.getDefaultValue());
detectPropertyMap.setDetectProperty(currentProperty, value);
}
@@ -177,6 +176,19 @@ public class DetectConfiguration {
return detectPropertyMap.getProperty(detectProperty);
}
+ /**
+ * Same as <code>getProperty()</code>, but returns an optional after performing a <code>StringUtils.isBlank()</code> check
+ */
+ public Optional<String> getOptionalProperty(final DetectProperty detectProperty) {
+ final String property = getProperty(detectProperty);
+ Optional<String> optionalProperty = Optional.empty();
+ if (StringUtils.isNotBlank(property)) {
+ optionalProperty = Optional.of(property);
+ }
+
+ return optionalProperty;
+ }
+
public String getPropertyValueAsString(final DetectProperty detectProperty) {
return detectPropertyMap.getPropertyValueAsString(detectProperty);
}
