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

net.sf.saxon.expr.oper.OperandArray Maven / Gradle / Ivy

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2013 Saxonica Limited.
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// This Source Code Form is “Incompatible With Secondary Licenses”, as defined by the Mozilla Public License, v. 2.0.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package net.sf.saxon.expr.oper;

import net.sf.saxon.expr.Expression;
import net.sf.saxon.expr.Operand;
import net.sf.saxon.expr.OperandRole;

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

/**
 * Defines an operand set comprising an array of operands numbered zero to N. All operands must be present.
 * Typically (but not exclusively) used for the arguments of a function call. The operands may all have the
 * same operand roles, or have different operand roles.
 */

public class OperandArray {

    private Operand[] operandArray;

    // operand role is currently always NAVIGATE, but this could change in the future

    public OperandArray(Expression parent, Expression[] args) {
        this.operandArray = new Operand[args.length];
        for (int i=0; i operands() {
        return Arrays.asList(operandArray);
    }

    public Iterable operandExpressions() {
        List list = new ArrayList(operandArray.length);
        for (Operand o : operands()) {
            list.add(o.getChildExpression());
        }
        return list;
    }

    /**
     * Set the value of the operand with integer n.
     * The method should implement a fast path for the case where the operand has
     * not actually been changed.
     *
     * @param n identifies the expression to be set/replaced
     * @param child the new subexpression
     * @throws IllegalArgumentException if the value of n identifies no operand
     */

    public void setOperand(int n, Expression child) {
        try {
            if (operandArray[n].getChildExpression() != child) {
                operandArray[n].setChildExpression(child);
            }
        } catch (ArrayIndexOutOfBoundsException a) {
            throw new IllegalArgumentException();
        }
    }

    /**
     * Get the number of operands in the operand array
     * @return  the number of operands
     */

    public int getNumberOfOperands() {
        return operandArray.length;
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy