/*
 *
 * Copyright (c) 2007
 * Adrian Michel
 * http://www.tradery.com
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Adrian Michel makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
*/

package  com.tradery.contentmodel;

import java.lang.Integer;
import com.tradery.collections.IntegerPair;

class Limits extends IntegerPair
{
  public final static int INFINITY = -1;
  
  Limits( int min, int max )
    throws BadLimitsException
  {
    super( min, max );
    if( min < 0 || max < INFINITY || max >= 0 && min > max )
      throw new BadLimitsException( min, max );
  }

  private Limits( IntegerPair ip )
  {
    super( ip );
  }

  public Object clone()
  {
    return new Limits( (IntegerPair)super.clone() );
  }
  
  public int min() { return first(); }
  public int max() { return second(); }
  
  public boolean checkMin( int count ) { return count >= min(); }
  public boolean checkMax( int count ) 
  {
    return max() == INFINITY || count <= max(); 
  }
  
  public String toString()
  {
    String min = ( new Integer( min() ) ).toString();
    String max = max() == -1 ? "*" : (new Integer( max() ) ).toString();
    return "[" + min + "," + max + "]";
  }             
  
  public void dump()
  {
    ModelWriter.print( toString() );
  }
}