ctubbsii commented on a change in pull request #1701:
URL: https://github.com/apache/accumulo/pull/1701#discussion_r484119541
##########
File path:
server/base/src/main/java/org/apache/accumulo/server/ServiceEnvironmentImpl.java
##########
@@ -78,6 +79,22 @@ public String get(String key) {
}
}
+ @Override
+ public Map<String,String> getWithPrefix(String prefix) {
+ if (Property.isValidPropertyPrefix(prefix)) {
+ Property propertyPrefix = Property.getPropertyByKey(prefix);
+ return acfg.getAllPropertiesWithPrefix(propertyPrefix);
+ } else {
+ Map<String,String> properties = new HashMap<>();
+ for (Entry<String,String> prop : acfg) {
+ if (prop.getKey().startsWith(prefix)) {
+ properties.put(prop.getKey(), prop.getValue());
+ }
+ }
+ return properties;
+ }
Review comment:
This can be more succinctly written with streams:
```suggestion
return StreamSupport.stream(acfg.spliterator(), false)
.filter(prop -> prop.getKey().startsWith(prefix))
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
```
##########
File path:
server/base/src/main/java/org/apache/accumulo/server/ServiceEnvironmentImpl.java
##########
@@ -78,6 +79,22 @@ public String get(String key) {
}
}
+ @Override
+ public Map<String,String> getWithPrefix(String prefix) {
+ if (Property.isValidPropertyPrefix(prefix)) {
+ Property propertyPrefix = Property.getPropertyByKey(prefix);
Review comment:
This check for valid prefix property can be avoided, by checking the
returned object from `Property.getPropertyByKey(prefix)`:
```suggestion
Property propertyPrefix = Property.getPropertyByKey(prefix);
if (propertyPrefix != null && propertyPrefix.getType() ==
PropertyType.PREFIX) {
```
##########
File path: core/src/main/java/org/apache/accumulo/core/conf/Property.java
##########
@@ -1233,6 +1233,18 @@ public static boolean isValidPropertyKey(String key) {
return validProperties.contains(key) || isKeyValidlyPrefixed(key);
}
+ /**
+ * Checks if the given property prefix is valid. A valid property prefix is
equal to some prefix
+ * defined in this class.
+ *
+ * @param prefix
+ * property prefix
+ * @return true if prefix is valid (recognized)
+ */
+ public static boolean isValidPropertyPrefix(String prefix) {
+ return validPrefixes.contains(prefix);
+ }
+
Review comment:
This method isn't necessary, since this loop can be avoided.
```suggestion
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]