/** * Compare these objects based on my property and ascending settings. Collections sort lower than * Resources. * * @param o1 The first object, ContentCollection or ContentResource * @param o2 The second object, ContentCollection or ContentResource * @return The compare result: -1 if o1 < o2, 0 if they are equal, and 1 if o1 > o2 */ public int compare(Object o1, Object o2) { String property = m_property; // PROP_CONTENT_PRIORITY is special because it allows // intermixing folders and files. if (property.equals(ResourceProperties.PROP_CONTENT_PRIORITY)) { Entity entity1 = (Entity) o1; Entity entity2 = (Entity) o2; String str1 = entity1.getProperties().getProperty(property); String str2 = entity2.getProperties().getProperty(property); if (str1 == null || str2 == null) { // ignore -- default to a different sort } else { try { Integer rank1 = new Integer(str1); Integer rank2 = new Integer(str2); return m_ascending ? rank1.compareTo(rank2) : rank2.compareTo(rank1); } catch (NumberFormatException e) { // ignore -- default to a different sort } } // if unable to do a priority sort, sort by title property = ResourceProperties.PROP_DISPLAY_NAME; } // collections sort lower than resources if ((o1 instanceof ContentCollection) && (o2 instanceof ContentResource)) { return (m_ascending ? -1 : 1); } if ((o1 instanceof ContentResource) && (o2 instanceof ContentCollection)) { return (m_ascending ? 1 : -1); } if (property.equals(ResourceProperties.PROP_CONTENT_LENGTH) && o1 instanceof ContentCollection) { int size1 = ((ContentCollection) o1).getMemberCount(); int size2 = ((ContentCollection) o2).getMemberCount(); int rv = ((size1 < size2) ? -1 : ((size1 > size2) ? 1 : 0)); if (!m_ascending) rv = -rv; return rv; } // ok, they are both the same: resources or collections // try a numeric interpretation try { long l1 = ((Entity) o1).getProperties().getLongProperty(property); long l2 = ((Entity) o2).getProperties().getLongProperty(property); int rv = ((l1 < l2) ? -1 : ((l1 > l2) ? 1 : 0)); if (!m_ascending) rv = -rv; return rv; } catch (Exception ignore) { } // try a Time interpretation try { Time t1 = ((Entity) o1).getProperties().getTimeProperty(property); Time t2 = ((Entity) o2).getProperties().getTimeProperty(property); int rv = t1.compareTo(t2); if (!m_ascending) rv = -rv; return rv; } catch (Exception ignore) { } // do a formatted interpretation - case insensitive if (o1 == null) return -1; if (o2 == null) return +1; int rv = 0; if (m_smart_sort) { rv = compareLikeMacFinder( ((Entity) o1).getProperties().getPropertyFormatted(property), ((Entity) o2).getProperties().getPropertyFormatted(property)); } else { rv = ((Entity) o1) .getProperties() .getPropertyFormatted(property) .compareTo(((Entity) o2).getProperties().getPropertyFormatted(property)); } return m_ascending ? rv : -rv; } // compare