1 /*
2  * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Distribution License v. 1.0, which is available at
6  * http://www.eclipse.org/org/documents/edl-v10.php.
7  *
8  * SPDX-License-Identifier: BSD-3-Clause
9  */

10
11 package com.sun.xml.bind.v2.runtime.reflect;
12
13 import com.sun.xml.bind.api.AccessorException;
14 import com.sun.xml.bind.v2.runtime.XMLSerializer;
15
16 /**
17  * {@link Lister} for primitive type arrays.
18  * <p><b>
19  *     Auto-generated, do not edit.
20  * </b></p>
21  * <p>
22  *     B y t e ArrayLister is used as the master to generate the rest of the
23  *     lister classes. Do not modify the generated copies.
24  * </p>
25  */

26 final class PrimitiveArrayListerDouble<BeanT> extends Lister<BeanT,double[],Double,PrimitiveArrayListerDouble.DoubleArrayPack> {
27     
28     private PrimitiveArrayListerDouble() {
29     }
30
31     /*package*/ static void register() {
32         Lister.primitiveArrayListers.put(Double.TYPE,new PrimitiveArrayListerDouble());
33     }
34
35     public ListIterator<Double> iterator(final double[] objects, XMLSerializer context) {
36         return new ListIterator<Double>() {
37             int idx=0;
38             public boolean hasNext() {
39                 return idx<objects.length;
40             }
41
42             public Double next() {
43                 return objects[idx++];
44             }
45         };
46     }
47
48     public DoubleArrayPack startPacking(BeanT current, Accessor<BeanT, double[]> acc) {
49         return new DoubleArrayPack();
50     }
51
52     public void addToPack(DoubleArrayPack objects, Double o) {
53         objects.add(o);
54     }
55
56     public void endPacking( DoubleArrayPack pack, BeanT bean, Accessor<BeanT,double[]> acc ) throws AccessorException {
57         acc.set(bean,pack.build());
58     }
59
60     public void reset(BeanT o,Accessor<BeanT,double[]> acc) throws AccessorException {
61         acc.set(o,new double[0]);
62     }
63
64     static final class DoubleArrayPack {
65         double[] buf = new double[16];
66         int size;
67
68         void add(Double b) {
69             if(buf.length==size) {
70                 // realloc
71                 double[] nb = new double[buf.length*2];
72                 System.arraycopy(buf,0,nb,0,buf.length);
73                 buf = nb;
74             }
75             if(b!=null)
76                 buf[size++] = b;
77         }
78
79         double[] build() {
80             if(buf.length==size)
81                 // if we are lucky enough
82                 return buf;
83
84             double[] r = new double[size];
85             System.arraycopy(buf,0,r,0,size);
86             return r;
87         }
88     }
89 }
90