001    package groovy.lang;
002    
003    import org.codehaus.groovy.runtime.InvokerHelper;
004    
005    import java.util.*;
006    
007    /**
008     * Constructing Ranges like 0..<0
009     * @author Dierk Koenig
010     */
011    public class EmptyRange implements Range {
012        protected Comparable at = null;
013        protected final List EMPTY_LIST = new ArrayList();
014    
015        public EmptyRange(Comparable at) {
016           this.at = at;
017        }
018    
019        public Comparable getFrom() {
020            return at;
021        }
022    
023        public Comparable getTo() {
024            return at;
025        }
026    
027        public boolean isReverse() {
028            return false;
029        }
030    
031        public String inspect() {
032            return InvokerHelper.inspect(at)+"..<"+InvokerHelper.inspect(at);
033        }
034    
035        public String toString() {
036            if (null == at) return "null..<null";
037            return at.toString()+"..<"+at.toString();
038        }
039    
040        public int size() {
041            return 0;
042        }
043    
044        public void clear() {
045        }
046    
047        public boolean isEmpty() {
048            return true;
049        }
050    
051        public Object[] toArray() {
052            return new Object[0];
053        }
054    
055        public Object get(int index) {
056            return null;
057        }
058    
059        public Object remove(int index) {
060            return null;
061        }
062    
063        /**
064         * @throws UnsupportedOperationException
065         */
066        public void add(int index, Object element) {
067            throw new UnsupportedOperationException("cannot add to Empty Ranges");
068        }
069    
070        public int indexOf(Object o) {
071            return -1;
072        }
073    
074        public int lastIndexOf(Object o) {
075            return -1;
076        }
077    
078        /**
079         * @throws UnsupportedOperationException
080         */
081        public boolean add(Object o) {
082            throw new UnsupportedOperationException("cannot add to Empty Ranges");
083        }
084    
085        public boolean contains(Object o) {
086            return false;
087        }
088    
089        public boolean remove(Object o) {
090            return false;
091        }
092    
093        /**
094         * @throws UnsupportedOperationException
095         */
096        public boolean addAll(int index, Collection c) {
097            throw new UnsupportedOperationException("cannot add to Empty Ranges");
098        }
099    
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    }