001: /*
002: * This program is free software; you can redistribute it and/or modify
003: * it under the terms of the GNU General Public License as published by
004: * the Free Software Foundation; either version 2 of the License, or
005: * (at your option) any later version.
006: *
007: * This program is distributed in the hope that it will be useful,
008: * but WITHOUT ANY WARRANTY; without even the implied warranty of
009: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
010: * GNU General Public License for more details.
011: *
012: * You should have received a copy of the GNU General Public License
013: * along with this program; if not, write to the Free Software
014: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
015: */
016:
017: /*
018: * Tag.java
019: * Copyright (C) 1999 University of Waikato, Hamilton, New Zealand
020: *
021: */
022:
023: package weka.core;
024:
025: /**
026: * A <code>Tag</code> simply associates a numeric ID with a String description.
027: *
028: * @author <a href="mailto:len@reeltwo.com">Len Trigg</a>
029: * @version $Revision: 1.9 $
030: */
031: public class Tag {
032:
033: /** The ID */
034: protected int m_ID;
035:
036: /** The unique string for this tag, doesn't have to be numeric */
037: protected String m_IDStr;
038:
039: /** The descriptive text */
040: protected String m_Readable;
041:
042: /**
043: * Creates a new <code>Tag</code> instance.
044: *
045: * @param ident the ID for the new Tag.
046: * @param readable the description for the new Tag.
047: */
048: public Tag(int ident, String readable) {
049: this (ident, "", readable);
050: }
051:
052: /**
053: * Creates a new <code>Tag</code> instance.
054: *
055: * @param ident the ID for the new Tag.
056: * @param identStr the ID string for the new Tag (case-insensitive).
057: * @param readable the description for the new Tag.
058: */
059: public Tag(int ident, String identStr, String readable) {
060: m_ID = ident;
061: if (identStr.length() == 0)
062: m_IDStr = "" + ident;
063: else
064: m_IDStr = identStr.toUpperCase();
065: m_Readable = readable;
066: }
067:
068: /**
069: * Gets the numeric ID of the Tag.
070: *
071: * @return the ID of the Tag.
072: */
073: public int getID() {
074: return m_ID;
075: }
076:
077: /**
078: * Gets the string ID of the Tag.
079: *
080: * @return the string ID of the Tag.
081: */
082: public String getIDStr() {
083: return m_IDStr;
084: }
085:
086: /**
087: * Gets the string description of the Tag.
088: *
089: * @return the description of the Tag.
090: */
091: public String getReadable() {
092: return m_Readable;
093: }
094:
095: /**
096: * returns the IDStr
097: *
098: * @return the IDStr
099: */
100: public String toString() {
101: return m_IDStr;
102: }
103:
104: /**
105: * returns a list that can be used in the listOption methods to list all
106: * the available ID strings, e.g.: <0|1|2> or <what|ever>
107: *
108: * @param tags the tags to create the list for
109: * @return a list of all ID strings
110: */
111: public static String toOptionList(Tag[] tags) {
112: String result;
113: int i;
114:
115: result = "<";
116: for (i = 0; i < tags.length; i++) {
117: if (i > 0)
118: result += "|";
119: result += tags[i];
120: }
121: result += ">";
122:
123: return result;
124: }
125:
126: /**
127: * returns a string that can be used in the listOption methods to list all
128: * the available options, i.e., "\t\tID = Text\n" for each option
129: *
130: * @param tags the tags to create the string for
131: * @return a string explaining the tags
132: */
133: public static String toOptionSynopsis(Tag[] tags) {
134: String result;
135: int i;
136:
137: result = "";
138: for (i = 0; i < tags.length; i++) {
139: result += "\t\t" + tags[i].getIDStr() + " = "
140: + tags[i].getReadable() + "\n";
141: }
142:
143: return result;
144: }
145: }
|