package ch.unibe.scg.regex;

/**
 * {@link InputRange} represent a range of {@link Character} which can be used in
 * {@link TransitionTable} of {@link TDFA}.
 * 
 * @author Fabien Dubosson
 */
abstract class InputRange implements Comparable<InputRange> {
  private static class Any extends SpecialInputRange {
    @Override
    public String toString() {
      return "ANY";
    }
  }

  private static class Eos extends SpecialInputRange {
    @Override
    public String toString() {
      return "$";
    }
  }

  private static class Epsilon extends SpecialInputRange {
    @Override
    public String toString() {
      return "ε";
    }
  }

  static class SpecialInputRange extends InputRange {
    @Override
    public boolean contains(char character) {
      return false;
    }

    @Override
    public char getFrom() {
      return Character.MIN_VALUE;
    }

    @Override
    public char getTo() {
      return Character.MIN_VALUE;
    }
  }

  public static final InputRange ANY = new Any();

  public static final InputRange EOS = new Eos();

  public static final InputRange EPSILON = new Epsilon();

  public static InputRange make(final char character) {
    return make(character, character);
  }

  public static InputRange make(final char from, final char to) {
    return new RealInputRange(from, to);
  }

  static class RealInputRange extends InputRange {
    /**
     * First {@link Character} of the range
     */
    private final char from;

    /**
     * Last {@link Character} or the range
     */
    private final char to;

    /**
     * Constructor which take the first and last character as parameter
     * 
     * @param from The first {@link Character} of the range
     * @param to The last {@link Character} of the range
     */
    RealInputRange(final char from, final char to) {
      this.from = from;
      this.to = to;
    }

    @Override
    public boolean contains(final char character) {
      return (from <= character && character <= to);
    }

    @Override
    public String toString() {
      return "" + from + "-" + to;
    }

    @Override
    public char getFrom() {
      return from;
    }

    @Override
    public char getTo() {
      return to;
    }
  }

  @Override
  public int compareTo(InputRange o) {
    return Character.compare(getFrom(), o.getFrom());
  };

  /**
   * Tell if the {@link InputRange} contains a {@link Character} within its range
   * 
   * @param character A specific {@link Character}.
   * @return if the {@link Character} is contained within the {@link InputRange}.
   */
  public abstract boolean contains(final char character);

  /**
   * Return the first {@link Character} of the range
   * 
   * @return the first {@link Character} of the range
   */
  public abstract char getFrom();

  /**
   * Return the last {@link Character} of the range
   * 
   * @return the last {@link Character} of the range
   */
  public abstract char getTo();
}

@@ -296,32 +296,127 @@
 ialInputRange %7B%0A
+    Any() %7B%0A      // Everything.%0A      super(Character.MIN_VALUE, Character.MAX_VALUE);%0A    %7D%0A%0A
     @Override%0A  
@@ -502,37 +502,34 @@
 ass Eos extends 
-Speci
+Re
 alInputRange %7B%0A 
@@ -519,32 +519,137 @@
 ealInputRange %7B%0A
+    Eos() %7B%0A      // Nothing.%0A      super((char) (Character.MIN_VALUE + 1), Character.MIN_VALUE);%0A    %7D%0A%0A
     @Override%0A  
@@ -757,32 +757,141 @@
 ialInputRange %7B%0A
+    Epsilon() %7B%0A      // Nothing.%0A      super((char) (Character.MIN_VALUE + 2), Character.MIN_VALUE);%0A    %7D%0A%0A
     @Override%0A  
@@ -981,32 +981,36 @@
 utRange extends 
+Real
 InputRange %7B%0A   
@@ -1014,246 +1014,77 @@
     
-@Override%0A    public boolean contains(char character) %7B%0A      return false;%0A    %7D%0A%0A    @Override%0A    public char getFrom() %7B%0A      return Character.MIN_VALUE;%0A    %7D%0A%0A    @Override%0A    public char getTo() %7B%0A      return Character.MIN_VALUE
+private SpecialInputRange(char from, char to) %7B%0A      super(from, to)
 ;%0A  

Clean up InputRange.