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.ListIterator;
020
021import org.apache.commons.collections.primitives.BooleanListIterator;
022
023/**
024 * Adapts a {@link Number}-valued {@link ListIterator ListIterator} 
025 * to the {@link BooleanListIterator BooleanListIterator} interface.
026 * <p />
027 * This implementation delegates most methods
028 * to the provided {@link BooleanListIterator BooleanListIterator} 
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 * @author Rodney Waldhoff 
034 */
035public class ListIteratorBooleanListIterator implements BooleanListIterator {
036        
037    /**
038     * Create an {@link BooleanListIterator BooleanListIterator} wrapping
039     * the specified {@link ListIterator ListIterator}.  When
040     * the given <i>iterator</i> is <code>null</code>,
041     * returns <code>null</code>.
042     * 
043     * @param iterator the (possibly <code>null</code>) 
044     *        {@link ListIterator ListIterator} to wrap
045     * @return an {@link BooleanListIterator BooleanListIterator} wrapping the given 
046     *         <i>iterator</i>, or <code>null</code> when <i>iterator</i> is
047     *         <code>null</code>.
048     */
049    public static BooleanListIterator wrap(ListIterator iterator) {
050        return null == iterator ? null : new ListIteratorBooleanListIterator(iterator);
051    }    
052    
053    /**
054     * Creates an {@link BooleanListIterator BooleanListIterator} wrapping
055     * the specified {@link ListIterator ListIterator}.
056     * @see #wrap
057     */
058    public ListIteratorBooleanListIterator(ListIterator iterator) {
059        _iterator = iterator;
060    }
061    
062    public int nextIndex() {
063        return _iterator.nextIndex();
064    }
065
066    public int previousIndex() {
067        return _iterator.previousIndex();
068    }
069
070    public boolean hasNext() {
071        return _iterator.hasNext();
072    }
073
074    public boolean hasPrevious() {
075        return _iterator.hasPrevious();
076    }
077    
078    public boolean next() {
079        return ((Boolean)_iterator.next()).booleanValue();
080    }
081
082    public boolean previous() {
083        return ((Boolean)_iterator.previous()).booleanValue();
084    }
085
086    public void add(boolean element) {
087        _iterator.add(new Boolean(element));
088    }
089      
090    public void set(boolean element) {
091        _iterator.set(new Boolean(element));
092    }
093
094    public void remove() {
095        _iterator.remove();
096    }
097      
098    private ListIterator _iterator = null;
099
100}