[jbosstools-commits] JBoss Tools SVN: r35919 - in trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common: meta/impl and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Oct 21 20:41:10 EDT 2011


Author: scabanovich
Date: 2011-10-21 20:41:10 -0400 (Fri, 21 Oct 2011)
New Revision: 35919

Modified:
   trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/XModelEntity.java
   trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XChildrenImpl.java
   trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XModelEntityImpl.java
   trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/XModelObjectLoaderUtil.java
Log:
JBIDE-9917
https://issues.jboss.org/browse/JBIDE-9917
XModelEntityImpl.getRequiredChildren() is reimplemented.

Modified: trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/XModelEntity.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/XModelEntity.java	2011-10-22 00:29:49 UTC (rev 35918)
+++ trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/XModelEntity.java	2011-10-22 00:41:10 UTC (rev 35919)
@@ -10,6 +10,8 @@
  ******************************************************************************/ 
 package org.jboss.tools.common.meta;
 
+import java.util.Set;
+
 import org.jboss.tools.common.meta.action.XActionList;
 import org.jboss.tools.common.model.XModelObject;
 import org.jboss.tools.common.model.loaders.XObjectLoader;
@@ -46,7 +48,7 @@
     public int getPropertyIndex(String name, boolean register);
     public int getPropertyCount();
     public String getChildByXML(String xmlname);
-    public java.util.HashSet<String> getRequiredChildren();
+    public Set<String> getRequiredChildren();
     
     public String testImplementation();
     public String testLoader();

Modified: trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XChildrenImpl.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XChildrenImpl.java	2011-10-22 00:29:49 UTC (rev 35918)
+++ trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XChildrenImpl.java	2011-10-22 00:41:10 UTC (rev 35919)
@@ -11,12 +11,14 @@
 package org.jboss.tools.common.meta.impl;
 
 import java.util.*;
+
 import org.w3c.dom.*;
 import org.jboss.tools.common.meta.*;
 
 public class XChildrenImpl implements XMetaDataConstants {
     protected XChild[] children = new XChild[0];
     protected HashMap<String,XChild> children_map = new HashMap<String,XChild>(10);
+    private Set<String> requiredChildren = new HashSet<String>();
 
     public XChildrenImpl() {}
 
@@ -28,6 +30,15 @@
         return children;
     }
 
+    /**
+     * Returns copy of set with names of required child entities.
+     *  
+     * @return
+     */
+    public Set<String> getRequiredChildren() {
+    	return (requiredChildren.isEmpty()) ? Collections.<String>emptySet() : new HashSet<String>(requiredChildren);
+    }
+
     public void load(Element el) {
         Element p = XMetaDataLoader.getUniqueChild(el, XMODEL_CHILDREN);
         if(p == null) return;
@@ -38,6 +49,9 @@
             m.load(es[i]);
             children_map.put(m.getName(), m);
             c.add(m);
+            if(m.getMaxCount() == 1 && m.isRequired()) {
+            	requiredChildren.add(m.getName());
+            }
         }
         children = c.toArray(new XChild[0]);
     }

Modified: trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XModelEntityImpl.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XModelEntityImpl.java	2011-10-22 00:29:49 UTC (rev 35918)
+++ trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XModelEntityImpl.java	2011-10-22 00:41:10 UTC (rev 35919)
@@ -372,24 +372,10 @@
         return xmlmap.getProperty(xmlname);
     }
 
-    private HashSet<String> requiredchildren = null;
-    private boolean requiredloaded = false;
-
-    public java.util.HashSet<String> getRequiredChildren() {
-        if(!requiredloaded) {
-            XChild[] cs = children.getChildren();
-            requiredchildren = new HashSet<String>(cs.length);
-            for (int i = 0; i < cs.length; i++) {
-                boolean required = (cs[i].getMaxCount() == 1 && cs[i].isRequired());
-                if(required) requiredchildren.add(cs[i].getName());
-            }
-            if(requiredchildren.size() == 0) requiredchildren = null;
-            requiredloaded = true;
-        }
-        return (requiredchildren == null) ? null : (HashSet<String>)requiredchildren.clone();
+    public Set<String> getRequiredChildren() {
+        return children.getRequiredChildren();
     }
     
-    
     /**
      * FIXME Move to ModelTest plugin
      */

Modified: trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/XModelObjectLoaderUtil.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/XModelObjectLoaderUtil.java	2011-10-22 00:29:49 UTC (rev 35918)
+++ trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/XModelObjectLoaderUtil.java	2011-10-22 00:41:10 UTC (rev 35919)
@@ -306,7 +306,7 @@
     public void loadChildren(Element element, XModelObject o) {
         XModelEntity entity = o.getModelEntity();
         XModel model = o.getModel();
-        HashSet<String> childset = entity.getRequiredChildren();
+        Set<String> childset = entity.getRequiredChildren();
         NodeList nl = element.getChildNodes();
         for (int i = 0; i < nl.getLength(); i++) {
             Node n = nl.item(i);
@@ -351,12 +351,14 @@
             	}
             	continue;
             } 
-            if(childset != null) childset.remove(en);
+            if(childset.contains(en)) {
+            	childset.remove(en);
+            }
         }
-        if(childset != null && childset.size() > 0) {
-            String[] ens = childset.toArray(new String[childset.size()]);
-            for (int i = 0; i < ens.length; i++)
-              o.addChild(createValidObject(model, ens[i]));
+        if(!childset.isEmpty()) { //in most cases the set is empty and this check is faster than creating an iterator.
+            for (String en: childset) {
+                o.addChild(createValidObject(model, en));
+            }
         }
     }
     



More information about the jbosstools-commits mailing list