01: /*******************************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *******************************************************************************/package org.ofbiz.entity.condition;
19:
20: import java.util.ArrayList;
21: import java.util.Collections;
22: import java.util.Iterator;
23: import java.util.LinkedHashMap;
24: import java.util.List;
25: import java.util.Map;
26:
27: /**
28: * Encapsulates simple expressions used for specifying queries
29: *
30: */
31: public class EntityFieldMap extends EntityConditionListBase {
32:
33: protected Map fieldMap;
34:
35: protected EntityFieldMap() {
36: super ();
37: }
38:
39: public static List makeConditionList(Map fieldMap,
40: EntityComparisonOperator op) {
41: if (fieldMap == null)
42: return new ArrayList();
43: List list = new ArrayList(fieldMap.size());
44: Iterator it = fieldMap.entrySet().iterator();
45: while (it.hasNext()) {
46: Map.Entry entry = (Map.Entry) it.next();
47: String field = (String) entry.getKey();
48: Object value = entry.getValue();
49: list.add(new EntityExpr(field, op, value));
50: }
51: return list;
52: }
53:
54: public EntityFieldMap(Map fieldMap,
55: EntityComparisonOperator compOp, EntityJoinOperator joinOp) {
56: super (makeConditionList(fieldMap, compOp), joinOp);
57: this .fieldMap = fieldMap;
58: if (this .fieldMap == null)
59: this .fieldMap = new LinkedHashMap();
60: this .operator = joinOp;
61: }
62:
63: public EntityFieldMap(Map fieldMap, EntityJoinOperator operator) {
64: this (fieldMap, EntityOperator.EQUALS, operator);
65: }
66:
67: public Object getField(String name) {
68: return this .fieldMap.get(name);
69: }
70:
71: public boolean containsField(String name) {
72: return this .fieldMap.containsKey(name);
73: }
74:
75: public Iterator getFieldKeyIterator() {
76: return Collections.unmodifiableSet(this .fieldMap.keySet())
77: .iterator();
78: }
79:
80: public Iterator getFieldEntryIterator() {
81: return Collections.unmodifiableSet(this .fieldMap.entrySet())
82: .iterator();
83: }
84:
85: public void accept(EntityConditionVisitor visitor) {
86: visitor.acceptEntityFieldMap(this);
87: }
88: }
|