- 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/CollectionMeta.java
r4293 r4366 59 59 */ 60 60 public class CollectionMeta 61 62 63 64 65 66 67 68 69 70 71 72 73 61 implements Comparable { 62 /** A reference to the collection design manager for access to the language manager. */ 63 private CollectionDesignManager manager = null; 64 /** The language of this metadata. Should be a two letter code. */ 65 private Language language = null; 66 /** The name of the thing this metadata is assigned to, which may index an Index. */ 67 private Object name = null; 68 /** The value of this metadata. */ 69 private String value = null; 70 /** Constructor. 71 * @param name The object the metadata is assigned to as an <strong>Object</strong>. 72 * @param language The language of the metadata as a <strong>Language</strong>. Should be a two letter code. 73 * @param value The value of this metadata, as a <strong>String</strong>. 74 74 */ 75 76 77 78 79 80 81 75 public CollectionMeta(CollectionDesignManager manager, Object name, Language language, String value) { 76 this.language = language; 77 this.manager = manager; 78 this.name = name; 79 this.value = value; 80 } 81 /** Method to compare two collection metadata objects to calculate their respective ordering. 82 82 * @param object The other metadata to compare to, as an <strong>Object</strong>. 83 83 * @return An <i>int</i> which is less than 0 if this object proceeds the given object, 0 if they are equal and greater than 0 otherwise. 84 84 * @see org.greenstone.gatherer.cdm.Language 85 85 */ 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 86 public int compareTo(Object object) { 87 if(object instanceof CollectionMeta) { 88 CollectionMeta metadata = (CollectionMeta) object; 89 int result = name.toString().compareTo(metadata.getName().toString()); 90 if(result == 0) { 91 Language other_language = metadata.getLanguage(); 92 if(language != null && other_language != null) { 93 result = language.compareTo(metadata.getLanguage()); 94 if(result == 0) { 95 return value.compareTo(metadata.getValue()); 96 } 97 } 98 else if(language != null) { 99 return -1; 100 } 101 else if(other_language != null) { 102 return 1; 103 } 104 } 105 return result; 106 } 107 return toString().compareTo(object.toString()); 108 } 109 /** Method to compare two collection metadata objects for equality. 110 110 * @param object The other metadata to compare to, as an <strong>Object</strong>. 111 111 * @return A <i>boolean</i> value of <i>true</i> if the object are equal, <i>false</i> otherwise. 112 112 */ 113 114 115 116 117 118 119 113 public boolean equals(Object object) { 114 if(compareTo(object) == 0) { 115 return true; 116 } 117 return false; 118 } 119 /** Method to retrieve the value of language. 120 120 * @return The value of language as a <strong>Language</strong>. 121 121 */ 122 123 124 125 122 public Language getLanguage() { 123 return language; 124 } 125 /** Method to retrieve the value of name. 126 126 * @return The value of name as an <strong>Object</strong>. 127 127 */ 128 129 130 131 128 public Object getName() { 129 return name; 130 } 131 /** Method to retrieve the value of value (well great choice of name there). 132 132 * @return The value of value as a <strong>String</strong>. 133 133 */ 134 135 136 137 134 public String getValue() { 135 return value; 136 } 137 /** Method to print out this class as it would appear within the collection configuration file. 138 138 * @return A <strong>String</strong> containing the text value of this class. 139 139 */ 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 140 public String toString() { 141 String text = "collectionmeta "; 142 if(name instanceof Index) { 143 text = text + "."; 144 Index index = (Index)name; 145 text = text + index.toString(false) + " "; 146 } 147 else { 148 text = text + name.toString() + " "; 149 } 150 if(language != null && manager.languages.size() > 0 && !manager.languages.isDefaultLanguage(language)) { 151 text = text + "[l=" + language.getCode() + "] "; 152 } 153 text = text + "\"" + Utility.encodeGreenstone(value) + "\"\n"; 154 return text; 155 } 156 /** Used to update the contents of this collection level metadata to the given 'new' values. 157 157 * @param name The new name of the metadata, as a <strong>Object</strong>. 158 158 * @param language The new <strong>Language</strong> of the metadata. 159 159 * @param value And the value the metadata is assigned, as a <strong>String</strong>. 160 160 */ 161 162 163 164 165 166 161 public void update(Object name, Language language, String value) { 162 this.name = name; 163 this.language = language; 164 this.value = value; 165 } 166 /** Ensure this is a valid metadata entry by checking that the value is non-null and non-zero length (after having removed whitespace). 167 167 * @return <i>true</i> if this metadata has a valid value and should be added to the config, <i>false</i> otherwise. 168 168 */ 169 170 171 169 public boolean valid() { 170 return(value != null && value.trim().length() > 0); 171 } 172 172 } 173 173
Note:
See TracChangeset
for help on using the changeset viewer.