1 package rero.config; 2 3 import java.util.*; 4 5 public class StringList 6 { 7 protected LinkedList values; 8 protected String key; 9 10 public StringList(String _key) 11 { 12 key = _key; 13 load(); 14 } 15 16 public void load() 17 { 18 String value = ClientState.getClientState().getString(key, null); 19 LinkedList rv = new LinkedList(); 20 21 if (value != null) 22 { 23 String [] temp = value.split("::"); 24 for (int x = 0; x < temp.length; x++) 25 { 26 if (temp[x].length() > 0) 27 rv.add(temp[x]); 28 } 29 } 30 31 values = rv; 32 } 33 34 public boolean isValue(String value) 35 { 36 return values.contains(value); 37 } 38 39 public LinkedList getList() 40 { 41 return values; 42 } 43 44 public void save() 45 { 46 StringBuffer value = new StringBuffer (); 47 48 if (values.size() > 0) 49 { 50 value.append(values.getFirst()); 51 52 Iterator i = values.listIterator(1); 53 while (i.hasNext()) 54 { 55 value.append("::"); 56 value.append(i.next().toString()); 57 } 58 } 59 60 ClientState.getClientState().setString(key, value.toString()); 61 } 62 63 public void add(String element) 64 { 65 values.add(element); 66 } 67 68 public void remove(String element) 69 { 70 Iterator i = values.listIterator(); 71 while (i.hasNext()) 72 { 73 if (i.next().toString().equals(element)) 74 { 75 i.remove(); 76 } 77 } 78 79 save(); 80 ClientState.getClientState().fireChange(key, element); 81 } 82 83 public void clear() 84 { 85 values = new LinkedList(); 86 save(); 87 ClientState.getClientState().fireChange(key); 88 } 89 } 90 | Popular Tags |