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

com.orientechnologies.orient.core.sql.parser.OGroupBy Maven / Gradle / Ivy

There is a newer version: 3.2.32
Show newest version
/* Generated By:JJTree: Do not edit this line. OGroupBy.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;

import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.executor.OResultInternal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class OGroupBy extends SimpleNode {

  protected List items = new ArrayList();

  public OGroupBy(int id) {
    super(id);
  }

  public OGroupBy(OrientSql p, int id) {
    super(p, id);
  }

  public void toString(Map params, StringBuilder builder) {
    builder.append("GROUP BY ");
    for (int i = 0; i < items.size(); i++) {
      if (i > 0) {
        builder.append(", ");
      }
      items.get(i).toString(params, builder);
    }
  }

  public void toGenericStatement(StringBuilder builder) {
    builder.append("GROUP BY ");
    for (int i = 0; i < items.size(); i++) {
      if (i > 0) {
        builder.append(", ");
      }
      items.get(i).toGenericStatement(builder);
    }
  }

  public List getItems() {
    return items;
  }

  public void addItem(OExpression item) {
    this.items.add(item);
  }

  public OGroupBy copy() {
    OGroupBy result = new OGroupBy(-1);
    result.items = items.stream().map(x -> x.copy()).collect(Collectors.toList());
    return result;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    OGroupBy oGroupBy = (OGroupBy) o;

    if (items != null ? !items.equals(oGroupBy.items) : oGroupBy.items != null) return false;

    return true;
  }

  @Override
  public int hashCode() {
    return items != null ? items.hashCode() : 0;
  }

  public void extractSubQueries(SubQueryCollector collector) {
    for (OExpression item : items) {
      item.extractSubQueries(collector);
    }
  }

  public boolean refersToParent() {
    for (OExpression item : items) {
      if (item.refersToParent()) {
        return true;
      }
    }
    return false;
  }

  public OResult serialize() {
    OResultInternal result = new OResultInternal();
    if (items != null) {
      result.setProperty(
          "items", items.stream().map(x -> x.serialize()).collect(Collectors.toList()));
    }
    return result;
  }

  public void deserialize(OResult fromResult) {

    if (fromResult.getProperty("items") != null) {
      List ser = fromResult.getProperty("items");
      items = new ArrayList<>();
      for (OResult r : ser) {
        OExpression exp = new OExpression(-1);
        exp.deserialize(r);
        items.add(exp);
      }
    }
  }
}
/* JavaCC - OriginalChecksum=4739190aa6c1a3533a89b76a15bd6fdf (do not edit this line) */




© 2015 - 2024 Weber Informatics LLC | Privacy Policy