From: kruland2607 Date: Fri, 4 May 2012 20:08:47 +0000 (+0000) Subject: Sort the collections prior to serialization since that makes the output a little... X-Git-Tag: upstream/12.09^2~302 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=a815239d7261f7aff342e4513606766a19ddcd4a;p=debian%2Fopenrocket Sort the collections prior to serialization since that makes the output a little easier to search. git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@644 180e2498-e6e9-4542-8430-84ac67f01cd8 --- diff --git a/core/src/net/sf/openrocket/preset/xml/OpenRocketComponentSaver.java b/core/src/net/sf/openrocket/preset/xml/OpenRocketComponentSaver.java index f3452ed4..708a1e09 100644 --- a/core/src/net/sf/openrocket/preset/xml/OpenRocketComponentSaver.java +++ b/core/src/net/sf/openrocket/preset/xml/OpenRocketComponentSaver.java @@ -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() { + + @Override + public int compare(Material o1, Material o2) { + return o1.getName().compareTo( o2.getName() ); + } + + }); + + Collections.sort(thePresetList, new Comparator() { + + @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();