ibessonov commented on a change in pull request #208:
URL: https://github.com/apache/ignite-3/pull/208#discussion_r670488661



##########
File path: 
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/util/OrderedMap.java
##########
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.configuration.util;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Simplified map interfaces with better control over the keys order.
+ *
+ * @param <V> Type of the value.
+ */
+public class OrderedMap<V> {
+    /** Underlying hash map. */
+    private final Map<String, V> map = new HashMap<>();
+
+    /** Ordered keys. */
+    private final List<String> orderedKeys = new ArrayList<>();
+
+    /** Default constructor. */
+    public OrderedMap() {
+    }
+
+    /**
+     * Copy constructor.
+     *
+     * @param other Source of keys/values to copy from.
+     */
+    public OrderedMap(OrderedMap<V> other) {
+        map.putAll(other.map);
+        orderedKeys.addAll(other.orderedKeys);
+    }
+
+    /**
+     * Same as {@link Map#containsKey(Object)}.
+     *
+     * @param key Key to check.
+     * @return {@code true} if map contains the key.
+     */
+    public boolean containsKey(String key) {
+        return map.containsKey(key);
+    }
+
+    /**
+     * Same as {@link Map#get(Object)}.
+     *
+     * @param key Key to search.
+     * @return Value assiciated with the key or {@code null} is it's not found.
+     */
+    public V get(String key) {
+        return map.get(key);
+    }
+
+    /**
+     * Same as {@link Map#remove(Object)}.
+     *
+     * @param key Key to remove.
+     * @return Provious value assiciated with the key or {@code null} if map 
had no such key.
+     */
+    public V remove(String key) {
+        if (map.containsKey(key))
+            orderedKeys.remove(key);
+
+        return map.remove(key);
+    }
+
+    /**
+     * Put value to the map. Key will be the last if it didn't exist in map 
before. If key did exist then the same
+     * ordering index will be used.
+     *
+     * @param key Key to put.
+     * @param value Value associated with the key.
+     */
+    public void put(String key, V value) {

Review comment:
       We don't need that result so why bothering




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