int (Element e1, Element e2) { if (sort == 0) { return 0; } String name1 = getElementNameNoLeadingUnderscore(e1); String name2 = getElementNameNoLeadingUnderscore(e2); int res = name1.compareToIgnoreCase(name2); if (sort == 2) { res = -1 * res; // flip result if desc } return res; }