[ 
https://issues.apache.org/jira/browse/SLING-7752?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16520247#comment-16520247
 ] 

ASF GitHub Bot commented on SLING-7752:
---------------------------------------

andreituicu commented on a change in pull request #2: SLING-7752 - 
Deserializing and serializing a feature model file suffles the configurations
URL: 
https://github.com/apache/sling-org-apache-sling-feature/pull/2#discussion_r197412875
 
 

 ##########
 File path: src/main/java/org/apache/sling/feature/impl/OrderedDictionary.java
 ##########
 @@ -0,0 +1,137 @@
+/*
+ * 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.sling.feature.impl;
+
+import java.util.*;
+
+/**
+ * A dictionary implementation with predictable iteration order.
+ *
+ * Actually this class is a simple adapter from the Dictionary interface
+ * to a synchronized LinkedHashMap
+ *
+ * @param <K>
+ * @param <V>
+ */
+public class OrderedDictionary<K, V> extends Dictionary<K, V> implements 
Map<K, V> {
+    private static class EnumarationImpl<E> implements Enumeration<E> {
+        private final Iterator<E> iterator;
+
+        public EnumarationImpl(Iterator<E> iterator) {
+            this.iterator = iterator;
+        }
+
+        @Override
+        public boolean hasMoreElements() {
+            return iterator.hasNext();
+        }
+
+        @Override
+        public E nextElement() {
+            return iterator.next();
+        }
+    }
+
+    private Map map = Collections.synchronizedMap(new LinkedHashMap());
 
 Review comment:
   @rombert Looking at the code of SynchronizedMap, Hashtable and 
LinkedHashMap, it seems to me that the implementation has the same problems 
with the iterators as the Hashtable too, so the two implementations are 
equivalent in that regard, just that the Synchronized Map gives you the 
warning, while the Hashtable lets you figure that out for your self. I think it 
is the case for almost all collection implementations that Java offers. I could 
also add the warning to the Javadoc. Do you think we should do more than that 
or do you have a different recommendation?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


> Deserializing and serializing a feature model file suffles the configurations
> -----------------------------------------------------------------------------
>
>                 Key: SLING-7752
>                 URL: https://issues.apache.org/jira/browse/SLING-7752
>             Project: Sling
>          Issue Type: Bug
>          Components: Feature Model
>            Reporter: Andrei Tuicu
>            Priority: Major
>
> h3. Problem
> Deserializing and serializing a feature model file suffles the 
> configurations. This happens, because unordered maps (HashMaps/Hashtables) 
> are used in the implementations. The problem is relevant in the context of 
> adding these files in code versioning systems, because a minor change to a 
> file, done in an automated fashion, produces a big diff in the versioning 
> system and it becomes very hard to see exactly what is the relevant change. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to