1 25 package org.ofbiz.entity.condition; 26 27 import java.util.ArrayList ; 28 import java.util.Collections ; 29 import java.util.Iterator ; 30 import java.util.LinkedHashMap ; 31 import java.util.List ; 32 import java.util.Map ; 33 34 41 public class EntityFieldMap extends EntityConditionListBase { 42 43 protected Map fieldMap; 44 45 protected EntityFieldMap() { 46 super(); 47 } 48 49 public static List makeConditionList(Map fieldMap, EntityComparisonOperator op) { 50 if (fieldMap == null) return new ArrayList (); 51 List list = new ArrayList (fieldMap.size()); 52 Iterator it = fieldMap.entrySet().iterator(); 53 while (it.hasNext()) { 54 Map.Entry entry = (Map.Entry ) it.next(); 55 String field = (String )entry.getKey(); 56 Object value = entry.getValue(); 57 list.add(new EntityExpr(field, op, value)); 58 } 59 return list; 60 } 61 62 public EntityFieldMap(Map fieldMap, EntityComparisonOperator compOp, EntityJoinOperator joinOp) { 63 super(makeConditionList(fieldMap, compOp), joinOp); 64 this.fieldMap = fieldMap; 65 if (this.fieldMap == null) this.fieldMap = new LinkedHashMap (); 66 this.operator = joinOp; 67 } 68 69 public EntityFieldMap(Map fieldMap, EntityJoinOperator operator) { 70 this(fieldMap, EntityOperator.EQUALS, operator); 71 } 72 73 public Object getField(String name) { 74 return this.fieldMap.get(name); 75 } 76 77 public boolean containsField(String name) { 78 return this.fieldMap.containsKey(name); 79 } 80 81 public Iterator getFieldKeyIterator() { 82 return Collections.unmodifiableSet(this.fieldMap.keySet()).iterator(); 83 } 84 85 public Iterator getFieldEntryIterator() { 86 return Collections.unmodifiableSet(this.fieldMap.entrySet()).iterator(); 87 } 88 89 public void accept(EntityConditionVisitor visitor) { 90 visitor.acceptEntityFieldMap(this); 91 } 92 } 93 | Popular Tags |