001    /*
002     * Copyright (c) 2007-2014 Concurrent, Inc. All Rights Reserved.
003     *
004     * Project and contact information: http://www.cascading.org/
005     *
006     * This file is part of the Cascading project.
007     *
008     * Licensed under the Apache License, Version 2.0 (the "License");
009     * you may not use this file except in compliance with the License.
010     * You may obtain a copy of the License at
011     *
012     *     http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing, software
015     * distributed under the License is distributed on an "AS IS" BASIS,
016     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017     * See the License for the specific language governing permissions and
018     * limitations under the License.
019     */
020    
021    package cascading.flow.hadoop.util;
022    
023    import java.util.Collection;
024    import java.util.Collections;
025    import java.util.Iterator;
026    
027    import cascading.tuple.Tuple;
028    
029    /**
030     *
031     */
032    public class FalseCollection implements Collection<Tuple>
033      {
034      boolean returnedIterator = false;
035      Iterator<Tuple> iterator;
036    
037      public void setIterator( Iterator<Tuple> iterator )
038        {
039        this.returnedIterator = false;
040        this.iterator = iterator;
041        }
042    
043      @Override
044      public int size()
045        {
046        return 0;
047        }
048    
049      @Override
050      public boolean isEmpty()
051        {
052        return iterator == null;
053        }
054    
055      @Override
056      public boolean contains( Object o )
057        {
058        return false;
059        }
060    
061      @Override
062      public Iterator<Tuple> iterator()
063        {
064        if( returnedIterator )
065          throw new IllegalStateException( "may not iterate this tuple stream more than once" );
066    
067        try
068          {
069          if( iterator == null )
070            return Collections.EMPTY_LIST.iterator();
071    
072          return iterator;
073          }
074        finally
075          {
076          returnedIterator = true;
077          }
078        }
079    
080      @Override
081      public Object[] toArray()
082        {
083        return new Object[ 0 ];
084        }
085    
086      @Override
087      public <T> T[] toArray( T[] a )
088        {
089        return null;
090        }
091    
092      @Override
093      public boolean add( Tuple tuple )
094        {
095        return false;
096        }
097    
098      @Override
099      public boolean remove( Object o )
100        {
101        return false;
102        }
103    
104      @Override
105      public boolean containsAll( Collection<?> c )
106        {
107        return false;
108        }
109    
110      @Override
111      public boolean addAll( Collection<? extends Tuple> c )
112        {
113        return false;
114        }
115    
116      @Override
117      public boolean removeAll( Collection<?> c )
118        {
119        return false;
120        }
121    
122      @Override
123      public boolean retainAll( Collection<?> c )
124        {
125        return false;
126        }
127    
128      @Override
129      public void clear()
130        {
131        iterator = null;
132        }
133      }