1 19 package gcc.util; 20 21 import gcc.*; 22 import gcc.properties.*; 23 import java.util.*; 24 25 public class NamedValueList extends LinkedList 26 { 27 public NamedValueList() 28 { 29 } 30 31 public NamedValueList(String namedValueList) 32 { 33 List csvList = ListUtil.getCommaSeparatedList(namedValueList); 34 for (Iterator i = csvList.iterator(); i.hasNext();) 35 { 36 String item = (String)i.next(); 37 int eqPos = item.indexOf("="); 38 if (eqPos == -1) 39 { 40 badList(namedValueList); 41 } 42 String name = item.substring(0, eqPos).trim(); 43 if (name.length() == 0) 44 { 45 badList(namedValueList); 46 } 47 String value = item.substring(eqPos + 1).trim(); 48 add(new NamedValue(name, value)); 49 } 50 } 51 52 54 public PropertyMap getProperties() 55 { 56 PropertyMap props = new PropertyMap(); 57 for (Iterator i = this.iterator(); i.hasNext();) 58 { 59 NamedValue nv = (NamedValue)i.next(); 60 props.put(nv.name, nv.value); 61 } 62 return props; 63 } 64 65 public String getValue(String name) 66 { 67 return getValue(name, null); 68 } 69 70 public String getValue(String name, String defaultValue) 71 { 72 return (String)getProperties().getProperty(name, defaultValue); 73 } 74 75 public String toString() 76 { 77 return ListUtil.formatCommaSeparatedList(this); 78 } 79 80 82 protected void badList(String namedValueList) 83 { 84 throw new IllegalArgumentException("namedValueList = " + namedValueList); 85 } 86 } 87 | Popular Tags |