Search in sources :

Example 1 with CompositeRange

use of datawave.query.composite.CompositeRange in project datawave by NationalSecurityAgency.

the class ExpandCompositeTerms method updateComposites.

/**
 * This method will add the given nodes to the passed in composites. If an invalid composite is produced as a result of adding in one of the nodes, we will
 * abort creation of this composite.
 *
 * @param composites
 *            Composite objects being tracked for a given key
 * @param nodes
 *            Collection of nodes matching a single field
 * @return A list of updated composites
 */
private List<Composite> updateComposites(List<Composite> composites, Collection<JexlNode> nodes) {
    List<Composite> updatedComposites = new ArrayList<>();
    // add each of the nodes to each of the composites
    for (JexlNode node : nodes) {
        for (Composite composite : composites) {
            Composite updatedComposite;
            // if this is a node which would be invalid for a normal composite, create a composite range
            if (!CompositeTerm.VALID_LEAF_NODE_CLASSES.contains(node.getClass()) && CompositeRange.VALID_LEAF_NODE_CLASSES.contains(node.getClass())) {
                updatedComposite = new CompositeRange(composite);
            } else // if there is more than 1 node to process, clone the composite
            if (nodes.size() > 1) {
                updatedComposite = composite.clone();
            } else // if there is only 1 node to process, just update the composite
            {
                updatedComposite = composite;
            }
            // update the composite
            updatedComposite.addComponent(node);
            // is it valid? if not, we can't build the composite
            if (!updatedComposite.isValid()) {
                updatedComposites.clear();
                break;
            }
            // save the updated composite
            updatedComposites.add(updatedComposite);
        }
        // composites, something went wrong
        if (updatedComposites.isEmpty())
            break;
    }
    return updatedComposites;
}
Also used : Composite(datawave.query.composite.Composite) ArrayList(java.util.ArrayList) JexlNode(org.apache.commons.jexl2.parser.JexlNode) CompositeRange(datawave.query.composite.CompositeRange)

Aggregations

Composite (datawave.query.composite.Composite)1 CompositeRange (datawave.query.composite.CompositeRange)1 ArrayList (java.util.ArrayList)1 JexlNode (org.apache.commons.jexl2.parser.JexlNode)1