leventov commented on a change in pull request #8157: Enum of ResponseContext keys URL: https://github.com/apache/incubator-druid/pull/8157#discussion_r309830904
########## File path: processing/src/main/java/org/apache/druid/query/context/ResponseContext.java ########## @@ -155,47 +159,60 @@ CPU_CONSUMED_NANOS( "cpuConsumed", (oldValue, newValue) -> (long) oldValue + (long) newValue + ), + /** + * Indicates if a {@link ResponseContext} was truncated during serialization. + */ + TRUNCATED( + "truncated", + (oldValue, newValue) -> (boolean) oldValue || (boolean) newValue ); /** * TreeMap is used to have the natural ordering of its keys */ - private static Map<String, BaseKey> map = new TreeMap<>(); + private static final Map<String, BaseKey> registeredKeys = new TreeMap<>(); static { for (BaseKey key : values()) { - addKey(key); + registerKey(key); } } /** - * The primary way of registering context keys. - * Only the keys registered this way are considered during the context merge. + * Primary way of registering context keys. + * @throws IllegalArgumentException if the key has already been registered. */ - public static void addKey(BaseKey key) + public static void registerKey(BaseKey key) { - Preconditions.checkState( - !map.containsKey(key.getName()), - "ResponseContext keys already has the key with [%s] name", + Preconditions.checkArgument( + !registeredKeys.containsKey(key.getName()), + "Key [%s] has already been registered as a context key", key.getName() ); - map.put(key.getName(), key); + registeredKeys.put(key.getName(), key); } /** - * Returns a key associated with the name if the key was added via addKey method + * Returns a registered key associated with the name {@param name}. + * @throws IllegalStateException if a corresponding key has not been registered. */ public static BaseKey keyOf(String name) { - return map.get(name); + Preconditions.checkState( + registeredKeys.containsKey(name), + "Key [%s] has not yet been registered as a context key", + name + ); + return registeredKeys.get(name); } /** - * Returns all keys the enum contains and the added via addKey method + * Returns all keys registered via {@link Key#registerKey}. */ - public static Collection<BaseKey> getKeys() + public static Collection<BaseKey> getAllRegisteredKeys() { - return map.values(); + return registeredKeys.values(); Review comment: Just in case, please wrap with `Collections.unmodifiableCollection()` ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org