ibessonov commented on a change in pull request #244:
URL: https://github.com/apache/ignite-3/pull/244#discussion_r678342688
##########
File path:
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/tree/NamedListNode.java
##########
@@ -156,18 +164,44 @@ private NamedListNode(NamedListNode<N> node) {
if (map.containsKey(key) && map.get(key) == null)
throw new IllegalArgumentException("You can't create entity that
has just been deleted [key=" + key + ']');
- N val = map.get(key);
+ IgniteBiTuple<String, N> pair = map.get(key);
- if (val == null)
- map.put(key, val = valSupplier.get());
- else
- map.put(key, val = (N)val.copy());
+ pair = pair == null
+ ? new IgniteBiTuple<>(newId(), valSupplier.get())
+ : new IgniteBiTuple<>(pair.getKey(), (N)pair.getValue().copy());
- valConsumer.accept(val);
+ map.put(key, pair);
+
+ valConsumer.accept(pair.getValue());
return this;
}
+ /** {@inheritDoc} */
+ @Override public NamedListChange<N> rename(String oldKey, String newKey) {
+ Objects.requireNonNull(oldKey, "oldKey");
+ Objects.requireNonNull(newKey, "newKey");
+
+ if (!map.containsKey(oldKey))
+ throw new IllegalArgumentException("Element with name " + oldKey +
" does not exist.");
+
+ if (map.get(oldKey) == null) {
+ throw new IllegalArgumentException(
+ "You can't rename entity that has just been deleted [key=" +
oldKey + ']'
+ );
+ }
+
+ checkNewKey(newKey);
+
+ map.rename(oldKey, newKey);
+
+ return this;
+ }
+
+ private static String newId() {
Review comment:
Inlined
--
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]