com.arcadedb.query.sql.parser.ContainsAllCondition 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
*/
/* Generated By:JJTree: Do not edit this line. OContainsAllCondition.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_USERTYPE_VISIBILITY_PUBLIC=true */
package com.arcadedb.query.sql.parser;
import com.arcadedb.database.Identifiable;
import com.arcadedb.query.sql.executor.CommandContext;
import com.arcadedb.query.sql.executor.MultiValue;
import com.arcadedb.query.sql.executor.Result;
import java.util.*;
public class ContainsAllCondition extends BooleanExpression {
protected Expression left;
protected Expression right;
protected OrBlock rightBlock;
public ContainsAllCondition(final int id) {
super(id);
}
public boolean execute(Object left, Object right) {
if (left instanceof Collection) {
if (right instanceof Collection) {
return ((Collection) left).containsAll((Collection) right);
}
if (right instanceof Iterable) {
right = ((Iterable) right).iterator();
}
if (right instanceof Iterator) {
final Iterator iterator = (Iterator) right;
while (iterator.hasNext()) {
final Object next = iterator.next();
if (!((Collection) left).contains(next)) {
return false;
}
}
}
return ((Collection) left).contains(right);
}
if (left instanceof Iterable) {
left = ((Iterable) left).iterator();
}
if (left instanceof Iterator) {
if (!(right instanceof Iterable)) {
right = Collections.singleton(right);
}
right = ((Iterable) right).iterator();
final Iterator leftIterator = (Iterator) left;
final Iterator rightIterator = (Iterator) right;
while (rightIterator.hasNext()) {
final Object leftItem = rightIterator.next();
boolean found = false;
while (leftIterator.hasNext()) {
final Object rightItem = leftIterator.next();
if (leftItem != null && leftItem.equals(rightItem)) {
found = true;
break;
}
}
if (!found) {
return false;
}
}
return true;
}
return false;
}
@Override
public Boolean evaluate(final Identifiable currentRecord, final CommandContext context) {
final Object leftValue = left.execute(currentRecord, context);
if (right != null) {
final Object rightValue = right.execute(currentRecord, context);
return execute(leftValue, rightValue);
} else {
if (!MultiValue.isMultiValue(leftValue)) {
return false;
}
final Iterator
© 2015 - 2024 Weber Informatics LLC | Privacy Policy