List of usage examples for org.apache.commons.lang ObjectUtils compare
public static <T extends Comparable<? super T>> int compare(T c1, T c2)
From source file:org.openhab.binding.ebus.tools.EBusJsonConfTool.java
private void writeMarkdownIdTable(List<Map<String, ?>> configurationMap, PrintStream out) { if (configurationMap == null || configurationMap.isEmpty()) { return;// w w w.ja v a 2 s . c o m } List<List<String>> table = createTelegramIdTable(configurationMap); // set sort order by column number final int sortColumns[] = new int[] { 1, 0 }; Collections.sort(table, new Comparator<List<String>>() { @Override public int compare(List<String> line1, List<String> line2) { int compareTo = 0; for (int i : sortColumns) { compareTo = ObjectUtils.compare(line1.get(i), line2.get(i)); if (compareTo != 0) { return compareTo; } } return compareTo; } }); // Add headers ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("ID"); // arrayList.add("Class"); // arrayList.add("Command"); arrayList.add("Item type"); arrayList.add("Description"); table.add(0, arrayList); // Add Markdown header delimiters arrayList = new ArrayList<String>(); for (int i = 0; i < table.get(0).size(); i++) { arrayList.add("---"); } table.add(1, arrayList); // compute max colum width int columnWidth[] = new int[arrayList.size()]; for (List<String> column : table) { for (int i = 0; i < column.size(); i++) { String elm = column.get(i); if (elm != null && elm.length() > columnWidth[i]) { columnWidth[i] = elm.length(); } } } for (List<String> column : table) { for (int i = 0; i < column.size(); i++) { String elm = column.get(i); out.print(String.format("%-" + columnWidth[i] + "s", elm)); if (i < column.size() - 1) { out.print(" | "); } } // line end out.print("\n"); } }
From source file:org.sakaiproject.scorm.entity.ScormEntity.java
@Override public int compareTo(ScormEntity entity) { return ObjectUtils.compare(entity.getID(), this.getID()); }
From source file:org.sakaiproject.scorm.model.api.comparator.LearnerExperienceComparator.java
@Override public int compare(LearnerExperience le1, LearnerExperience le2) { // Perform different comparison depending on which comparison type has been selected switch (compType) { case Learner: { return le1.getLearnerName().compareTo(le2.getLearnerName()); }/*from ww w . ja v a 2s . co m*/ case AttemptDate: { return ObjectUtils.compare(le1.getLastAttemptDate(), le2.getLastAttemptDate()); } case Status: { return Integer.compare(le1.getStatus(), le2.getStatus()); } case NumberOfAttempts: { return Integer.compare(le1.getNumberOfAttempts(), le2.getNumberOfAttempts()); } } return 0; }