ctubbsii commented on code in PR #2695:
URL: https://github.com/apache/accumulo/pull/2695#discussion_r872509188


##########
core/src/main/java/org/apache/accumulo/core/conf/Property.java:
##########
@@ -1828,24 +1785,24 @@ public static <T> T 
createInstanceFromPropertyName(AccumuloConfiguration conf, P
     // Precomputing information here avoids :
     // * Computing it each time a method is called
     // * Using synch to compute the first time a method is called
-    for (Property p : Property.values()) {
-      propertiesByKey.put(p.getKey(), p);
-      if (p.getType().equals(PropertyType.PREFIX)) {
-        validPrefixes.add(p.getKey());
-      } else {
-        validProperties.add(p.getKey());
-      }
-      // exclude prefix types (prevents setting a prefix type like 
table.custom or
-      // table.constraint, directly, since they aren't valid properties on 
their own)
-      if (!p.getType().equals(PropertyType.PREFIX)
-          && p.getKey().startsWith(Property.TABLE_PREFIX.getKey())) {
-        validTableProperties.add(p.getKey());
-      }
-    }
+    Predicate<Property> isPrefix = p -> p.getType() == PropertyType.PREFIX;
+    Arrays.stream(Property.values())
+        // record all properties by key
+        .peek(p -> propertiesByKey.put(p.getKey(), p))
+        // save all the prefix properties
+        .peek(p -> {
+          if (isPrefix.test(p))
+            validPrefixes.add(p.getKey());
+        })
+        // only use the keys for the non-prefix properties from here on
+        .filter(isPrefix.negate()).map(Property::getKey)
+        // everything left is a valid property
+        .peek(validProperties::add)
+        // but some are also valid table properties
+        .filter(k -> k.startsWith(Property.TABLE_PREFIX.getKey()))
+        .forEach(validTableProperties::add);

Review Comment:
   Yeah, I debated with myself on this one. But I preferred the stream because 
I was able to structure it in this nice linear workflow, with comments, without 
the need to add some conditional checks to filter out table property prefixes.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to