001/*
002 * Copyright (c) 2007-2017 Xplenty, 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
021package cascading.flow.hadoop.util;
022
023import java.util.Collection;
024import java.util.Collections;
025import java.util.Iterator;
026
027import cascading.tuple.Tuple;
028
029/**
030 *
031 */
032public class FalseCollection implements Collection<Tuple>, ResettableCollection<Iterator<Tuple>>
033  {
034  boolean returnedIterator = false;
035  Iterator<Tuple> iterator;
036
037  @Override
038  public void reset( Iterator<Tuple> iterator )
039    {
040    this.returnedIterator = false;
041    this.iterator = iterator;
042    }
043
044  @Override
045  public int size()
046    {
047    return 0;
048    }
049
050  @Override
051  public boolean isEmpty()
052    {
053    return iterator == null || !iterator.hasNext();
054    }
055
056  @Override
057  public boolean contains( Object o )
058    {
059    return false;
060    }
061
062  @Override
063  public Iterator<Tuple> iterator()
064    {
065    if( returnedIterator )
066      throw new IllegalStateException( "may not iterate this tuple stream more than once" );
067
068    try
069      {
070      if( iterator == null )
071        return Collections.emptyIterator();
072
073      return iterator;
074      }
075    finally
076      {
077      returnedIterator = true;
078      }
079    }
080
081  @Override
082  public Object[] toArray()
083    {
084    return new Object[ 0 ];
085    }
086
087  @Override
088  public <T> T[] toArray( T[] a )
089    {
090    return null;
091    }
092
093  @Override
094  public boolean add( Tuple tuple )
095    {
096    return false;
097    }
098
099  @Override
100  public boolean remove( Object o )
101    {
102    return false;
103    }
104
105  @Override
106  public boolean containsAll( Collection<?> c )
107    {
108    return false;
109    }
110
111  @Override
112  public boolean addAll( Collection<? extends Tuple> c )
113    {
114    return false;
115    }
116
117  @Override
118  public boolean removeAll( Collection<?> c )
119    {
120    return false;
121    }
122
123  @Override
124  public boolean retainAll( Collection<?> c )
125    {
126    return false;
127    }
128
129  @Override
130  public void clear()
131    {
132    iterator = null;
133    }
134  }