Ejemplo n.º 1
0
  @Override
  public void print(
      ChronoDisplay formattable,
      Appendable buffer,
      AttributeQuery attributes,
      Set<ElementPosition> positions, // optional
      FormatStep step)
      throws IOException {

    if (buffer instanceof CharSequence) {
      CharSequence cs = (CharSequence) buffer;
      int offset = cs.length();
      this.element.print(formattable, buffer, step.getQuery(attributes));

      if (positions != null) {
        positions.add(new ElementPosition(this.element, offset, cs.length()));
      }
    } else {
      this.element.print(formattable, buffer, step.getQuery(attributes));
    }
  }
Ejemplo n.º 2
0
  @Override
  public void parse(
      CharSequence text,
      ParseLog status,
      AttributeQuery attributes,
      Map<ChronoElement<?>, Object> parsedResult,
      FormatStep step) {

    int start = status.getPosition();
    int len = text.length();

    int protectedChars =
        step.getAttribute(Attributes.PROTECTED_CHARACTERS, attributes, 0).intValue();

    if (protectedChars > 0) {
      len -= protectedChars;
    }

    if (start >= len) {
      status.setError(start, "Missing chars for: " + this.element.name());
      status.setWarning();
      return;
    }

    TextElement<?> te = TextElement.class.cast(this.element);
    Object value = te.parse(text, status.getPP(), step.getQuery(attributes));

    if (status.isError()) {
      Class<V> valueType = this.element.getType();
      if (valueType.isEnum()) {
        status.setError(status.getErrorIndex(), "No suitable enum found: " + valueType.getName());
      }
    } else {
      if (value == null) {
        status.setError(start, "No interpretable value.");
      } else {
        parsedResult.put(this.element, value);
      }
    }
  }