001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.commons.weaver.privilizer;
020
021import org.apache.commons.lang3.ObjectUtils;
022import org.apache.commons.lang3.StringUtils;
023import org.apache.commons.lang3.Validate;
024import org.objectweb.asm.Type;
025
026/**
027 * Represents a Java field.
028 */
029public class Field {
030    /**
031     * Access modifier.
032     */
033    public final int access;
034
035    /**
036     * Field name.
037     */
038    public final String name;
039
040    /**
041     * Field type.
042     */
043    public final Type type;
044
045    /**
046     * Create a new {@link Field}.
047     * @param access modifier
048     * @param name of field
049     * @param type of field
050     */
051    public Field(final int access, final String name, final Type type) {
052        super();
053        this.access = access;
054        this.name = Validate.notNull(name);
055        this.type = Validate.notNull(type);
056    }
057
058    /**
059     * Considers name and type.
060     * @param obj to check for equality
061     * @return whether equal
062     */
063    @SuppressWarnings("deprecation")
064    @Override
065    public boolean equals(final Object obj) {
066        if (obj == this) {
067            return true;
068        }
069        if (!(obj instanceof Field)) {
070            return false;
071        }
072        final Field other = (Field) obj;
073        return StringUtils.equals(other.name, name) && ObjectUtils.equals(other.type, type);
074    }
075
076    /**
077     * Considers name and type.
078     * @return hashCode
079     */
080    @Override
081    public int hashCode() {
082        int result = 57 << 2;
083        result |= name.hashCode();
084        result <<= 4;
085        result |= type.hashCode();
086        return result;
087    }
088}