1 6 7 package org.netbeans.test.editor.app.core.properties; 8 9 import java.util.ArrayList ; 10 import java.util.Enumeration ; 11 import java.util.Iterator ; 12 import java.util.Vector ; 13 14 18 public class Properties { 19 20 Vector entries; 21 22 23 public Properties() { 24 entries=new Vector (30); 25 } 26 27 public Object getProperty(java.lang.String name) { 28 if (name == null) throw new NullPointerException ("Null name property."); 29 Entry e; 30 for (Iterator it=entries.iterator();it.hasNext();) { 31 e=(Entry)(it.next()); 32 if (e.key.compareTo(name) == 0) { 33 return e.value; 34 } 35 } 36 return null; 37 } 38 39 public Object put(String name, Object value) { 40 Object ret=null; 41 Entry e=null; 42 if (name == null) throw new NullPointerException ("Null name property."); 43 if (value == null) throw new NullPointerException ("Null property value."); 44 for (Iterator it=entries.iterator();it.hasNext();) { 45 e=(Entry)(it.next()); 46 if (e.key.compareTo(name) == 0) { 47 ret=e.value; 48 break; 49 } 50 } 51 if (ret == null) { 52 entries.add(new Entry(name,value)); 53 } else { 54 e.value=value; 55 } 56 return ret; 57 } 58 59 public Enumeration propertyNames() { 60 return new Enumeration () { 61 String [] names=getNames(); 62 int i=0; 63 64 public boolean hasMoreElements() { 65 return (i < names.length); 66 } 67 68 public Object nextElement() { 69 return names[i++]; 70 } 71 }; 72 } 73 74 private String [] getNames() { 75 ArrayList ar=new ArrayList (); 76 Entry e; 77 for (Iterator it=entries.iterator();it.hasNext();) { 78 e=(Entry)(it.next()); 79 ar.add(e.key); 80 } 81 return (String [])(ar.toArray(new String [] {})); 82 } 83 84 90 public void clear() { 91 entries.removeAllElements(); 92 } 93 94 99 public boolean isEmpty() { 100 return entries.size() == 0; 101 } 102 103 128 public Object remove(String key) { 129 Entry e; 130 for (Iterator it=entries.iterator();it.hasNext();) { 131 e=(Entry)(it.next()); 132 if (e.key.compareTo(key) == 0) { 133 entries.remove(e); 134 return e.value; 135 } 136 } 137 return null; 138 } 139 140 147 public int size() { 148 return entries.size(); 149 } 150 151 static class Entry { 152 public String key; 153 public Object value; 154 155 public Entry(String key,Object value) { 156 this.key=key; 157 this.value=value; 158 } 159 } 160 } 161 | Popular Tags |