com.bigdata.striterator.Dechunkerator Maven / Gradle / Ivy
/**
Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
Contact:
SYSTAP, LLC DBA Blazegraph
2501 Calvert ST NW #106
Washington, DC 20008
[email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Created on Sep 6, 2010
*/
package com.bigdata.striterator;
import java.util.Arrays;
import java.util.Iterator;
import cutthecrap.utils.striterators.Expander;
import cutthecrap.utils.striterators.ICloseable;
import cutthecrap.utils.striterators.ICloseableIterator;
import cutthecrap.utils.striterators.Striterator;
/**
* Wrap an iterator visiting chunks as an iterator visiting the individual
* elements in each chunk.
*
* @param
* The generic type of the elements in the chunks.
*
* @author Bryan Thompson
* @version $Id$
*
* @see CloseableChunkedIteratorWrapperConverter
*/
public class Dechunkerator implements ICloseableIterator {
/**
* The iterator given to the constructor.
*/
private final Iterator src;
/**
* The iterator which visits the unchunked elements.
*/
private final Iterator itr;
/**
* Wrap an iterator visiting chunks as an iterator visiting the individual
* elements in each chunk.
*
* @param src
* An iterator visiting chunks of type
*/
@SuppressWarnings("unchecked")
public Dechunkerator(final Iterator src) {
this.src = src;
itr = new Striterator(src).addFilter(new Expander() {
private static final long serialVersionUID = 1L;
@Override
protected Iterator expand(final Object e) {
return Arrays.asList((E[]) e).iterator();
}
});
}
@Override
public boolean hasNext() {
return itr.hasNext();
}
@Override
public E next() {
return itr.next();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
@Override
public void close() {
if (src instanceof ICloseable) {
((ICloseable) src).close();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy