View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF 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.apache.commons.weaver.privilizer;
20  
21  import java.util.Objects;
22  
23  import org.apache.commons.lang3.StringUtils;
24  import org.apache.commons.lang3.Validate;
25  import org.objectweb.asm.Type;
26  
27  /**
28   * Represents a Java field.
29   */
30  public class Field {
31      /**
32       * Access modifier.
33       */
34      public final int access;
35  
36      /**
37       * Field name.
38       */
39      public final String name;
40  
41      /**
42       * Field type.
43       */
44      public final Type type;
45  
46      /**
47       * Create a new {@link Field}.
48       * @param access modifier
49       * @param name of field
50       * @param type of field
51       */
52      public Field(final int access, final String name, final Type type) {
53          super();
54          this.access = access;
55          this.name = Validate.notNull(name);
56          this.type = Validate.notNull(type);
57      }
58  
59      /**
60       * Considers name and type.
61       * @param obj to check for equality
62       * @return whether equal
63       */
64      @Override
65      public boolean equals(final Object obj) {
66          if (obj == this) {
67              return true;
68          }
69          if (!(obj instanceof Field)) {
70              return false;
71          }
72          final Field other = (Field) obj;
73          return StringUtils.equals(other.name, name) && Objects.equals(other.type, type);
74      }
75  
76      /**
77       * Considers name and type.
78       * @return hashCode
79       */
80      @Override
81      public int hashCode() {
82          return Objects.hash(name, type);
83      }
84  }