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

org.vertexium.cypher.VertexiumCypherQueryResult Maven / Gradle / Ivy

There is a newer version: 4.10.0
Show newest version
package org.vertexium.cypher;

import com.google.common.collect.ImmutableList;

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

public class VertexiumCypherQueryResult {
    private final String[] columnNames;
    private List rows;

    public VertexiumCypherQueryResult(String[] columnNames, List rows) {
        this.columnNames = columnNames;
        this.rows = rows;
    }

    public static VertexiumCypherQueryResult createEmpty() {
        return new VertexiumCypherQueryResult(new String[0], ImmutableList.of());
    }

    public String[] getColumnNames() {
        return columnNames;
    }

    public List getRows() {
        return rows;
    }

    public VertexiumCypherQueryResult concat(VertexiumCypherQueryResult newResults, boolean all) {
        List newRows = new ArrayList<>();
        newRows.addAll(getRows());
        if (all) {
            newRows.addAll(newResults.getRows());
        } else {
            for (Row row : newResults.getRows()) {
                if (!getRows().contains(row)) {
                    newRows.add(row);
                }
            }
        }
        return new VertexiumCypherQueryResult(columnNames, newRows);
    }

    public static class Row {
        private final List columns;

        public Row(List columns) {
            this.columns = columns;
        }

        public List getColumns() {
            return columns;
        }

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

            Row row = (Row) o;

            return columns.equals(row.columns);
        }

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