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