Search in sources :

Example 71 with MutableObject

use of org.apache.commons.lang3.mutable.MutableObject in project vcell by virtualcell.

the class Xmlproducer method getXML.

/**
 * This method returns a XML representation of a MembraneSubDomain object.
 * Creation date: (3/2/2001 5:40:17 PM)
 * @return Element
 * @param param cbit.vcell.math.MembraneSubDomain
 */
private Element getXML(MembraneSubDomain param) throws XmlParseException {
    Element membrane = new Element(XMLTags.MembraneSubDomainTag);
    // Add attributes
    membrane.setAttribute(XMLTags.NameAttrTag, mangle(param.getName()));
    membrane.setAttribute(XMLTags.InsideCompartmentTag, mangle(param.getInsideCompartment().getName()));
    membrane.setAttribute(XMLTags.OutsideCompartmentTag, mangle(param.getOutsideCompartment().getName()));
    // Add boundaryType subelements
    Element boundary;
    // Xm
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueXm);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionXm().boundaryTypeStringValue());
    membrane.addContent(boundary);
    // Xp
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueXp);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionXp().boundaryTypeStringValue());
    membrane.addContent(boundary);
    // Ym
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueYm);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionYm().boundaryTypeStringValue());
    membrane.addContent(boundary);
    // Yp
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueYp);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionYp().boundaryTypeStringValue());
    membrane.addContent(boundary);
    // Zm
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueZm);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionZm().boundaryTypeStringValue());
    membrane.addContent(boundary);
    // Zp
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueZp);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionZp().boundaryTypeStringValue());
    membrane.addContent(boundary);
    // Add Equation subelements
    Enumeration<Equation> enum1 = param.getEquations();
    while (enum1.hasMoreElements()) {
        Equation equ = enum1.nextElement();
        membrane.addContent(getXML(equ));
    }
    // Add JumConditions
    Enumeration<JumpCondition> enum2 = param.getJumpConditions();
    while (enum2.hasMoreElements()) {
        JumpCondition jc = (JumpCondition) enum2.nextElement();
        membrane.addContent(getXML(jc));
    }
    // Add FastSystem (if there is)
    if (param.getFastSystem() != null) {
        membrane.addContent(getXML(param.getFastSystem()));
    }
    for (ParticleProperties pp : param.getParticleProperties()) {
        membrane.addContent(getXML(pp));
    }
    for (ParticleJumpProcess pjp : param.getParticleJumpProcesses()) {
        membrane.addContent(getXML(pjp));
    }
    Mutable<Element> velocity = new MutableObject<>();
    addVelocityMaybe(velocity, XMLTags.XAttrTag, param.getVelocityX());
    addVelocityMaybe(velocity, XMLTags.YAttrTag, param.getVelocityY());
    if (velocity.getValue() != null) {
        membrane.addContent(velocity.getValue());
    }
    return membrane;
}
Also used : JumpCondition(cbit.vcell.math.JumpCondition) Element(org.jdom.Element) ParticleJumpProcess(cbit.vcell.math.ParticleJumpProcess) ComputeNormalComponentEquation(cbit.vcell.math.ComputeNormalComponentEquation) VolumeRegionEquation(cbit.vcell.math.VolumeRegionEquation) PdeEquation(cbit.vcell.math.PdeEquation) ComputeMembraneMetricEquation(cbit.vcell.math.ComputeMembraneMetricEquation) OdeEquation(cbit.vcell.math.OdeEquation) ComputeCentroidComponentEquation(cbit.vcell.math.ComputeCentroidComponentEquation) MembraneRegionEquation(cbit.vcell.math.MembraneRegionEquation) Equation(cbit.vcell.math.Equation) ParticleProperties(cbit.vcell.math.ParticleProperties) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 72 with MutableObject

use of org.apache.commons.lang3.mutable.MutableObject in project oap by oaplatform.

the class SchemaPath method traverse.

