Changeset 4366 for trunk/gli/src/org/greenstone/gatherer/cdm/SubIndex.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/SubIndex.java
r4293 r4366 60 60 */ 61 61 public class SubIndex 62 63 64 65 66 67 68 69 62 extends Vector 63 implements Comparable { 64 /** Default Constructor. 65 */ 66 public SubIndex() { 67 super(); 68 } 69 /** Copy Constructor. 70 70 * @param original The <strong>Vector</strong> used to initially fill the SubIndex. 71 71 */ 72 73 74 75 72 public SubIndex(Vector original) { 73 super(original); 74 } 75 /** Parsed data Constructor. 76 76 * @param raw A <strong>String</strong> containing a comma separated list of subcollection names. 77 77 * @param manager A reference to the <strong>SubcollectionManager</strong> via which we retrieve the required Subcollections. 78 78 */ 79 80 81 82 83 84 85 86 87 88 89 90 79 public SubIndex(String raw, SubcollectionManager manager) { 80 super(); 81 StringTokenizer tokenizer = new StringTokenizer(raw, ","); 82 while(tokenizer.hasMoreTokens()) { 83 String name = tokenizer.nextToken(); 84 Subcollection sub = manager.getSubcollection(name); 85 if(sub != null) { 86 add(sub); 87 } 88 } 89 } 90 /** Method to compare two subindexes. 91 91 * @param object The other subindex to compare to, as an <strong>Object</strong>. 92 92 * @return An <i>int</i> which is greater than, equal to or less than zero if the this object is before, equal to, or after the target object respectively. 93 93 */ 94 95 96 97 98 94 public int compareTo(Object object) { 95 SubIndex index = (SubIndex) object; 96 return toString().compareTo(index.toString()); 97 } 98 /** Method to determine if this subindex contains a certain subcollection. 99 99 * @param name The name, as a <strong>String</strong>, of the subcollection you are checking for. 100 100 * @return A <i>boolean</i> which is <i>true</i> if this index contains the named subcollection, <i>false</i> otherwise. 101 101 */ 102 103 104 105 106 107 108 109 110 111 102 public boolean containsSubcollection(String name) { 103 for(int i = 0; i < size(); i++) { 104 Subcollection sub = (Subcollection) get(i); 105 if(sub.getName().equals(name)) { 106 return true; 107 } 108 } 109 return false; 110 } 111 /** Method to check two subindexes for equality. 112 112 * @param object The other subindex to compare to, as an <strong>Object</strong>. 113 113 * @return A <i>boolean</i> which is <i>true</i> if the subindexes are equal, <i>false</i> otherwise. 114 114 */ 115 116 117 118 119 120 121 115 public boolean equals(Object object) { 116 if(compareTo(object) == 0) { 117 return true; 118 } 119 return false; 120 } 121 /** Method to generate a comma separated list from a subindex vector. 122 122 * @return A <strong>String</strong> representing this subindex. 123 123 */ 124 125 126 127 128 129 130 131 132 133 134 135 124 public String toString() { 125 String text = ""; 126 for(int i = 0; i < size(); i++) { 127 Object object = get(i); 128 Subcollection sub = (Subcollection) get(i); 129 text = text + sub.getName(); 130 if(i < size() - 1) { 131 text = text + ","; 132 } 133 } 134 return text; 135 } 136 136 }
Note:
See TracChangeset
for help on using the changeset viewer.