aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/slime/ArrayValue.java
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-03-21 12:04:47 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2023-03-21 12:04:47 +0100
commit97237223999b3d53453b114fdc627aa3b812fea6 (patch)
tree78e4083cb26ae69238d52123eef531f566ead918 /vespajlib/src/main/java/com/yahoo/slime/ArrayValue.java
parent01d979598823255af37bd3dde53bea888e31d7b3 (diff)
Implement overloads of native types
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/slime/ArrayValue.java')
-rw-r--r--vespajlib/src/main/java/com/yahoo/slime/ArrayValue.java67
1 files changed, 53 insertions, 14 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/slime/ArrayValue.java b/vespajlib/src/main/java/com/yahoo/slime/ArrayValue.java
index 9f455a5b7d4..63b22d70da2 100644
--- a/vespajlib/src/main/java/com/yahoo/slime/ArrayValue.java
+++ b/vespajlib/src/main/java/com/yahoo/slime/ArrayValue.java
@@ -10,9 +10,11 @@ final class ArrayValue extends Value {
static final Impl initial_impl = new EmptyImpl();
private interface Impl {
- public void prepareFor(ArrayValue self, Type type);
- public Value add(Value value, int used);
- public Value get(int index);
+ void prepareFor(ArrayValue self, Type type);
+ Value add(Value value, int used);
+ Value add(long value, int used);
+ Value add(double value, int used);
+ Value get(int index);
}
private static final class EmptyImpl implements Impl {
@@ -26,6 +28,8 @@ final class ArrayValue extends Value {
}
}
public Value add(Value value, int used) { return NixValue.invalid(); }
+ public Value add(long value, int used) { return NixValue.invalid(); }
+ public Value add(double value, int used) { return NixValue.invalid(); }
public Value get(int index) { return NixValue.invalid(); }
}
@@ -36,15 +40,22 @@ final class ArrayValue extends Value {
self.impl = new GenericImpl(this, self.used);
}
}
+ private static long [] grow(long [] arr) {
+ long [] v = new long[arr.length << 1];
+ System.arraycopy(arr, 0, v, 0, arr.length);
+ return v;
+ }
public Value add(Value value, int used) {
+ return add(value.asLong(), used);
+ }
+ public Value add(long value, int used) {
if (used == values.length) {
- long[] v = values;
- values = new long[v.length << 1];
- System.arraycopy(v, 0, values, 0, used);
+ values = grow(values);
}
- values[used] = value.asLong();
+ values[used] = value;
return get(used);
}
+ public Value add(double value, int used) { return NixValue.invalid(); }
public Value get(int index) { return new LongValue(values[index]); }
}
@@ -55,15 +66,22 @@ final class ArrayValue extends Value {
self.impl = new GenericImpl(this, self.used);
}
}
+ private static double [] grow(double [] arr) {
+ double [] v = new double[arr.length << 1];
+ System.arraycopy(arr, 0, v, 0, arr.length);
+ return v;
+ }
public Value add(Value value, int used) {
+ return add(value.asDouble(), used);
+ }
+ public Value add(double value, int used) {
if (used == values.length) {
- double[] v = values;
- values = new double[v.length << 1];
- System.arraycopy(v, 0, values, 0, used);
+ values = grow(values);
}
- values[used] = value.asDouble();
+ values[used] = value;
return get(used);
}
+ public Value add(long value, int used) { return NixValue.invalid(); }
public Value get(int index) { return new DoubleValue(values[index]); }
}
@@ -80,11 +98,20 @@ final class ArrayValue extends Value {
}
}
public void prepareFor(ArrayValue self, Type type) {}
+ private static Value [] grow(Value [] arr) {
+ Value [] v = new Value[arr.length << 1];
+ System.arraycopy(arr, 0, v, 0, arr.length);
+ return v;
+ }
+ public Value add(long value, int used) {
+ return add(new LongValue(value), used);
+ }
+ public Value add(double value, int used) {
+ return add(new DoubleValue(value), used);
+ }
public Value add(Value value, int used) {
if (used == values.length) {
- Value[] v = values;
- values = new Value[v.length << 1];
- System.arraycopy(v, 0, values, 0, used);
+ values = grow(values);
}
values[used] = value;
return get(used);
@@ -112,6 +139,18 @@ final class ArrayValue extends Value {
}
}
+ @Override
+ public Cursor addLong(long value) {
+ impl.prepareFor(this, Type.LONG);
+ return impl.add(value, used++);
+ }
+
+ @Override
+ public Cursor addDouble(double value) {
+ impl.prepareFor(this, Type.DOUBLE);
+ return impl.add(value, used++);
+ }
+
protected Value addLeaf(Value value) {
impl.prepareFor(this, value.type());
return impl.add(value, used++);