View Javadoc

    1   package groovy.lang;
    2
    3   import org.codehaus.groovy.runtime.InvokerHelper;
    4
    5   import java.util.*;
    6
    7   /***
    8    * Constructing Ranges like 0..<0
    9    * @author Dierk Koenig
    10   */
    11  public class EmptyRange implements Range {
    12      protected Comparable at = null;
    13      protected final List EMPTY_LIST = new ArrayList();
    14
    15      public EmptyRange(Comparable at) {
    16         this.at = at;
    17      }
    18
    19      public Comparable getFrom() {
    20          return at;
    21      }
    22
    23      public Comparable getTo() {
    24          return at;
    25      }
    26
    27      public boolean isReverse() {
    28          return false;
    29      }
    30
    31      public String inspect() {
    32          return InvokerHelper.inspect(at)+"..<"+InvokerHelper.inspect(at);
    33      }
    34
    35      public String toString() {
    36          if (null == at) return "null..<null";
    37          return at.toString()+"..<"+at.toString();
    38      }
    39
    40      public int size() {
    41          return 0;
    42      }
    43
    44      public void clear() {
    45      }
    46
    47      public boolean isEmpty() {
    48          return true;
    49      }
    50
    51      public Object[] toArray() {
    52          return new Object[0];
    53      }
    54
    55      public Object get(int index) {
    56          return null;
    57      }
    58
    59      public Object remove(int index) {
    60          return null;
    61      }
    62
    63      /***
    64       * @throws UnsupportedOperationException
    65       */
    66      public void add(int index, Object element) {
    67          throw new UnsupportedOperationException("cannot add to Empty Ranges");
    68      }
    69
    70      public int indexOf(Object o) {
    71          return -1;
    72      }
    73
    74      public int lastIndexOf(Object o) {
    75          return -1;
    76      }
    77
    78      /***
    79       * @throws UnsupportedOperationException
    80       */
    81      public boolean add(Object o) {
    82          throw new UnsupportedOperationException("cannot add to Empty Ranges");
    83      }
    84
    85      public boolean contains(Object o) {
    86          return false;
    87      }
    88
    89      public boolean remove(Object o) {
    90          return false;
    91      }
    92
    93      /***
    94       * @throws UnsupportedOperationException
    95       */
    96      public boolean addAll(int index, Collection c) {
    97          throw new UnsupportedOperationException("cannot add to Empty Ranges");
    98      }
    99
    100      /***
    101      * @throws UnsupportedOperationException
    102      */
    103     public boolean addAll(Collection c) {
    104         throw new UnsupportedOperationException("cannot add to Empty Ranges");
    105     }
    106
    107     public boolean containsAll(Collection c) {
    108         return false;
    109     }
    110
    111     public boolean removeAll(Collection c) {
    112         return false;
    113     }
    114
    115     public boolean retainAll(Collection c) {
    116         return false;
    117     }
    118
    119     public Iterator iterator() {
    120         return EMPTY_LIST.iterator();
    121     }
    122
    123     public List subList(int fromIndex, int toIndex) {
    124         return EMPTY_LIST.subList(fromIndex, toIndex);
    125     }
    126
    127     public ListIterator listIterator() {
    128         return EMPTY_LIST.listIterator();
    129     }
    130
    131     public ListIterator listIterator(int index) {
    132         return EMPTY_LIST.listIterator(index);
    133     }
    134
    135      /***
    136      * @throws UnsupportedOperationException
    137      */
    138     public Object set(int index, Object element) {
    139         throw new UnsupportedOperationException("cannot set in Empty Ranges");
    140     }
    141
    142     public Object[] toArray(Object a[]) {
    143         return new Object[0];
    144     }
    145
    146     public void step(int step, Closure closure) {
    147     }
    148
    149     public List step(int step) {
    150         return EMPTY_LIST;
    151     }
    152 }