// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) fieldsfirst 
// Source File Name:   IntegerGene.java

package drm.genetics.simple;

import drm.genetics.Gene;
import drm.genetics.Inversible;

public class IntegerGene
	implements Gene, Inversible
{

	protected int value;
	protected int min;
	protected int max;

	public IntegerGene()
	{
		value = 0;
		min = -1;
		max = 1;
	}

	public IntegerGene(int value, int min, int max)
	{
		this.value = 0;
		this.min = -1;
		this.max = 1;
		setRange(min, max);
		set(value);
	}

	public void set(int value)
	{
		this.value = Math.min(max, Math.max(min, value));
	}

	public int get()
	{
		return value;
	}

	public void setMin(int min)
	{
		this.min = min;
		value = Math.max(value, min);
		max = Math.max(max, min);
	}

	public int getMin()
	{
		return min;
	}

	public void setMax(int max)
	{
		this.max = max;
		value = Math.min(value, max);
		min = Math.min(max, min);
	}

	public void setRange(int min, int max)
	{
		setMin(min);
		setMax(max);
	}

	public int getMax()
	{
		return max;
	}

	public void inverse()
	{
		int range = max - min;
		value = (int)(Math.random() * (double)range + (double)min);
	}

	public String toString()
	{
		return String.valueOf(value);
	}
}
