001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.collections.primitives.adapters; 018 019import java.util.Iterator; 020 021import org.apache.commons.collections.primitives.BooleanIterator; 022 023/** 024 * Adapts an {@link org.apache.commons.collections.primitives.BooleanIterator 025 * BooleanIterator} to the {@link java.util.Iterator Iterator} interface. 026 * <p /> 027 * This implementation delegates most methods to the provided {@link 028 * org.apache.commons.collections.primitives.BooleanIterator BooleanIterator} 029 * implementation in the "obvious" way. 030 * 031 * @since Commons Primitives 1.1 032 * @version $Revision: 480462 $ $Date: 2006-11-29 03:15:00 -0500 (Wed, 29 Nov 2006) $ 033 */ 034public class BooleanIteratorIterator implements Iterator { 035 036 /** 037 * Create an {@link java.util.Iterator Iterator} wrapping the specified 038 * {@link org.apache.commons.collections.primitives.BooleanIterator 039 * BooleanIterator}. When the given <i>iterator</i> is <code>null</code>, 040 * returns <code>null</code>. 041 * 042 * @param iterator the (possibly <code>null</code>) 043 * {@link org.apache.commons.collections.primitives.BooleanIterator 044 * BooleanIterator} to wrap 045 * @return an {@link java.util.Iterator Iterator} wrapping the given 046 * <i>iterator</i>, or <code>null</code> when <i>iterator</i> is 047 * <code>null</code>. 048 */ 049 public static Iterator wrap(BooleanIterator iterator) { 050 return null == iterator ? null : new BooleanIteratorIterator(iterator); 051 } 052 053 /** 054 * Creates an {@link java.util.Iterator Iterator} wrapping the specified 055 * {@link org.apache.commons.collections.primitives.BooleanIterator 056 * BooleanIterator}. 057 * @see #wrap 058 */ 059 public BooleanIteratorIterator(BooleanIterator iterator) { 060 _iterator = iterator; 061 } 062 063 public boolean hasNext() { 064 return _iterator.hasNext(); 065 } 066 067 public Object next() { 068 return new Boolean(_iterator.next()); 069 } 070 071 public void remove() { 072 _iterator.remove(); 073 } 074 075 private BooleanIterator _iterator = null; 076 077}