]> git.gag.com Git - debian/openrocket/commitdiff
Sort the collections prior to serialization since that makes the output a little...
authorkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Fri, 4 May 2012 20:08:47 +0000 (20:08 +0000)
committerkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Fri, 4 May 2012 20:08:47 +0000 (20:08 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@644 180e2498-e6e9-4542-8430-84ac67f01cd8

core/src/net/sf/openrocket/preset/xml/OpenRocketComponentSaver.java

index f3452ed46c1c4f772fb4e3a2500ab1269e7deec2..708a1e093cd037b91002dbcba686c54ef966013f 100644 (file)
@@ -1,22 +1,25 @@
 package net.sf.openrocket.preset.xml;
 
-import net.sf.openrocket.material.Material;
-import net.sf.openrocket.preset.ComponentPreset;
-import net.sf.openrocket.preset.InvalidComponentPresetException;
-import net.sf.openrocket.startup.Application;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
 import java.io.BufferedWriter;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.StringWriter;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+import net.sf.openrocket.material.Material;
+import net.sf.openrocket.preset.ComponentPreset;
+import net.sf.openrocket.preset.InvalidComponentPresetException;
+import net.sf.openrocket.startup.Application;
+
 /**
  * The active manager class that is the entry point for reading and writing *.orc files.
  */
@@ -53,6 +56,32 @@ public class OpenRocketComponentSaver {
         marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
         StringWriter sw = new StringWriter();
 
+        // We're going to sort the initial data since that makes the output much easier on the eyes.
+        
+        Collections.sort(theMaterialList, new Comparator<Material>() {
+
+                       @Override
+                       public int compare(Material o1, Material o2) {
+                               return o1.getName().compareTo( o2.getName() );
+                       }
+               
+        });
+        
+        Collections.sort(thePresetList, new Comparator<ComponentPreset>() {
+
+                       @Override
+                       public int compare(ComponentPreset o1, ComponentPreset o2) {
+                               int manucmp = o1.getManufacturer().getSimpleName().compareTo( o2.getManufacturer().getSimpleName() );
+                               
+                               if ( manucmp != 0 ) {
+                                       return manucmp;
+                               }
+                               
+                               return o1.getPartNo().compareTo( o2.getPartNo());
+                       }
+               
+        });
+        
         marshaller.marshal(toOpenRocketComponentDTO(theMaterialList, thePresetList), sw);
         return sw.toString();