01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package com.db4o.nativequery.expr.cmp.operand;
22:
23: public class MethodCallValue extends ComparisonOperandDescendant {
24: private String _methodName;
25: private Class[] _paramTypes;
26: private ComparisonOperand[] _args;
27:
28: public MethodCallValue(ComparisonOperandAnchor parent, String name,
29: Class[] paramTypes, ComparisonOperand[] args) {
30: super (parent);
31: _methodName = name;
32: _paramTypes = paramTypes;
33: _args = args;
34: }
35:
36: public void accept(ComparisonOperandVisitor visitor) {
37: visitor.visit(this );
38: }
39:
40: public String methodName() {
41: return _methodName;
42: }
43:
44: public Class[] paramTypes() {
45: return _paramTypes;
46: }
47:
48: public ComparisonOperand[] args() {
49: return _args;
50: }
51:
52: public boolean equals(Object obj) {
53: if (!super .equals(obj)) {
54: return false;
55: }
56: MethodCallValue casted = (MethodCallValue) obj;
57: return _methodName.equals(casted._methodName)
58: && arrayCmp(_paramTypes, casted._paramTypes)
59: && arrayCmp(_args, casted._args);
60: }
61:
62: public int hashCode() {
63: int hc = super .hashCode();
64: hc *= 29 + _methodName.hashCode();
65: hc *= 29 + _paramTypes.hashCode();
66: hc *= 29 + _args.hashCode();
67: return hc;
68: }
69:
70: public String toString() {
71: String str = super .toString() + "." + _methodName + "(";
72: for (int paramIdx = 0; paramIdx < _paramTypes.length; paramIdx++) {
73: if (paramIdx > 0) {
74: str += ",";
75: }
76: str += _paramTypes[paramIdx] + ":" + _args[paramIdx];
77: }
78: str += ")";
79: return str;
80: }
81:
82: private boolean arrayCmp(Object[] a, Object[] b) {
83: if (a.length != b.length) {
84: return false;
85: }
86: for (int paramIdx = 0; paramIdx < a.length; paramIdx++) {
87: if (!a[paramIdx].equals(b[paramIdx])) {
88: return false;
89: }
90: }
91: return true;
92: }
93: }
|