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

org.petitparser.grammar.xml.ast.XmlParent Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
package org.petitparser.grammar.xml.ast;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

/**
 * Abstract XML node with actual children.
 */
public abstract class XmlParent extends XmlNode {

  private final List children;

  public XmlParent(Collection children) {
    this.children = new ArrayList<>(children);
    for (XmlNode child : children) {
      child.setParent(this);
    }
  }

  @Override
  public List getChildren() {
    return children;
  }

  @Override
  public void writeTo(StringBuilder buffer) {
    for (XmlNode node : getChildren()) {
      node.writeTo(buffer);
    }
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null || getClass() != obj.getClass()) {
      return false;
    }
    XmlParent other = (XmlParent) obj;
    return Objects.equals(children, other.children);
  }

  @Override
  public int hashCode() {
    return children.size();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy