// Copyright(c) 1997 ObjectSpace, Inc.

package COM.objectspace.jgl;

import java.text.Collator;

/**
 * LessCollator is a binary predicate that returns true
 * if the first operand as a string is less than the
 * second operand as a string when compared using the given Collator object.
 * <p>
 * If an explicit Collator object is not given, the default is used.
 * <p>
 * @see java.text.Collator
 * @see COM.objectspace.jgl.examples.CollateExamples
 * @version 2.0.2
 * @author ObjectSpace, Inc.
 */

public final class LessCollator implements BinaryPredicate
  {
  Collator collator;

  /**
   * Construct a LessCollator function object that uses the collator
   * object for the current default locale to compare objects.
   */
  public LessCollator()
    {
    collator = Collator.getInstance();
    }

  /**
   * Construct a LessCollator function object that uses the given collator
   * object to compare objects.
   * @param collator The Collator object that is to be used for comparisons.
   */
  public LessCollator( Collator collator )
    {
    this.collator = collator;
    }

  /**
   * Return true if the first operand is less than the second operand.
   * @see java.text.Collator#compare
   * @param first The first operand.
   * @param second The second operand.
   * @return collator.compare( first.toString(), second.toString() ) < 0.
   */
  public boolean execute( Object first, Object second )
    {
    return collator.compare( first.toString(), second.toString() ) < 0;
    }
  }
