View Javadoc

1   /**
2    * Licensed to jclouds, Inc. (jclouds) under one or more
3    * contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  jclouds licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
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   */
19  package org.jclouds.internal;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  
23  import java.lang.reflect.Method;
24  import java.util.Arrays;
25  
26  import org.jclouds.javax.annotation.Nullable;
27  
28  /**
29   * 
30   * @author Adrian Cole
31   */
32  public class ClassMethodArgs {
33     private final Method method;
34     private final Object[] args;
35     private final Class<?> asyncClass;
36  
37     public ClassMethodArgs(Class<?> asyncClass, Method method, @Nullable Object[] args) {
38        this.asyncClass = checkNotNull(asyncClass, "asyncClass");
39        this.method = checkNotNull(method, "method");
40        this.args = args;
41     }
42  
43     @Override
44     public String toString() {
45        return "[class=" + asyncClass.getSimpleName() + ", method=" + method.getName() + ", args="
46              + Arrays.toString(args) + "]";
47     }
48  
49     public Method getMethod() {
50        return method;
51     }
52  
53     public Object[] getArgs() {
54        return args;
55     }
56  
57     @Override
58     public int hashCode() {
59        final int prime = 31;
60        int result = 1;
61        result = prime * result + Arrays.hashCode(args);
62        result = prime * result + ((asyncClass == null) ? 0 : asyncClass.hashCode());
63        result = prime * result + ((method == null) ? 0 : method.hashCode());
64        return result;
65     }
66  
67     @Override
68     public boolean equals(Object obj) {
69        if (this == obj)
70           return true;
71        if (obj == null)
72           return false;
73        if (getClass() != obj.getClass())
74           return false;
75        ClassMethodArgs other = (ClassMethodArgs) obj;
76        if (!Arrays.equals(args, other.args))
77           return false;
78        if (asyncClass == null) {
79           if (other.asyncClass != null)
80              return false;
81        } else if (!asyncClass.equals(other.asyncClass))
82           return false;
83        if (method == null) {
84           if (other.method != null)
85              return false;
86        } else if (!method.equals(other.method))
87           return false;
88        return true;
89     }
90  
91     public Class<?> getAsyncClass() {
92        return asyncClass;
93     }
94  }