001: // Copyright 09/25/00 Sun Microsystems, Inc. All Rights Reserved.
002: // "@(#)Target.java 1.8 00/09/25 Sun Microsystems"
003:
004: package com.sun.portal.desktop.util;
005:
006: import java.util.ArrayList;
007: import java.util.Enumeration;
008: import java.util.List;
009: import java.util.Vector;
010:
011: public class Target {
012: private static final String sccsID = "@(#)Target.java 1.8 00/09/25 Sun Microsystems, Inc.";
013:
014: private static final int NAMES = 0;
015: private static final int VALUES = 1;
016:
017: public static final int INDEX_FIRST = 0;
018: public static final int INDEX_LAST = 1;
019:
020: private String name = null;
021: private String value = null;
022:
023: public Target(String t, char sep, int indexType) {
024: int index;
025: if (indexType == INDEX_FIRST) {
026: index = t.indexOf(sep);
027: } else {
028: index = t.lastIndexOf(sep);
029: }
030:
031: if (index != -1) {
032: name = t.substring(0, index);
033: value = t.substring(index + 1);
034: }
035: }
036:
037: public Target(String t) {
038: this (t, '|', INDEX_LAST);
039: }
040:
041: public Target(String n, String v) {
042: name = n;
043: value = v;
044: }
045:
046: public String toString() {
047: return name + "|" + value;
048: }
049:
050: public String getName() {
051: return name;
052: }
053:
054: public String getValue() {
055: return value;
056: }
057:
058: public void setName(String n) {
059: name = n;
060: }
061:
062: public void setValue(String v) {
063: value = v;
064: }
065:
066: private static List breakTargetList(List targetStrings, int type) {
067: List result = new ArrayList();
068:
069: for (int i = 0; i < targetStrings.size(); i++) {
070: String s = (String) targetStrings.get(i);
071: Target t = new Target(s);
072:
073: String item = null;
074: if (type == NAMES) {
075: item = t.getName();
076: } else {
077: item = t.getValue();
078: }
079: result.add(item);
080: }
081:
082: return result;
083: }
084:
085: private static Vector breakTargetVector(Vector targetStrings,
086: int type) {
087: Vector result = new Vector();
088:
089: Enumeration e = targetStrings.elements();
090: while (e.hasMoreElements()) {
091: String s = (String) e.nextElement();
092: Target t = new Target(s);
093:
094: String item = null;
095: if (type == NAMES) {
096: item = t.getName();
097: } else {
098: item = t.getValue();
099: }
100: result.add(item);
101: }
102:
103: return result;
104: }
105:
106: public static List getNames(List targetStrings) {
107: List result = breakTargetList(targetStrings, NAMES);
108: return result;
109: }
110:
111: public static Vector getNamesVector(Vector targetStrings) {
112: Vector result = breakTargetVector(targetStrings, NAMES);
113: return result;
114: }
115:
116: public static List getValues(List targetStrings) {
117: List result = breakTargetList(targetStrings, VALUES);
118: return result;
119: }
120:
121: public static Vector getValuesVector(Vector targetStrings) {
122: Vector result = breakTargetVector(targetStrings, VALUES);
123: return result;
124: }
125:
126: }
|