1 24 25 package com.mckoi.util; 26 27 import java.util.Vector ; 28 29 37 38 public class StringListBucket { 39 40 43 private Vector string_list; 44 45 48 public StringListBucket() { 49 string_list = new Vector (); 50 } 51 52 public StringListBucket(String list) { 53 this(); 54 fromString(list); 55 } 56 57 58 61 public int size() { 62 return string_list.size(); 63 } 64 65 68 public void clear() { 69 string_list.clear(); 70 } 71 72 75 public void add(String element) { 76 string_list.addElement(element); 77 } 78 79 82 public void add(String element, int index) { 83 string_list.insertElementAt(element, index); 84 } 85 86 89 public String get(int index) { 90 return (String ) string_list.elementAt(index); 91 } 92 93 96 public void remove(int index) { 97 string_list.removeElementAt(index); 98 } 99 100 103 public boolean contains(String element) { 104 return string_list.contains(element); 105 } 106 107 110 public int indexOfVar(String element) { 111 return string_list.indexOf(element); 112 } 113 114 118 public StringBuffer toStringBuffer() { 119 StringBuffer buffer = new StringBuffer (); 120 buffer.append("||"); 121 for (int i = 0; i < size(); ++i) { 122 String str = get(i); 123 buffer.append(str); 124 buffer.append("||"); 125 } 126 return buffer; 127 } 128 129 public String toString() { 130 return toStringBuffer().toString(); 131 } 132 133 137 public void fromString(String list) { 138 clear(); 139 if (list != null && list.length() > 2) { 140 int last = 2; 141 int i = list.indexOf("||", 2); 142 while (i != -1) { 143 String entry = list.substring(last, i); 144 add(entry); 145 last = i + 2; 146 i = list.indexOf("||", last); 147 } 148 } 149 } 150 151 } 152 | Popular Tags |