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 a {@link Boolean Boolean}-valued {@link java.util.Iterator Iterator}
025 * to the {@link org.apache.commons.collections.primitives.BooleanIterator
026 * BooleanIterator} interface.
027 * <p />
028 * This implementation delegates most methods to the provided {@link
029 * java.util.Iterator Iterator} implementation in the "obvious" way.
030 *
031 * @since Commons Primitives 1.2
032 * @version $Revision: 480462 $
033 */
034public class IteratorBooleanIterator implements BooleanIterator {
035    
036    /**
037     * Create an {@link org.apache.commons.collections.primitives.BooleanIterator
038     * BooleanIterator} wrapping the specified {@link java.util.Iterator
039     * Iterator}.  When the given <i>iterator</i> is <code>null</code>, returns
040     * <code>null</code>.
041     * 
042     * @param iterator the (possibly <code>null</code>)
043     *        {@link java.util.Iterator Iterator} to wrap
044     * @return an {@link
045     * org.apache.commons.collections.primitives.BooleanIterator BooleanIterator}
046     * wrapping the given <i>iterator</i>, or <code>null</code> when <i>
047     * iterator</i> is <code>null</code>.
048     */
049    public static BooleanIterator wrap(Iterator iterator) {
050        return null == iterator ? null : new IteratorBooleanIterator(iterator);
051    }
052   
053    /**
054     * Creates an {@link org.apache.commons.collections.primitives.BooleanIterator
055     * BooleanIterator} wrapping the specified {@link java.util.Iterator Iterator}.
056     * @see #wrap
057     */
058    public IteratorBooleanIterator(Iterator iterator) {
059        _iterator = iterator;
060    }
061    
062    public boolean hasNext() {
063        return _iterator.hasNext();
064    }
065    
066    public boolean next() {
067        return ((Boolean)(_iterator.next())).booleanValue();
068    }
069    
070    public void remove() {
071        _iterator.remove();
072    }
073    
074    private Iterator _iterator = null;
075
076}