1 package jodd.util; 2 3 import java.util.HashMap; 4 import java.util.Iterator; 5 6 import jodd.bean.BeanUtil; 7 8 35 public class StringFlags { 36 37 private HashMap map = new HashMap(); 38 39 class Flag { 40 String bpname; 41 boolean val; 42 } 43 44 51 public void addFlag(char c, String bpname, boolean val) { 52 Flag f = new Flag(); 53 f.bpname = bpname; 54 f.val = val; 55 map.put(new Character(c), f); 56 } 57 58 61 public void clearFlags() { 62 map.clear(); 63 } 64 65 66 72 public void parse(String params, Object o) { 73 if (params == null) { 74 params = ""; 75 } 76 char[] ca = params.toCharArray(); 77 Iterator i = map.keySet().iterator(); 78 while (i.hasNext()) { 79 Character c = (Character) i.next(); 80 Flag f = (Flag) map.get(c); 81 if (f == null) { 82 continue; 83 } 84 boolean b = f.val; 85 if (params.indexOf(c.charValue()) == -1) { 86 b = !b; 87 } 88 BeanUtil.setProperty(o, f.bpname, new Boolean(b)); 89 } 90 } 91 92 } 93 94 | Popular Tags |