/*
 *  Copyright 2001-present Stephen Colebourne
 *
 *  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.
 */
package org.joda.beans.sample;

import java.lang.invoke.MethodHandles;

import org.joda.beans.ImmutableBean;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaBean;
import org.joda.beans.TypedMetaBean;
import org.joda.beans.gen.BeanDefinition;
import org.joda.beans.gen.PropertyDefinition;
import org.joda.beans.impl.light.LightMetaBean;

/**
 * Mock pair, used for testing.
 * 
 * @author Stephen Colebourne
 */
@BeanDefinition(style = "light", factoryName = "of")
public final class ImmPair<A, B> implements ImmutableBean {

    /**
     * The first value.
     */
    @PropertyDefinition
    private final A first;
    /**
     * The second value.
     */
    @PropertyDefinition
    private final B second;

    //------------------------- AUTOGENERATED START -------------------------
    /**
     * The meta-bean for {@code ImmPair}.
     */
    private static final MetaBean META_BEAN =
            LightMetaBean.of(
                    ImmPair.class,
                    MethodHandles.lookup(),
                    new String[] {
                            "first",
                            "second"},
                    new Object[0]);

    /**
     * The meta-bean for {@code ImmPair}.
     * @return the meta-bean, not null
     */
    public static MetaBean meta() {
        return META_BEAN;
    }

    static {
        MetaBean.register(META_BEAN);
    }

    /**
     * Obtains an instance.
     * @param <A>  the type
     * @param <B>  the type
     * @param first  the value of the property
     * @param second  the value of the property
     * @return the instance
     */
    public static <A, B> ImmPair<A, B> of(
            A first,
            B second) {
        return new ImmPair<>(
            first,
            second);
    }

    private ImmPair(
            A first,
            B second) {
        this.first = first;
        this.second = second;
    }

    @Override
    @SuppressWarnings("unchecked")
    public TypedMetaBean<ImmPair<A, B>> metaBean() {
        return (TypedMetaBean<ImmPair<A, B>>) META_BEAN;
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the first value.
     * @return the value of the property
     */
    public A getFirst() {
        return first;
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the second value.
     * @return the value of the property
     */
    public B getSecond() {
        return second;
    }

    //-----------------------------------------------------------------------
    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj != null && obj.getClass() == this.getClass()) {
            ImmPair<?, ?> other = (ImmPair<?, ?>) obj;
            return JodaBeanUtils.equal(this.first, other.first) &&
                    JodaBeanUtils.equal(this.second, other.second);
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = getClass().hashCode();
        hash = hash * 31 + JodaBeanUtils.hashCode(first);
        hash = hash * 31 + JodaBeanUtils.hashCode(second);
        return hash;
    }

    @Override
    public String toString() {
        StringBuilder buf = new StringBuilder(96);
        buf.append("ImmPair{");
        buf.append("first").append('=').append(JodaBeanUtils.toString(first)).append(',').append(' ');
        buf.append("second").append('=').append(JodaBeanUtils.toString(second));
        buf.append('}');
        return buf.toString();
    }

    //-------------------------- AUTOGENERATED END --------------------------
}
