/** *######################################################################### * * A component of the Gatherer application, part of the Greenstone digital * library suite from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * *

* * Author: John Thompson, Greenstone Digital Library, University of Waikato * *

* * Copyright (C) 1999 New Zealand Digital Library Project * *

* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * *

* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * *

* * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *######################################################################## */ package org.greenstone.gatherer.cdm; /************************************************************************************** * Title: Gatherer * Description: The Gatherer: a tool for gathering and enriching a digital collection. * Copyright: Copyright (c) 2001 * Company: The University of Waikato * Written: 03/05/02 * Revised: 17/11/02 - Commented **************************************************************************************/ import java.util.Collections; import java.util.StringTokenizer; import java.util.Vector; import org.greenstone.gatherer.cdm.Subcollection; import org.greenstone.gatherer.cdm.SubcollectionManager; /** The SubIndex class is essentially a Vector with some extra added magic to make it print out properly. * @author John Thompson, Greenstone Digital Library, University of Waikato * @version 2.1 */ public class SubIndex extends Vector implements Comparable { /** Default Constructor. */ public SubIndex() { super(); } /** Copy Constructor. * @param original The Vector used to initially fill the SubIndex. */ public SubIndex(Vector original) { super(original); } /** Parsed data Constructor. * @param raw A String containing a comma separated list of subcollection names. * @param manager A reference to the SubcollectionManager via which we retrieve the required Subcollections. */ public SubIndex(String raw, SubcollectionManager manager) { super(); StringTokenizer tokenizer = new StringTokenizer(raw, ","); while(tokenizer.hasMoreTokens()) { String name = tokenizer.nextToken(); Subcollection sub = manager.getSubcollection(name); if(sub != null) { add(sub); } } } /** Method to compare two subindexes. * @param object The other subindex to compare to, as an Object. * @return An int which is greater than, equal to or less than zero if the this object is before, equal to, or after the target object respectively. */ public int compareTo(Object object) { SubIndex index = (SubIndex) object; return toString().compareTo(index.toString()); } /** Method to determine if this subindex contains a certain subcollection. * @param name The name, as a String, of the subcollection you are checking for. * @return A boolean which is true if this index contains the named subcollection, false otherwise. */ public boolean containsSubcollection(String name) { for(int i = 0; i < size(); i++) { Subcollection sub = (Subcollection) get(i); if(sub.getName().equals(name)) { return true; } } return false; } /** Method to check two subindexes for equality. * @param object The other subindex to compare to, as an Object. * @return A boolean which is true if the subindexes are equal, false otherwise. */ public boolean equals(Object object) { if(compareTo(object) == 0) { return true; } return false; } /** Method to generate a comma separated list from a subindex vector. * @return A String representing this subindex. */ public String toString() { String text = ""; for(int i = 0; i < size(); i++) { Object object = get(i); Subcollection sub = (Subcollection) get(i); text = text + sub.getName(); if(i < size() - 1) { text = text + ","; } } return text; } }