-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBasePVFloatArray.java
More file actions
118 lines (101 loc) · 2.89 KB
/
BasePVFloatArray.java
File metadata and controls
118 lines (101 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
package org.epics.pvdata.factory;
import java.nio.ByteBuffer;
import java.util.Arrays;
import org.epics.pvdata.pv.DeserializableControl;
import org.epics.pvdata.pv.FloatArrayData;
import org.epics.pvdata.pv.PVFloatArray;
import org.epics.pvdata.pv.ScalarArray;
import org.epics.pvdata.pv.SerializableControl;
import org.epics.util.array.ArrayFloat;
import org.epics.util.array.CollectionNumbers;
/**
* Base class for implementing PVFloatArray.
* @author mrk
*
*/
public class BasePVFloatArray extends AbstractPVScalarArray implements PVFloatArray
{
protected float[] value;
/**
* Constructor.
* @param array The introspection interface.
*/
public BasePVFloatArray(ScalarArray array)
{
super(array);
}
@Override
protected void allocate(int newCapacity) {
value = new float[newCapacity];
capacity = newCapacity;
}
@Override
protected Object getValue()
{
return value;
}
@Override
protected void setValue(Object array)
{
value = (float[])array;
}
@Override
protected int putToBuffer(ByteBuffer buffer, SerializableControl control, int offset, int length)
{
buffer.asFloatBuffer().put(value, offset, length);
buffer.position(buffer.position() + length*4);
return length;
}
@Override
protected int getFromBuffer(ByteBuffer buffer, DeserializableControl control, int offset, int length)
{
buffer.asFloatBuffer().get(value, offset, length);
buffer.position(buffer.position() + length*4);
return length;
}
/* (non-Javadoc)
* @see org.epics.pvdata.pv.PVFloatArray#get(int, int, org.epics.pvdata.pv.FloatArrayData)
*/
@Override
public int get(int offset, int len, FloatArrayData data) {
return internalGet(offset, len, data);
}
@Override
public ArrayFloat get() {
return CollectionNumbers.unmodifiableListFloat(value);
}
/* (non-Javadoc)
* @see org.epics.pvdata.pv.PVFloatArray#put(int, int, float[], int)
*/
@Override
public int put(int offset, int len, float[] from, int fromOffset) {
return internalPut(offset, len, from, fromOffset);
}
/* (non-Javadoc)
* @see org.epics.pvdata.pv.PVFloatArray#shareData(float[])
*/
@Override
public void shareData(float[] from) {
internalShareData(from);
}
@Override
protected boolean valueEquals(Object obj)
{
PVFloatArray b = (PVFloatArray)obj;
FloatArrayData arrayData = new FloatArrayData();
// NOTE: this assumes entire array set to arrayData
b.get(0, b.getLength(), arrayData);
return Arrays.equals(arrayData.data, value);
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return Arrays.hashCode(value);
}
}