All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.datanucleus.enhancer.ClassField Maven / Gradle / Ivy

Go to download

DataNucleus Core provides the primary components of a heterogenous Java persistence solution. It supports persistence API's being layered on top of the core functionality.

There is a newer version: 6.0.7
Show newest version
/**********************************************************************
Copyright (c) 2007 Andy Jefferson and others. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Contributors:
    ...
**********************************************************************/
package org.datanucleus.enhancer;

/**
 * Representation of a field that an enhanced class requires.
 */
public class ClassField
{
    /** The parent enhancer. */
    protected ClassEnhancer enhancer;

    /** Name of the field. */
    protected String fieldName;

    /** Access flags for the field (public, protected etc). */
    protected int access;

    /** Type for the field */
    protected Object type;

    /** Initial value for the field. */
    protected Object initialValue;

    /**
     * Constructor
     * @param enhancer Class Enhancer
     * @param name Name of the field
     * @param access Access for the field (PUBLIC, PROTECTED etc)
     * @param type Type of the field
     */
    public ClassField(ClassEnhancer enhancer, String name, int access, Object type)
    {
        this.enhancer = enhancer;
        this.fieldName = name;
        this.access = access;
        this.type = type;
    }

    /**
     * Constructor
     * @param enhancer Class Enhancer
     * @param name Name of the field
     * @param access Access for the field (PUBLIC, PROTECTED etc)
     * @param type Type of the field
     * @param value Initial value
     */
    public ClassField(ClassEnhancer enhancer, String name, int access, Object type, Object value)
    {
        this.enhancer = enhancer;
        this.fieldName = name;
        this.access = access;
        this.type = type;
        this.initialValue = value;
    }

    /**
     * Accessor for the field name
     * @return Name of the field
     */
    public String getName()
    {
        return fieldName;
    }

    /**
     * Accessor for the access
     * @return Access type for the field
     */
    public int getAccess()
    {
        return access;
    }

    /**
     * Accessor for the type
     * @return Type of the field
     */
    public Object getType()
    {
        return type;
    }

    /**
     * Accessor for the value
     * @return Initial value of the field
     */
    public Object getInitialValue()
    {
        return initialValue;
    }

    /**
     * Return hash code of this instance.
     * @return hash code of this instance
     */
    public int hashCode()
    {
        return fieldName.hashCode();
    }

    /**
     * Indicates whether some other object is "equal to" this one.
     * @param o the reference object with which to compare.
     * @return true if this object is the same as the obj argument; false otherwise.
     */
    public boolean equals(Object o)
    {
        if (o instanceof ClassField)
        {
            ClassField cf = (ClassField)o;
            if (cf.fieldName.equals(fieldName))
            {
                return type == cf.type;
            }
        }
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy