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

io.honeybadger.com.github.mustachejava.util.NodeValue Maven / Gradle / Ivy

There is a newer version: 2.1.2
Show newest version
package com.github.mustachejava.util;

import java.util.List;
import java.util.Objects;

public class NodeValue {
  private final List list;
  private final String value;
  private final boolean isList;

  private NodeValue(List list, String value) {
    this.list = list;
    isList = list != null;
    this.value = value;
  }

  public static NodeValue list(List list) {
    return new NodeValue(list, null);
  }

  public static NodeValue value(String value) {
    return new NodeValue(null, value);
  }

  public boolean isList() {
    return isList;
  }

  public List list() {
    return list;
  }

  public String value() {
    return value;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    NodeValue nodeValue = (NodeValue) o;
    return Objects.equals(list, nodeValue.list) &&
            Objects.equals(value, nodeValue.value);
  }

  @Override
  public int hashCode() {
    int result = list != null ? list.hashCode() : 0;
    result = 31 * result + (value != null ? value.hashCode() : 0);
    return result;
  }

  @Override
  public String toString() {
    return isList ? list.toString() : value;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy