All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.launchdarkly.sdk.LDValueArray Maven / Gradle / Ivy

There is a newer version: 2.1.1
Show newest version
package com.launchdarkly.sdk;

import com.google.gson.annotations.JsonAdapter;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

import static java.util.Collections.unmodifiableList;

@JsonAdapter(LDValueTypeAdapter.class)
final class LDValueArray extends LDValue {
  private static final LDValueArray EMPTY = new LDValueArray(Collections.emptyList());
  private final List list;
  // Note that this is not  

  static LDValueArray fromList(List list) {
    return list.isEmpty() ? EMPTY : new LDValueArray(list);
  }

  private LDValueArray(List list) {
    this.list = unmodifiableList(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();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy