1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.pool;
19
20 import java.util.List;
21 import java.util.Collections;
22 import java.util.Arrays;
23
24
25
26
27
28
29
30 public class MethodCall {
31 private final String name;
32 private final List params;
33 private Object returned;
34
35 public MethodCall(final String name) {
36 this(name, null);
37 }
38
39 public MethodCall(final String name, final Object param) {
40 this(name, Collections.singletonList(param));
41 }
42
43 public MethodCall(final String name, final Object param1, final Object param2) {
44 this(name, Arrays.asList(new Object[] {param1, param2}));
45 }
46
47 public MethodCall(final String name, final List params) {
48 if (name == null) {
49 throw new IllegalArgumentException("name must not be null.");
50 }
51 this.name = name;
52 if (params != null) {
53 this.params = params;
54 } else {
55 this.params = Collections.EMPTY_LIST;
56 }
57 }
58
59 public String getName() {
60 return name;
61 }
62
63 public List getParams() {
64 return params;
65 }
66
67 public Object getReturned() {
68 return returned;
69 }
70
71 public void setReturned(final Object returned) {
72 this.returned = returned;
73 }
74
75 public MethodCall returned(Object obj) {
76 setReturned(obj);
77 return this;
78 }
79
80 public boolean equals(final Object o) {
81 if (this == o) return true;
82 if (o == null || getClass() != o.getClass()) return false;
83
84 final MethodCall that = (MethodCall)o;
85
86 if (name != null ? !name.equals(that.name) : that.name != null) return false;
87 if (params != null ? !params.equals(that.params) : that.params != null) return false;
88 if (returned != null ? !returned.equals(that.returned) : that.returned != null) return false;
89
90 return true;
91 }
92
93 public int hashCode() {
94 int result;
95 result = (name != null ? name.hashCode() : 0);
96 result = 29 * result + (params != null ? params.hashCode() : 0);
97 result = 29 * result + (returned != null ? returned.hashCode() : 0);
98 return result;
99 }
100
101 public String toString() {
102 final StringBuffer sb = new StringBuffer();
103 sb.append("MethodCall");
104 sb.append("{name='").append(name).append('\'');
105 if (!params.isEmpty()) {
106 sb.append(", params=").append(params);
107 }
108 if (returned != null) {
109 sb.append(", returned=").append(returned);
110 }
111 sb.append('}');
112 return sb.toString();
113 }
114 }