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

com.squarespace.cldrengine.internal.PartsValue Maven / Gradle / Ivy

The newest version!
package com.squarespace.cldrengine.internal;

import java.util.ArrayList;
import java.util.List;

import com.squarespace.cldrengine.api.Part;
import com.squarespace.cldrengine.parsing.WrapperPattern;

public class PartsValue implements AbstractValue> {

  private ArrayList parts = new ArrayList<>();

  public int length() {
    return this.parts.size();
  }

  public String get(int i) {
    return i < this.parts.size() ? this.parts.get(i).value : "";
  }

  public void add(String type, String value) {
    this.parts.add(new Part(type, value));
  }

  public void append(List value) {
    this.parts.addAll(value);
  }

  public void insert(int i, String type, String value) {
    this.parts.add(i, new Part(type, value));
  }

  public List render() {
    List p = this.parts;
    this.parts = new ArrayList<>();
    return p;
  }

  public void reset() {
    this.parts = new ArrayList<>();
  }

  public List join(List> lists) {
    List res = new ArrayList<>();
    for (List lst : lists) {
      res.addAll(lst);
    }
    return res;
  }

  public void wrap(WrapperPattern pattern, List> args) {
    for (Object node : pattern.nodes) {
      if (node instanceof String) {
        this.add("literal", (String)node);
      } else {
        int idx = (int) node;
        if (idx < args.size()) {
          List arg = args.get(idx);
          if (arg != null) {
            for (Part part : arg) {
              this.parts.add(part);
            }
          }
        }
      }
    }
  }

  public List empty() {
    return new ArrayList<>();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy