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

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

2030098: Fixed translation manager and separated the Languages from the possible text fragment Translations.

  • 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 return toString().compareTo(object.toString());
96 }
97 /** Method to determine if this subindex contains a certain subcollection.
98 * @param name The name, as a <strong>String</strong>, of the subcollection you are checking for.
99 * @return A <i>boolean</i> which is <i>true</i> if this index contains the named subcollection, <i>false</i> otherwise.
100 */
101 public boolean containsSubcollection(String name) {
102 for(int i = 0; i < size(); i++) {
103 Subcollection sub = (Subcollection) get(i);
104 if(sub.getName().equals(name)) {
105 return true;
106 }
107 }
108 return false;
109 }
110 /** Method to check two subindexes for equality.
111 * @param object The other subindex to compare to, as an <strong>Object</strong>.
112 * @return A <i>boolean</i> which is <i>true</i> if the subindexes are equal, <i>false</i> otherwise.
113 */
114 public boolean equals(Object object) {
115 return (compareTo(object) == 0);
116 }
117 /** Method to generate a comma separated list from a subindex vector.
118 * @return A <strong>String</strong> representing this subindex.
119 */
120 public String toString() {
121 StringBuffer text = new StringBuffer("");
122 for(int i = 0; i < size(); i++) {
123 Object object = get(i);
124 Subcollection sub = (Subcollection) get(i);
125 text.append(sub.getName());
126 if(i < size() - 1) {
127 text.append(",");
128 }
129 }
130 return text.toString();
131 }
132}
Note: See TracBrowser for help on using the repository browser.