source: trunk/gli/src/org/greenstone/gatherer/cdm/SubIndex.java@ 4293

Last change on this file since 4293 was 4293, checked in by jmt12, 21 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37
38
39
40
41
42
43package org.greenstone.gatherer.cdm;
44/**************************************************************************************
45 * Title: Gatherer
46 * Description: The Gatherer: a tool for gathering and enriching a digital collection.
47 * Copyright: Copyright (c) 2001
48 * Company: The University of Waikato
49 * Written: 03/05/02
50 * Revised: 17/11/02 - Commented
51 **************************************************************************************/
52import java.util.Collections;
53import java.util.StringTokenizer;
54import java.util.Vector;
55import org.greenstone.gatherer.cdm.Subcollection;
56import org.greenstone.gatherer.cdm.SubcollectionManager;
57/** The <strong>SubIndex</strong> class is essentially a <strong>Vector</strong> with some extra added magic to make it print out properly.
58* @author John Thompson, Greenstone Digital Library, University of Waikato
59* @version 2.1
60*/
61public class SubIndex
62 extends Vector
63 implements Comparable {
64 /** Default Constructor.
65 */
66 public SubIndex() {
67 super();
68 }
69 /** Copy Constructor.
70 * @param original The <strong>Vector</strong> used to initially fill the SubIndex.
71 */
72 public SubIndex(Vector original) {
73 super(original);
74 }
75 /** Parsed data Constructor.
76 * @param raw A <strong>String</strong> containing a comma separated list of subcollection names.
77 * @param manager A reference to the <strong>SubcollectionManager</strong> via which we retrieve the required Subcollections.
78 */
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 * @param object The other subindex to compare to, as an <strong>Object</strong>.
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 */
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 * @param name The name, as a <strong>String</strong>, of the subcollection you are checking for.
100 * @return A <i>boolean</i> which is <i>true</i> if this index contains the named subcollection, <i>false</i> otherwise.
101 */
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 * @param object The other subindex to compare to, as an <strong>Object</strong>.
113 * @return A <i>boolean</i> which is <i>true</i> if the subindexes are equal, <i>false</i> otherwise.
114 */
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 * @return A <strong>String</strong> representing this subindex.
123 */
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}
Note: See TracBrowser for help on using the repository browser.