// FILE. . . . . /home/hak/hlt/src/hlt/osfv2/exec/CyclicSortOrderingException.java
// EDIT BY . . . Hassan Ait-Kaci
// ON MACHINE. . Hak-Laptop
// STARTED ON. . Tue Jan 21 08:10:42 2014

/**
 * @version     Last modified on Tue Jan 21 08:11:06 2014 by hak
 * @author      <a href="mailto:hak@acm.org">Hassan A&iuml;t-Kaci</a>
 * @copyright   &copy; <a href="http://www.hassan-ait-kaci.net/">by the author</a>
 */

package hlt.osf.exec;

import hlt.language.util.ArrayList;

public class CyclicSortOrderingException extends RuntimeException
{
  private ArrayList _cycles;
  
  public CyclicSortOrderingException (String msg)
  {
    super(msg);
  }

  public CyclicSortOrderingException (ArrayList cycles)
  {
    _cycles = cycles;
  }

  /**
   * Returns a string consisting of a message followed by the cycles detected.
   */
  public String getMessage ()
  {
    int size = _cycles.size();

    StringBuilder buf = new StringBuilder("Cyclic sort ordering; "+size+" cycle"+(size>1?"s":"")+" detected:\n");

    for (int i=0; i<size; i++)
      buf.append("***        Cycle -> "+_cycles.get(i)+(i<size-1?"\n":""));

    return buf.toString();
  }

}