package net.minecraft.src;

import net.lax1dude.eaglercraft.ProfileUUID;

public class AttributeModifier
{
    private final double amount;
    private final int operation;
    private final String name;
    private final ProfileUUID id;

    /**
     * If false, this modifier is not saved in NBT. Used for "natural" modifiers like speed boost from sprinting
     */
    private boolean isSaved;

    public AttributeModifier(String par1Str, double par2, int par4)
    {
        this(ProfileUUID.randomUUID(), par1Str, par2, par4);
    }

    public AttributeModifier(ProfileUUID par1UUID, String par2Str, double par3, int par5)
    {
        this.isSaved = true;
        this.id = par1UUID;
        this.name = par2Str;
        this.amount = par3;
        this.operation = par5;
        notEmpty(par2Str);
        inclusiveBetween(0, 2, par5);
    }

    private void notEmpty(String par2Str){
        if (par2Str == null){
            throw new NullPointerException();
        }
        else if (par2Str.equals("")){
            throw new IllegalArgumentException("Modifier name cannot be empty");
        }
    }

    private void inclusiveBetween(int start, int end, int par5){
        if(par5 < start && par5 > end){
            throw new IllegalArgumentException("Invalid operation");
        }
    }



    public ProfileUUID getID()
    {
        return this.id;
    }

    public String getName()
    {
        return this.name;
    }

    public int getOperation()
    {
        return this.operation;
    }

    public double getAmount()
    {
        return this.amount;
    }

    /**
     * @see #isSaved
     */
    public boolean isSaved()
    {
        return this.isSaved;
    }

    /**
     * @see #isSaved
     */
    public AttributeModifier setSaved(boolean par1)
    {
        this.isSaved = par1;
        return this;
    }

    public boolean equals(Object par1Obj)
    {
        if (this == par1Obj)
        {
            return true;
        }
        else if (par1Obj != null && this.getClass() == par1Obj.getClass())
        {
            AttributeModifier var2 = (AttributeModifier)par1Obj;

            if (this.id != null)
            {
                if (!this.id.equals(var2.id))
                {
                    return false;
                }
            }
            else if (var2.id != null)
            {
                return false;
            }

            return true;
        }
        else
        {
            return false;
        }
    }

    public int hashCode()
    {
        return this.id != null ? this.id.hashCode() : 0;
    }

    public String toString()
    {
        return "AttributeModifier{amount=" + this.amount + ", operation=" + this.operation + ", name=\'" + this.name + '\'' + ", id=" + this.id + ", serialize=" + this.isSaved + '}';
    }
}
