
com.launchdarkly.client.value.LDValueArray Maven / Gradle / Ivy
package com.launchdarkly.client.value;
import com.google.common.collect.ImmutableList;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
@JsonAdapter(LDValueTypeAdapter.class)
final class LDValueArray extends LDValue {
private static final LDValueArray EMPTY = new LDValueArray(ImmutableList.of());
private final ImmutableList list;
static LDValueArray fromList(ImmutableList list) {
return list.isEmpty() ? EMPTY : new LDValueArray(list);
}
private LDValueArray(ImmutableList list) {
this.list = list;
}
public LDValueType getType() {
return LDValueType.ARRAY;
}
@Override
public int size() {
return list.size();
}
@Override
public Iterable values() {
return list;
}
@Override
public LDValue get(int index) {
if (index >= 0 && index < list.size()) {
return list.get(index);
}
return ofNull();
}
@Override
void write(JsonWriter writer) throws IOException {
writer.beginArray();
for (LDValue v: list) {
v.write(writer);
}
writer.endArray();
}
@Override
@SuppressWarnings("deprecation")
JsonElement computeJsonElement() {
JsonArray a = new JsonArray();
for (LDValue item: list) {
a.add(item.asUnsafeJsonElement());
}
return a;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy