Changeset 4366 for trunk/gli/src/org/greenstone/gatherer/cdm/Index.java
- Timestamp:
- 2003-05-27T15:57:37+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/Index.java
r4293 r4366 57 57 import org.w3c.dom.Element; 58 58 /** This class encapsulates a single indexing pair. 59 * @author John Thompson, Greenstone Digital Library, University of Waikato60 * @version 2.261 */59 * @author John Thompson, Greenstone Digital Library, University of Waikato 60 * @version 2.2 61 */ 62 62 public class Index 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 63 implements Comparable { 64 /** A refernce to the main manager for access to other sub-managers. */ 65 private CollectionDesignManager manager = null; 66 /** The level of this index. */ 67 private int level = 0; 68 /** The sources for data this index is built apon, which are either fully qualified metadata element names or 'text'. */ 69 private Vector sources = null; 70 /** An element in the index level enumeration. */ 71 static public final int DOCUMENT = 0; 72 /** An element in the index level enumeration. */ 73 static public final int PARAGRAPH = 1; 74 /** An element in the index level enumeration. */ 75 static public final int SECTION = 2; 76 /** An values of items in the index level enumeration. */ 77 static public final String LEVEL[] = {"document","paragraph","section"}; 78 /** Constructor. 79 * @param level The level of this index as a <strong>String</string>. 80 * @param metadata The fully qualified name of the metadata this index is built on as a <strong>String</strong>, or <i>null</i> in which case the data defaults to "text". 81 */ 82 public Index(int level, Vector sources, CollectionDesignManager manager) { 83 this.level = level; 84 this.manager = manager; 85 this.sources = sources; 86 if(this.sources == null) { 87 this.sources = new Vector(); 88 this.sources.add("text"); 89 } 90 } 91 /** Method to compare two indexes. 92 92 * @param object The other index as an <strong>Object</strong>. 93 93 * @return An <i>int</i> which indicates how the indexes compare. 94 94 * @see java.lang.String 95 95 */ 96 97 98 99 100 101 102 103 96 public int compareTo(Object object) { 97 if(object instanceof Index) { 98 Index index = (Index) object; 99 return toString(false).compareTo(index.toString(false)); 100 } 101 return toString(false).compareTo(object.toString()); 102 } 103 /** Method to test for the equality of two indexes. 104 104 * @param object The other index as an <strong>Object</strong>. 105 105 * @return A <i>boolean</i> which is <i>true</i> if the two indexes are equal, <i>false</i> otherwise. 106 106 */ 107 108 109 110 111 112 113 107 public boolean equals(Object object) { 108 if(compareTo(object) == 0) { 109 return true; 110 } 111 return false; 112 } 113 /** Method to get the data source of this index. 114 114 * @return A <strong>String</string> which is a comma separated list of either fully qualified names of an assigned metadata elements, or "text". 115 115 */ 116 117 118 119 120 121 122 123 124 125 126 127 116 public String getData() { 117 String result = ""; 118 Collections.sort(sources, new IndexComparator()); 119 for(int i = 0; i < sources.size(); i++) { 120 result = result + sources.get(i).toString(); 121 if(i < sources.size() - 1) { 122 result = result + ","; 123 } 124 } 125 return result; 126 } 127 /** Method to get the value of level. 128 128 * @return The value of level as a <strong>String</strong>. 129 129 */ 130 131 132 133 130 public int getLevel() { 131 return level; 132 } 133 /** Method to get the value of metadata. 134 134 * @return The value of metadata as an <strong>Vector</strong>. 135 135 */ 136 137 138 139 136 public Vector getMetadata() { 137 return sources; 138 } 139 /** Method to retrieve this indexes name. 140 140 * @return A <strong>String</strong>. 141 141 */ 142 143 144 145 146 147 148 149 150 151 152 153 142 public String getName() { 143 if(manager != null) { 144 String name = LEVEL[level] + ":" + getData(); 145 Language language = manager.languages.getDefaultLanguage(); 146 CollectionMeta metadata = manager.collectionmetadatum.getMetadata(name, language, true); 147 if(metadata != null) { 148 return metadata.getValue(); 149 } 150 } 151 return ""; 152 } 153 /** Method to turn this object into a string representation ready to be placed in the collection configuration file. 154 154 * @return A <strong>String</strong> containing the information of this class. 155 155 */ 156 157 158 159 156 public String toString() { 157 return LEVEL[level] + ":" + getData() + " \"" + getName() + "\""; 158 } 159 /** Retrieve a textual representation of this index. 160 160 * @param show_name <i>true</i> if you want the name of this index, <i>false</i> for the gsdl index reference. 161 161 */ 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 162 public String toString(boolean show_name) { 163 if(show_name) { 164 return getName(); 165 } 166 return LEVEL[level] + ":" + getData(); 167 } 168 /** A custom comparator for comparing Indexes. */ 169 private class IndexComparator 170 implements Comparator { 171 /** Method to compare two objects, which may be either indexes or strings. 172 * @param object1 One object as an <strong>Object</strong>. 173 * @param object2 Another object as an <strong>Object</strong>. 174 * @return An <i>int</i> which indicates how they compare. 175 * @see java.lang.String 176 */ 177 public int compare(Object object1, Object object2) { 178 if(object1 instanceof Index && object2 instanceof Index) { 179 Index index1 = (Index)object1; 180 Index index2 = (Index)object2; 181 return index1.toString(false).compareTo(index2.toString(false)); 182 } 183 else if(object1 instanceof Index) { 184 Index index = (Index) object1; 185 return index.toString(false).compareTo(object2.toString()); 186 } 187 else if(object2 instanceof Index) { 188 Index index = (Index) object2; 189 return object1.toString().compareTo(index.toString(false)); 190 } 191 return object1.toString().compareTo(object2.toString()); 192 } 193 /** Method to test for the equality of two objects, which may be indexes or strings. 194 194 * @param object Another object as an <strong>Object</strong>. 195 195 * @return A <i>boolean</i> which is <i>true</i> if the two objects are equal, <i>false</i> otherwise. 196 196 */ 197 198 199 200 201 202 203 197 public boolean equals(Object object) { 198 if(compareTo(object) == 0) { 199 return true; 200 } 201 return false; 202 } 203 } 204 204 }
Note:
See TracChangeset
for help on using the changeset viewer.