KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > entity > condition > EntityFieldMap


1 /*
2  * $Id: EntityFieldMap.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.entity.condition;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.Collections JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.LinkedHashMap JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Map JavaDoc;
33
34 /**
35  * Encapsulates simple expressions used for specifying queries
36  *
37  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
38  * @version $Rev: 5462 $
39  * @since 2.0
40  */

41 public class EntityFieldMap extends EntityConditionListBase {
42
43     protected Map JavaDoc fieldMap;
44
45     protected EntityFieldMap() {
46         super();
47     }
48
49     public static List JavaDoc makeConditionList(Map JavaDoc fieldMap, EntityComparisonOperator op) {
50         if (fieldMap == null) return new ArrayList JavaDoc();
51         List JavaDoc list = new ArrayList JavaDoc(fieldMap.size());
52         Iterator JavaDoc it = fieldMap.entrySet().iterator();
53         while (it.hasNext()) {
54             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) it.next();
55             String JavaDoc field = (String JavaDoc)entry.getKey();
56             Object JavaDoc value = entry.getValue();
57             list.add(new EntityExpr(field, op, value));
58         }
59         return list;
60     }
61
62     public EntityFieldMap(Map JavaDoc fieldMap, EntityComparisonOperator compOp, EntityJoinOperator joinOp) {
63         super(makeConditionList(fieldMap, compOp), joinOp);
64         this.fieldMap = fieldMap;
65         if (this.fieldMap == null) this.fieldMap = new LinkedHashMap JavaDoc();
66         this.operator = joinOp;
67     }
68
69     public EntityFieldMap(Map JavaDoc fieldMap, EntityJoinOperator operator) {
70         this(fieldMap, EntityOperator.EQUALS, operator);
71     }
72
73     public Object JavaDoc getField(String JavaDoc name) {
74         return this.fieldMap.get(name);
75     }
76     
77     public boolean containsField(String JavaDoc name) {
78         return this.fieldMap.containsKey(name);
79     }
80     
81     public Iterator JavaDoc getFieldKeyIterator() {
82         return Collections.unmodifiableSet(this.fieldMap.keySet()).iterator();
83     }
84     
85     public Iterator JavaDoc 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