Changeset 4330
- Timestamp:
- 2003-05-26T16:00:05+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/msm/MSMUtils.java
r4293 r4330 52 52 * @version 2.3 53 53 **************************************************************************************/ 54 import java.io.BufferedReader; 55 import java.io.File; 56 import java.io.FileInputStream; 57 import java.io.FileReader; 58 import java.io.InputStream; 59 import java.util.ArrayList; 60 import java.util.Collections; 61 import java.util.Enumeration; 62 import java.util.Hashtable; 63 import java.util.Locale; 64 import java.util.TreeSet; 65 import java.util.Vector; 54 import java.io.*; 55 import java.util.*; 56 import org.greenstone.gatherer.Gatherer; 66 57 import org.greenstone.gatherer.cdm.CommandTokenizer; 67 58 import org.greenstone.gatherer.mem.Attribute; … … 70 61 import org.greenstone.gatherer.util.Utility; 71 62 import org.greenstone.gatherer.valuetree.GValueModel; 72 import org.w3c.dom.Attr; 73 import org.w3c.dom.Document; 74 import org.w3c.dom.Element; 75 import org.w3c.dom.NamedNodeMap; 76 import org.w3c.dom.Node; 63 import org.w3c.dom.*; 77 64 /** This class contains a plethora of methods associated with handling the content of <strong>MetadataSet</strong>s and the <strong>Element</strong>s within. For example this is where you will find methods for comparing various parts of two <strong>MetadataSet</strong>s for equality. It also has methods for extracting common and useful data from <strong>Element</strong>s such as the AssignedValue nodes. 78 65 * @author John Thompson, Greenstone Digital Libraries … … 80 67 */ 81 68 public class MSMUtils { 69 /** Used to order metadata according to set standard element order then alphabetically by value. */ 70 static public MetadataComparator METADATA_COMPARATOR = new MetadataComparator(); 82 71 /** An element of the enumeration of type filter. */ 83 72 static public final int NONE = 0; … … 849 838 return false; 850 839 } 840 841 /** A comparator for sorting metadata element-value pairs into their standard order (elements) then alphabetical order (values). */ 842 static final private class MetadataComparator 843 implements Comparator { 844 /** Compares its two arguments for order. */ 845 public int compare(Object o1, Object o2) { 846 int result = 0; 847 Metadata m1 = (Metadata) o1; 848 Metadata m2 = (Metadata) o2; 849 ///ystem.err.println("MSMUtils.compare(" + m1 + ", " + m2 + ") = "); 850 ElementWrapper e1 = m1.getElement(); 851 ElementWrapper e2 = m2.getElement(); 852 // First we compare the namespaces 853 result = e1.getNamespace().compareTo(e2.getNamespace()); 854 if(result == 0) { 855 // Now, given both elements are in the same set, we compare the element ordering using methods in MetadataSet 856 MetadataSet set = Gatherer.c_man.getCollection().msm.getSet(e1.getNamespace()); 857 ///ystem.err.print("MetadataSet.compare(" + e1 + ", " + e2 + ") = "); 858 result = set.compare(e1.getElement(), e2.getElement()); 859 ///ystem.err.println(result); 860 if(result == 0) { 861 // Finally we compare the values alphabetically. 862 result = m1.getValue().compareTo(m2.getValue()); 863 } 864 } 865 ///ystem.err.println("Result: " + result); 866 return result; 867 } 868 869 /** Indicates whether some other object is "equal to" this Comparator. */ 870 public boolean equals(Object obj) { 871 return compare(this, obj) == 0; 872 } 873 } 851 874 }
Note:
See TracChangeset
for help on using the changeset viewer.