325N/A/*
325N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.bind.v2.runtime.reflect;
325N/A
325N/Aimport com.sun.xml.internal.bind.api.AccessorException;
325N/Aimport com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
325N/A
325N/A/**
325N/A * {@link Lister} for primitive type arrays.
325N/A *
325N/A * <p>
325N/A * B y t e ArrayLister is used as the master to generate the rest of the
325N/A * lister classes. Do not modify the generated copies.
325N/A */
325N/Afinal class PrimitiveArrayListerBoolean<BeanT> extends Lister<BeanT,boolean[],Boolean,PrimitiveArrayListerBoolean.BooleanArrayPack> {
325N/A
325N/A private PrimitiveArrayListerBoolean() {
325N/A }
325N/A
325N/A /*package*/ static void register() {
325N/A Lister.primitiveArrayListers.put(Boolean.TYPE,new PrimitiveArrayListerBoolean());
325N/A }
325N/A
325N/A public ListIterator<Boolean> iterator(final boolean[] objects, XMLSerializer context) {
325N/A return new ListIterator<Boolean>() {
325N/A int idx=0;
325N/A public boolean hasNext() {
325N/A return idx<objects.length;
325N/A }
325N/A
325N/A public Boolean next() {
325N/A return objects[idx++];
325N/A }
325N/A };
325N/A }
325N/A
325N/A public BooleanArrayPack startPacking(BeanT current, Accessor<BeanT, boolean[]> acc) {
325N/A return new BooleanArrayPack();
325N/A }
325N/A
325N/A public void addToPack(BooleanArrayPack objects, Boolean o) {
325N/A objects.add(o);
325N/A }
325N/A
325N/A public void endPacking( BooleanArrayPack pack, BeanT bean, Accessor<BeanT,boolean[]> acc ) throws AccessorException {
325N/A acc.set(bean,pack.build());
325N/A }
325N/A
325N/A public void reset(BeanT o,Accessor<BeanT,boolean[]> acc) throws AccessorException {
325N/A acc.set(o,new boolean[0]);
325N/A }
325N/A
325N/A static final class BooleanArrayPack {
325N/A boolean[] buf = new boolean[16];
325N/A int size;
325N/A
325N/A void add(Boolean b) {
325N/A if(buf.length==size) {
325N/A // realloc
325N/A boolean[] nb = new boolean[buf.length*2];
325N/A System.arraycopy(buf,0,nb,0,buf.length);
325N/A buf = nb;
325N/A }
325N/A if(b!=null)
325N/A buf[size++] = b;
325N/A }
325N/A
325N/A boolean[] build() {
325N/A if(buf.length==size)
325N/A // if we are lucky enough
325N/A return buf;
325N/A
325N/A boolean[] r = new boolean[size];
325N/A System.arraycopy(buf,0,r,0,size);
325N/A return r;
325N/A }
325N/A }
325N/A}