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