package com.bluedragontavern; import org.jdom.Element; /** * A holder for an Element which implements Comparable for sorting */ public class SortElementsByName implements Comparable { Element element = null; /** * Constructor */ public SortElementsByName(Element element) { this.element = element; } /** * Compare mehtod inherited from Comparable */ public int compareTo(Object o) { try { //Always put albums ahead of songs for songs that are not associated with an album if (element.getName().equals("Song") && ((SortElementsByName)o).element.getName().equals("Album")) return 1; return element.getAttributeValue("name").compareTo(((SortElementsByName)o).element.getAttributeValue("name")); } catch(Exception ex) { return 0; } } /** * Return the Element that this sort wrapper contains */ public Element getElement() { return element; } }