com.magicsoftbay.qbuildersandroid.conditions.Condition Maven / Gradle / Ivy
Show all versions of q-builders-android Show documentation
/*
* The MIT License (MIT)
*
* Copyright (c) 2018 MAGIC SOFTWARE BAY SRL
* Copyright (c) 2016 Paul Rutledge
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.magicsoftbay.qbuildersandroid.conditions;
import com.magicsoftbay.qbuildersandroid.builders.QBuilder;
import com.magicsoftbay.qbuildersandroid.nodes.AndNode;
import com.magicsoftbay.qbuildersandroid.nodes.ComparisonNode;
import com.magicsoftbay.qbuildersandroid.nodes.OrNode;
import com.magicsoftbay.qbuildersandroid.visitors.ContextualNodeVisitor;
import java.util.List;
/**
* A logically complete condition that can either be met or not met by an object.
* Intended to be composed into more complex conditions, or built into a query
* that can be executed against a set of objects to determine those things
* which satisfy the criteria.
*
* @param The final type of the builder, used for a fluid chaining interface.
* @author Paul Rutledge
* @author Clivens Petit
*/
public interface Condition> {
/**
* Prepare to append another condition onto the current node in the condition tree
* in such a way that both the preceeding condition AND the next condition
* specified must be met in order to match an object.
*
* If more flexibility surrounding precedence is needed than what chaining provides,
* please see {@link Partial#and(List)} and {@link Partial#or(List)}.
*
* @return The beginnings of another condition.
*/
T and();
/**
* Prepare to append another condition onto the current node in the condition tree
* in such a way that both the preceeding condition OR the next condition
* specified must be met in order to match an object.
*
* If more flexibility surrounding precedence is needed than what chaining provides,
* please see {@link Partial#and(List)} and {@link Partial#or(List)}.
*
* @return The beginnings of another condition.
*/
T or();
/**
* Given this logically complete condition, execute a node visitor against the
* underlying condition tree in order to build a query or predicate against which
* objects can be queried / tested.
*
* @param visitor The visitor which specifies how to traverse the nodes in the visitor tree.
* Nodes can be {@link AndNode}s or {@link OrNode}s or {@link ComparisonNode}s.
* @param The type of the results returned from visiting any node in the tree.
* @return The result of the visitor's execution.
*/
Q query(ContextualNodeVisitor visitor);
/**
* Given this logically complete condition, execute a node visitor against the
* underlying condition tree in order to build a query or predicate against which
* objects can be queried / tested.
*
* @param visitor The visitor which specifies how to traverse the nodes in the visitor tree.
* Nodes can be {@link AndNode}s or {@link OrNode}s or {@link ComparisonNode}s.
* @param The type of the results returned from visiting any node in the tree.
* @return The result of the visitor's execution.
*/
Q query(ContextualNodeVisitor visitor, S context);
}