2010-07-16 16:13:12 -04:00
|
|
|
/*
|
2014-04-08 05:46:41 -04:00
|
|
|
* Copyright (C) 2010-2014 Thialfihar <thi@thialfihar.org>
|
2010-07-16 16:13:12 -04:00
|
|
|
*
|
2014-04-08 05:37:38 -04:00
|
|
|
* 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, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2010-07-16 16:13:12 -04:00
|
|
|
*
|
2014-04-08 05:37:38 -04:00
|
|
|
* 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.
|
2010-07-16 16:13:12 -04:00
|
|
|
*
|
2014-04-08 05:37:38 -04:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-07-16 16:13:12 -04:00
|
|
|
*/
|
|
|
|
|
2013-01-16 08:31:16 -05:00
|
|
|
package org.sufficientlysecure.keychain.util;
|
2010-07-16 16:13:12 -04:00
|
|
|
|
2014-03-15 13:15:39 -04:00
|
|
|
import java.util.ArrayList;
|
2010-07-16 16:13:12 -04:00
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
public class IterableIterator<T> implements Iterable<T> {
|
|
|
|
private Iterator<T> mIter;
|
|
|
|
|
2014-03-15 13:15:39 -04:00
|
|
|
public IterableIterator(Iterator<T> iter, boolean failsafe) {
|
2010-07-16 16:13:12 -04:00
|
|
|
mIter = iter;
|
2014-04-01 19:43:40 -04:00
|
|
|
if (failsafe && mIter == null) {
|
2014-03-15 13:15:39 -04:00
|
|
|
// is there a better way?
|
|
|
|
mIter = new ArrayList<T>().iterator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public IterableIterator(Iterator<T> iter) {
|
|
|
|
this(iter, false);
|
2010-07-16 16:13:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public Iterator<T> iterator() {
|
|
|
|
return mIter;
|
|
|
|
}
|
|
|
|
}
|