Java Iterator fillArray(Iterator ii, Object[] fillMe, boolean null_terminate)

Here you can find the source of fillArray(Iterator ii, Object[] fillMe, boolean null_terminate)

Description

Fills an array with the contents of an iterator.

License

Open Source License

Parameter

Parameter Description
null_terminate iff there is extra space in the array, set the element immediately after the last from the iterator to null.

Declaration

public static void fillArray(Iterator ii, Object[] fillMe, boolean null_terminate) 

Method Source Code


//package com.java2s;
/*/*from w  ww.  ja v a  2 s.c o  m*/
 * Distributed as part of debuggen v.0.1.0
 *
 * Copyright (C) 2005 Machinery For Change, Inc.
 *
 * Author: Steve Waldman <swaldman@mchange.com>
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 2.1, as 
 * published by the Free Software Foundation.
 *
 * This software 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this software; see the file LICENSE.  If not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 */

import java.util.*;

public class Main {
    /**
     * Fills an array with the contents of an iterator. If the array is too small,
     * it will contain the first portion of the iterator. If the array can contain
     * more elements than the iterator, extra elements are left untouched, unless
     * null_terminate is set to true, in which case the element immediately following
     * the last from the iterator is set to null. (This method is intended to make
     * it easy to implement Collection.toArray(Object[] oo) methods...
     *
     * @param null_terminate iff there is extra space in the array, set the element
     *        immediately after the last from the iterator to null.
     */
    public static void fillArray(Iterator ii, Object[] fillMe, boolean null_terminate) {
        int i = 0;
        int len = fillMe.length;
        while (i < len && ii.hasNext())
            fillMe[i++] = ii.next();
        if (null_terminate && i < len)
            fillMe[i] = null;
    }

    public static void fillArray(Iterator ii, Object[] fillMe) {
        fillArray(ii, fillMe, false);
    }
}

Related

  1. createSkipIterator(Iterable source, int count)
  2. dump(Iterator it)
  3. endOfData(Iterator inputIter, Iterator resultIter)
  4. equalsIterator(Iterator it, Iterator it2)
  5. fill(final Iterator iterator, final S collection)
  6. fillCollection(final Iterator iterator, final Collection collection)
  7. fillCollection(final Iterator iterator, final Collection collection)
  8. firstOrDefault(Iterator iterator)
  9. fmtSeq(Iterator it, String divider)