com.arcadedb.query.sql.parser.JsonItem Maven / Gradle / Ivy
/*
* Copyright © 2021-present Arcade Data Ltd ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-FileCopyrightText: 2021-present Arcade Data Ltd ([email protected])
* SPDX-License-Identifier: Apache-2.0
*/
package com.arcadedb.query.sql.parser;
import com.arcadedb.query.sql.executor.CommandContext;
import java.util.*;
/**
* Created by luigidellaquila on 18/02/15.
*/
public class JsonItem {
protected Identifier leftIdentifier;
protected String leftString;
protected Expression right;
public void toString(final Map params, final StringBuilder builder) {
if (leftIdentifier != null) {
builder.append("\"");
leftIdentifier.toString(params, builder);
builder.append("\"");
}
if (leftString != null) {
builder.append("\"");
builder.append(Expression.encode(leftString));
builder.append("\"");
}
builder.append(": ");
right.toString(params, builder);
}
public String getLeftValue() {
if (leftString != null) {
return leftString;
}
if (leftIdentifier != null) {
return leftIdentifier.getStringValue();
}
return null;
}
public boolean isAggregate(final CommandContext context) {
return right.isAggregate(context);
}
public JsonItem splitForAggregation(final AggregateProjectionSplit aggregateSplit, final CommandContext context) {
if (isAggregate(context)) {
final JsonItem item = new JsonItem();
item.leftIdentifier = leftIdentifier;
item.leftString = leftString;
item.right = right.splitForAggregation(aggregateSplit, context);
return item;
} else {
return this;
}
}
public JsonItem copy() {
final JsonItem result = new JsonItem();
result.leftIdentifier = leftIdentifier == null ? null : leftIdentifier.copy();
result.leftString = leftString;
result.right = right.copy();
return result;
}
public void extractSubQueries(final SubQueryCollector collector) {
right.extractSubQueries(collector);
}
public boolean refersToParent() {
return right != null && right.refersToParent();
}
@Override
public boolean equals(final Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
final JsonItem oJsonItem = (JsonItem) o;
if (!Objects.equals(leftIdentifier, oJsonItem.leftIdentifier))
return false;
if (!Objects.equals(leftString, oJsonItem.leftString))
return false;
return Objects.equals(right, oJsonItem.right);
}
@Override
public int hashCode() {
int result = leftIdentifier != null ? leftIdentifier.hashCode() : 0;
result = 31 * result + (leftString != null ? leftString.hashCode() : 0);
result = 31 * result + (right != null ? right.hashCode() : 0);
return result;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy