Sort the collections prior to serialization since that makes the output a little easier to search.

This commit is contained in:
Kevin Ruland 2012-05-04 20:08:47 +00:00
parent 9661b47562
commit 4eea3292b6

View 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();