mail[Wesnoth-commits] r44495 - in /trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema: SchemaParser.java Tag.java TagKey.java


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by timotei_cluj on July 21, 2010 - 20:00:
Author: timotei
Date: Wed Jul 21 20:00:20 2010
New Revision: 44495

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44495&view=rev
Log:
eclipse plugin: order tags/children by cardinality, showing first the 
required tags/keys

Modified:
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/SchemaParser.java
    trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/Tag.java
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/TagKey.java

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/SchemaParser.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/SchemaParser.java?rev=44495&r1=44494&r2=44495&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/SchemaParser.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/SchemaParser.java
 Wed Jul 21 20:00:20 2010
@@ -9,6 +9,7 @@
 package wesnoth_eclipse_plugin.schema;
 
 import java.io.File;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Stack;
 
@@ -42,7 +43,6 @@
         */
        public void parseSchema(boolean force)
        {
-               //TODO: sort tags's keys by cardinality (required first) ??
                if (parsingDone_ && !force)
                {
                        Logger.getInstance().log("schema not parsed since 
there is already in cache.");
@@ -201,29 +201,36 @@
                                }
                        }
                }
+
+               sortTags();
                Logger.getInstance().log("parsing done");
                parsingDone_ = true;
-               //
-               //              try
-               //              {
-               //                      BufferedWriter bw = new 
BufferedWriter(new PrintWriter(new 
File("D:\\timo\\gw\\data\\schema-out.cfg")));
-               //                      // print primitives
-               //                      for (Entry<String, String> primitive 
: primitives.entrySet())
-               //                      {
-               //                              bw.write(primitive.getKey() + 
": " + primitive.getValue() + "\n");
-               //                      }
-               //                      // print tags
-               //                      Tag root = tags.get("root");
-               //                      for (Tag tag : root.TagChildren)
-               //                      {
-               //                              bw.write(getOutput(tag, ""));
-               //                      }
-               //                      bw.close();
-               //              } catch (Exception e)
-               //              {
-               //                      Logger.getInstance().logException(e);
-               //              }
-               //              System.out.println("End writing result");
+       }
+
+       /**
+        * Sorts the tags in the hashmap
+        */
+       private void sortTags()
+       {
+               for(Tag tag : tags_.values())
+               {
+                       sortChildren(tag);
+               }
+       }
+
+       /**
+        * Sorts all tag's children by using the cardinality comparator
+        * @param tag
+        */
+       private void sortChildren(Tag tag)
+       {
+               Collections.sort(tag.TagChildren, new 
Tag.CardinalityComparator());
+               Collections.sort(tag.KeyChildren, new 
TagKey.CardinalityComparator());
+
+               for (Tag childTag : tag.TagChildren)
+               {
+                       sortChildren(childTag);
+               }
        }
 
        /**

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/Tag.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/Tag.java?rev=44495&r1=44494&r2=44495&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/Tag.java 
(original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/Tag.java 
Wed Jul 21 20:00:20 2010
@@ -9,6 +9,7 @@
 package wesnoth_eclipse_plugin.schema;
 
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 
 /**
@@ -30,6 +31,7 @@
                TagChildren = tagChildren;
                KeyChildren = keyChildren;
                Cardinality = cardinality;
+               safeInit();
        }
 
        public Tag(String name, char cardinality) {
@@ -38,6 +40,7 @@
                TagChildren = new ArrayList<Tag>();
                KeyChildren = new ArrayList<TagKey>();
                Cardinality = cardinality;
+               safeInit();
        }
 
        public Tag(String name, String extendedTagName, char cardinality) {
@@ -46,6 +49,15 @@
                TagChildren = new ArrayList<Tag>();
                KeyChildren = new ArrayList<TagKey>();
                Cardinality = cardinality;
+               safeInit();
+       }
+
+       private void safeInit()
+       {
+               if (TagChildren == null)
+                       TagChildren = new ArrayList<Tag>();
+               if (KeyChildren == null)
+                       KeyChildren = new ArrayList<TagKey>();
        }
 
        /**
@@ -78,4 +90,22 @@
        {
                addKey(new TagKey(name, cardinality, valueType, 
translatable));
        }
+
+       /**
+        * A tag comparator that sorts just after required cardinality.
+        */
+       public static class CardinalityComparator implements Comparator<Tag>
+       {
+               @Override
+               public int compare(Tag o1, Tag o2)
+               {
+                       if (o1.Cardinality == o2.Cardinality)
+                               return 0;
+                       if (o1.Cardinality == '1')
+                               return 1;
+                       else if (o2.Cardinality == '1')
+                               return -1;
+                       return 0;
+               }
+       }
 }

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/TagKey.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/TagKey.java?rev=44495&r1=44494&r2=44495&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/TagKey.java 
(original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/schema/TagKey.java 
Wed Jul 21 20:00:20 2010
@@ -7,6 +7,8 @@
  * http://www.eclipse.org/legal/epl-v10.html
  
*******************************************************************************/
 package wesnoth_eclipse_plugin.schema;
+
+import java.util.Comparator;
 
 /**
  * This class represents a tag's key parsed by the schema
@@ -45,4 +47,21 @@
                        IsTranslatable = trans;
                }
        }
+       /**
+        * A tag comparator that sorts just after required cardinality.
+        */
+       public static class CardinalityComparator implements 
Comparator<TagKey>
+       {
+               @Override
+               public int compare(TagKey o1, TagKey o2)
+               {
+                       if (o1.Cardinality == o2.Cardinality)
+                               return 0;
+                       if (o1.Cardinality == '1')
+                               return -1;
+                       else if (o2.Cardinality == '1')
+                               return 1;
+                       return 0;
+               }
+       }
 }




Related Messages


Powered by MHonArc, Updated Wed Jul 21 20:20:34 2010