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