/*
 * The MIT License
 *
 *   Copyright (c) 2016, Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
 *
 *   Permission is hereby granted, free of charge, to any person obtaining a copy
 *   of this software and associated documentation files (the "Software"), to deal
 *   in the Software without restriction, including without limitation the rights
 *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *   copies of the Software, and to permit persons to whom the Software is
 *   furnished to do so, subject to the following conditions:
 *
 *   The above copyright notice and this permission notice shall be included in
 *   all copies or substantial portions of the Software.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *   THE SOFTWARE.
 */

package io.github.benas.randombeans;

/**
 * Defines attributes used to identify fields.
 *
 * @param <T> The declaring class type
 * @param <F> The field type
 * @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
 */
public class FieldDefinition<T, F> {

    private final String name;

    private final Class<F> type;

    private final Class<T> clazz;

    /**
     * Create a new {@link FieldDefinition}.
     *
     * @param name the name of the field
     * @param type the type of the field
     * @param clazz the type of the class containing the field
     */
    public FieldDefinition(String name, Class<F> type, Class<T> clazz) {
        this.name = name;
        this.type = type;
        this.clazz = clazz;
    }

    public String getName() {
        return name;
    }

    public Class<F> getType() {
        return type;
    }

    public Class<T> getClazz() {
        return clazz;
    }

    /*
     * Field definitions are unique according to field name, field type, and declaring class type
     */

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        FieldDefinition<?, ?> that = (FieldDefinition<?, ?>) o;

        if (!name.equals(that.name)) {
            return false;
        }
        if (!type.equals(that.type)) {
            return false;
        }
        return clazz.equals(that.clazz);

    }

    @Override
    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + type.hashCode();
        result = 31 * result + clazz.hashCode();
        return result;
    }
}

@@ -2698,17 +2698,16 @@
 clazz);%0A
-%0A
     %7D%0A%0A 
@@ -2910,11 +2910,157 @@
 t;%0A    %7D
+%0A%0A    @Override%0A    public String toString() %7B%0A        return %22FieldDefinition %5Bname=%22 + name + %22, type=%22 + type + %22, clazz=%22 + clazz + %22%5D%22;%0A    %7D
 %0A%7D%0A

add #toString for FieldDefinition to ease debugging