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;
}
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()));
}
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");
}
}
}
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);
}
}
}
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));
}
Aggregations