public static Result traverse(SchemaAST root, String path) {
    SchemaAST schemaAST = root;
    val additionalProperties = new MutableObject<Boolean>(null);
    final Supplier<Result> empty = () -> new Result(Optional.empty(), Optional.ofNullable(additionalProperties.getValue()));
    for (val item : StringUtils.split(path, '.')) {
        if (schemaAST instanceof ObjectSchemaAST) {
            val objectSchemaAST = (ObjectSchemaAST) schemaAST;
            schemaAST = objectSchemaAST.properties.get(item);
            objectSchemaAST.additionalProperties.ifPresent(additionalProperties::setValue);
            if (schemaAST == null)
                return empty.get();
        } else if (schemaAST instanceof ArraySchemaAST) {
            if (!"items".equals(item))
                return empty.get();
            schemaAST = ((ArraySchemaAST) schemaAST).items;
        } else {
            return empty.get();
        }
    }
    return new Result(Optional.of(schemaAST), Optional.ofNullable(additionalProperties.getValue()));
}
Also used : lombok.val(lombok.val) ArraySchemaAST(oap.json.schema.validator.array.ArraySchemaAST) ObjectSchemaAST(oap.json.schema.validator.object.ObjectSchemaAST) ObjectSchemaAST(oap.json.schema.validator.object.ObjectSchemaAST) ArraySchemaAST(oap.json.schema.validator.array.ArraySchemaAST) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 73 with MutableObject

use of org.apache.commons.lang3.mutable.MutableObject in project oap by oaplatform.

the class JavaCTemplate method addPathOr.

