Changeset 4564 for trunk/gli


Ignore:
Timestamp:
2003-06-11T13:50:52+12:00 (21 years ago)
Author:
jmt12
Message:

2030118: Extended the MetadataComparator to allow it to correctly sort ElementWrapper lists. This is then used to sort the columns in the MetaAudit viewby the natural ordering.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/msm/MSMUtils.java

    r4503 r4564  
    867867    public int compare(Object o1, Object o2) {
    868868        int result = 0;
    869         Metadata m1 = (Metadata) o1;
    870         Metadata m2 = (Metadata) o2;
    871         ///ystem.err.println("MSMUtils.compare(" + m1 + ", " + m2 + ") = ");
    872         ElementWrapper e1 = m1.getElement();
    873         ElementWrapper e2 = m2.getElement();
    874         // First we compare the namespaces
    875         result = e1.getNamespace().compareTo(e2.getNamespace());
    876         if(result == 0 && Gatherer.c_man != null && Gatherer.c_man.ready() && e1.getNamespace() != null) {
    877         // Now, given both elements are in the same set, we compare the element ordering using methods in MetadataSet
    878         MetadataSet set = Gatherer.c_man.getCollection().msm.getSet(e1.getNamespace());
    879         ///ystem.err.print("MetadataSet.compare(" + e1 + ", " + e2 + ") = ");
    880         result = set.compare(e1.getElement(), e2.getElement());
    881         ///ystem.err.println(result);
    882         if(result == 0) {
    883             // Finally we compare the values alphabetically.
    884             result = m1.getValue().toLowerCase().compareTo(m2.getValue().toLowerCase());
    885         }
    886         }
    887                 ///ystem.err.println("Result: " + result);
     869        ElementWrapper e1 = null;
     870        ElementWrapper e2 = null;
     871        String v1 = null;
     872        String v2 = null;
     873        if(o1 instanceof Metadata && o2 instanceof Metadata) {
     874        Metadata m1 = (Metadata) o1;
     875        Metadata m2 = (Metadata) o2;
     876        ///ystem.err.println("MSMUtils.compare(" + m1 + ", " + m2 + ") = ");
     877        e1 = m1.getElement();
     878        e2 = m2.getElement();
     879        v1 = m1.getValue().toLowerCase();
     880        v2 = m2.getValue().toLowerCase();
     881        }
     882        else if(o1 instanceof ElementWrapper && o2 instanceof ElementWrapper) {
     883        e1 = (ElementWrapper) o1;
     884        e2 = (ElementWrapper) o2;
     885        }
     886        if(e1 != null && e2 != null) {
     887        // First we compare the namespaces
     888        result = e1.getNamespace().compareTo(e2.getNamespace());
     889        if(result == 0 && Gatherer.c_man != null && Gatherer.c_man.ready() && e1.getNamespace() != null) {
     890            // Now, given both elements are in the same set, we compare the element ordering using methods in MetadataSet
     891            MetadataSet set = Gatherer.c_man.getCollection().msm.getSet(e1.getNamespace());
     892            ///ystem.err.print("MetadataSet.compare(" + e1 + ", " + e2 + ") = ");
     893            result = set.compare(e1.getElement(), e2.getElement());
     894            ///ystem.err.println(result);
     895            if(result == 0 && v1 != null && v2 != null) {
     896            // Finally we compare the values alphabetically.
     897            result = v1.compareTo(v2);
     898            }
     899        }
     900        }
     901        else {
     902        result = o1.toString().compareTo(o2.toString());
     903        }
     904        ///ystem.err.println("Result: " + result);
    888905        return result;
    889906    }
Note: See TracChangeset for help on using the changeset viewer.