001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019:
020: package de.schlund.pfixxml.targets;
021:
022: import java.util.ArrayList;
023: import java.util.Arrays;
024: import java.util.StringTokenizer;
025:
026: /**
027: * Describe class Themes here.
028: *
029: *
030: * Created: Fri Apr 22 13:57:33 2005
031: *
032: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
033: * @version 1.0
034: */
035: public class Themes {
036: ArrayList<String> themes;
037: String id;
038:
039: /**
040: * Creates a new <code>Themes</code> instance.
041: *
042: */
043: public Themes(String[] themesarr) {
044: if (themesarr == null) {
045: throw new RuntimeException("Themes array must not be null");
046: }
047: if (themesarr.length == 0) {
048: throw new RuntimeException("Themes array must not be empty");
049: }
050: this .themes = new ArrayList<String>();
051: themes.addAll(Arrays.asList(themesarr));
052: StringBuffer themesstr = new StringBuffer("");
053: for (int i = 0; i < themesarr.length; i++) {
054: if (themesstr.length() > 0) {
055: themesstr.append(" ");
056: }
057: themesstr.append(themesarr[i]);
058: }
059: id = themesstr.toString();
060: }
061:
062: public Themes(String id) {
063: if (id == null) {
064: throw new RuntimeException("Themes id must not be null");
065: }
066: if (id.equals("")) {
067: throw new RuntimeException("Themes id must not be empty");
068: }
069: this .id = id;
070: StringTokenizer tok = new StringTokenizer(id);
071: this .themes = new ArrayList<String>();
072: while (tok.hasMoreElements()) {
073: String currtok = tok.nextToken();
074: themes.add(currtok);
075: }
076: }
077:
078: public String getId() {
079: return id;
080: }
081:
082: public String[] getThemesArr() {
083: return (String[]) themes.toArray(new String[] {});
084: }
085:
086: public boolean equals(Object input) {
087: if (!(input instanceof Themes)) {
088: return false;
089: } else {
090: return id.equals(((Themes) input).getId());
091: }
092: }
093:
094: public int hashCode() {
095: return id.hashCode();
096: }
097:
098: public boolean containsTheme(String themepart) {
099: return themes.contains(themepart);
100: }
101:
102: }
|