private void addPathOr(Class<T> clazz, String delimiter, StringBuilder c, AtomicInteger num, FieldStack fields, boolean last, AtomicInteger tab, String[] orPath, int orIndex, TLine line) throws NoSuchFieldException, NoSuchMethodException {
    val currentPath = orPath[orIndex].trim();
    val m = mapper.get(currentPath);
    if (m != null) {
        printDefaultValue(tab(c, tab), m.get(), line);
    } else {
        int sp = 0;
        StringBuilder newPath = new StringBuilder("s.");
        MutableObject<Type> lc = new MutableObject<>(clazz);
        AtomicInteger psp = new AtomicInteger(0);
        AtomicInteger opts = new AtomicInteger(0);
        while (sp >= 0) {
            sp = currentPath.indexOf('.', sp + 1);
            if (sp > 0) {
                Pair<Type, String> pnp = fields.computeIfAbsent(currentPath.substring(0, sp), Try.map((key) -> {
                    String prefix = StringUtils.trim(psp.get() > 1 ? key.substring(0, psp.get() - 1) : "");
                    String suffix = StringUtils.trim(key.substring(psp.get()));
                    boolean optional = isOptional(lc.getValue());
                    Type declaredFieldType = getDeclaredFieldOrFunctionType(optional ? getOptionalArgumentType(lc.getValue()) : lc.getValue(), suffix);
                    String classType = toJavaType(declaredFieldType);
                    String field = "field" + num.incrementAndGet();
                    Optional<Pair<Type, String>> rfP = Optional.ofNullable(fields.get(prefix));
                    String rf = rfP.map(p -> p._2 + (optional ? ".get()" : "") + "." + suffix).orElse("s." + key);
                    if (optional) {
                        tab(c, tab).append("if( ").append(rfP.map(p -> p._2).orElse("s")).append(".isPresent() ) {\n");
                        opts.incrementAndGet();
                        tabInc(tab);
                        fields.up();
                    }
                    tab(c, tab).append(" ").append(classType).append(" ").append(field).append(" = ").append(rf).append(";\n");
                    lc.setValue(declaredFieldType);
                    return __(lc.getValue(), field);
                }));
                newPath = new StringBuilder(pnp._2 + ".");
                lc.setValue(pnp._1);
                psp.set(sp + 1);
            } else {
                newPath.append(currentPath.substring(psp.get()));
            }
        }
        int in = newPath.toString().lastIndexOf('.');
        String pField = in > 0 ? newPath.substring(0, in) : newPath.toString();
        String cField = newPath.substring(in + 1);
        boolean isJoin = cField.startsWith("{");
        String[] cFields = isJoin ? StringUtils.split(cField.substring(1, cField.length() - 1), ',') : new String[] { cField };
        Type parentClass = lc.getValue();
        boolean isOptionalParent = isOptional(parentClass) && !cField.startsWith("isPresent");
        String optField = null;
        if (isOptionalParent) {
            opts.incrementAndGet();
            tab(c, tab).append("if( ").append(pField).append(".isPresent() ) {\n");
            fields.up();
            tabInc(tab);
            parentClass = getOptionalArgumentType(parentClass);
            optField = "opt" + num.incrementAndGet();
            tab(c, tab).append(" ").append(toJavaType(parentClass)).append(" ").append(optField).append(" = ").append(pField).append(".get();\n");
        }
        for (int i = 0; i < cFields.length; i++) {
            cField = StringUtils.trim(cFields[i]);
            Optional<Join> join = isJoin ? Optional.of(new Join(i, cFields.length)) : Optional.empty();
            if (cField.startsWith("\"")) {
                tab(c.append("\n"), tab);
                map.map(c, String.class, line, cField, delimiter, join);
            } else {
                if (isOptionalParent) {
                    newPath = new StringBuilder(in > 0 ? optField + "." + cField : cField);
                } else {
                    newPath = new StringBuilder(in > 0 ? pField + "." + cField : "s." + cField);
                }
                Type cc = in > 0 ? getDeclaredFieldOrFunctionType(parentClass, cField) : parentClass;
                add(c, num, newPath.toString(), cc, parentClass, true, tab, orPath, orIndex, clazz, delimiter, fields, last || (i < cFields.length - 1), line, join);
            }
        }
        c.append("\n");
        for (int i = 0; i < opts.get(); i++) {
            fields.down();
            tabDec(tab);
            tab(c, tab).append("} else {\n");
            fields.up();
            tabInc(tab);
            if (orIndex + 1 < orPath.length) {
                addPathOr(clazz, delimiter, c, num, fields, last, new AtomicInteger(tab.get() + 2), orPath, orIndex + 1, line);
            } else {
                printDefaultValue(c, line.defaultValue, line);
                if (!map.ignoreDefaultValue())
                    printDelimiter(delimiter, c, last, tab);
            }
            tabDec(tab);
            fields.down();
            tab(c, tab).append("}\n");
        }
    }
}
Also used : lombok.val(lombok.val) Pair(oap.util.Pair) SneakyThrows(lombok.SneakyThrows) BiFunction(java.util.function.BiFunction) Pair.__(oap.util.Pair.__) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Stack(java.util.Stack) ClassUtils(org.apache.commons.lang3.ClassUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) StringEscapeUtils(org.apache.commons.lang3.StringEscapeUtils) MutableObject(org.apache.commons.lang3.mutable.MutableObject) Path(java.nio.file.Path) Types.isPrimitive(oap.reflect.Types.isPrimitive) Types.getOptionalArgumentType(oap.reflect.Types.getOptionalArgumentType) lombok.val(lombok.val) Collectors.joining(java.util.stream.Collectors.joining) Slf4j(lombok.extern.slf4j.Slf4j) Try(oap.util.Try) List(java.util.List) Types.toJavaType(oap.reflect.Types.toJavaType) MemoryClassLoader(oap.tools.MemoryClassLoader) StringReader(java.io.StringReader) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) Optional(java.util.Optional) Types.getOptionalArgumentType(oap.reflect.Types.getOptionalArgumentType) Types.toJavaType(oap.reflect.Types.toJavaType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 74 with MutableObject

use of org.apache.commons.lang3.mutable.MutableObject in project sponge by softelnet.

the class AbstractRuleAdapterRuntime method buildEventTree.

/**
 * Continues building the event tree for the incoming event starting at the specified node.
 *
 * @param node event tree node.
 * @param event incoming event.
 */
protected void buildEventTree(TreeNode<NodeValue> node, Event event) {
    // Check if this event is the first event that starts the rule instance.
    boolean isFirstNode = (node == null);
    // Create a new node for the incoming event and add to the event tree. This node may be removed later when the event doesn't match.
    TreeNode<NodeValue> newNode = new TreeNode<>(new NodeValue(event));
    if (isFirstNode) {
        // First event that starts the rule.
        node = newNode;
        // Add the new node to the event tree as root.
        eventTree.setRoot(node);
    } else {
        // Recursively try to continue building the event tree, but only for modes FIRST, LAST and ALL.
        node.getChildren().forEach(child -> {
            // NONE events are processed in shouldAddToEventTreeForNMode(), not here.
            if (adapter.getEventMode(getEventIndex(child)) != EventMode.NONE) {
                buildEventTree(child, event);
            }
        });
        // Return if reached the last level.
        if (node.getLevel() + 1 >= adapter.getEventCount()) {
            return;
        }
        // Add the new node to the event tree.
        node.addChild(newNode);
    }
    // Should this event be added to the event tree in this place.
    boolean rememberEvent = false;
    EventMode eventMode = getEventMode(newNode);
    if (eventMode != null) {
        switch(eventMode) {
            case FIRST:
            case LAST:
            case ALL:
                rememberEvent = shouldAddToEventTreeForFlaModes(newNode, event);
                break;
            case NONE:
                Mutable<TreeNode<NodeValue>> newNodeHolder = new MutableObject<>(newNode);
                rememberEvent = shouldAddToEventTreeForNMode(node, newNodeHolder, event);
                // shouldAddToEventTreeForNMode() may change newNode.
                newNode = newNodeHolder.getValue();
                break;
            default:
                throw new SpongeException("Unsupported value: " + eventMode);
        }
    }
    // Remove the node for the incoming event if the event doesn't match.
    if (!rememberEvent) {
        if (isFirstNode) {
            eventTree.setRoot(null);
        } else {
            node.removeChild(newNode);
        }
    }
}
Also used : EventMode(org.openksavi.sponge.rule.EventMode) SpongeException(org.openksavi.sponge.SpongeException) TreeNode(org.openksavi.sponge.core.util.TreeNode) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 75 with MutableObject

use of org.apache.commons.lang3.mutable.MutableObject in project rest-assured by rest-assured.

the class FilterITest method httpClientIsAccessibleFromTheRequestSpecification.

@Test
public void httpClientIsAccessibleFromTheRequestSpecification() {
    // Given
    final MutableObject<HttpClient> client = new MutableObject<HttpClient>();
    // When
    given().filter(new Filter() {

        public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
            client.setValue(requestSpec.getHttpClient());
            return new ResponseBuilder().setStatusCode(200).setContentType("application/json").setBody("{ \"message\" : \"hello\"}").build();
        }
    }).expect().body("message", equalTo("hello")).when().get("/something");
    // Then
    assertThat(client.getValue(), instanceOf(DefaultHttpClient.class));
}
Also used : Response(io.restassured.response.Response) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) ErrorLoggingFilter(io.restassured.filter.log.ErrorLoggingFilter) SpookyGreetJsonResponseFilter(io.restassured.itest.java.support.SpookyGreetJsonResponseFilter) FormAuthFilter(io.restassured.internal.filter.FormAuthFilter) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Filter(io.restassured.filter.Filter) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) MutableObject(org.apache.commons.lang3.mutable.MutableObject) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Aggregations

Mutable (org.apache.commons.lang3.mutable.Mutable)119 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)113 MutableObject (org.apache.commons.lang3.mutable.MutableObject)111 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)101 ArrayList (java.util.ArrayList)93 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)91 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)78 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)54 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)49 Pair (org.apache.hyracks.algebricks.common.utils.Pair)47 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)46 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)35 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)29 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)26 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)25 List (java.util.List)23 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)23 AggregateFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression)23 UnnestingFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression)23 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)22