use of com.dexels.navajo.document.Selection in project navajo by Dexels.
the class SimpleNode method lazyBiFunction.
public ContextExpression lazyBiFunction(List<String> problems, String expression, BinaryOperator<Operand> func, BiFunction<Optional<String>, Optional<String>, Boolean> acceptTypes, BiFunction<Optional<String>, Optional<String>, Optional<String>> returnTypeResolver, Function<String, FunctionClassification> functionClassifier, Function<String, Optional<Node>> mapResolver) {
ContextExpression expA = jjtGetChild(0).interpretToLambda(problems, expression, functionClassifier, mapResolver);
ContextExpression expB = jjtGetChild(1).interpretToLambda(problems, expression, functionClassifier, mapResolver);
Optional<String> aType = expA.returnType();
Optional<String> bType = expB.returnType();
boolean inputTypesValid = acceptTypes.apply(aType, bType);
if (!inputTypesValid) {
problems.add("Invalid input types in node: " + aType.orElse("unknown") + " and " + bType.orElse("unknown") + " in node type: " + this.getClass());
}
Optional<String> returnType = returnTypeResolver.apply(aType, bType);
return new ContextExpression() {
@Override
public Operand apply(Navajo doc, Message parentMsg, Message parentParamMsg, Selection parentSel, MappableTreeNode mapNode, TipiLink tipiLink, Access access, Optional<ImmutableMessage> immutableMessage, Optional<ImmutableMessage> paramMessage) {
Operand a = expA.apply(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage);
Operand b = expB.apply(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage);
return func.apply(a, b);
}
@Override
public boolean isLiteral() {
return expA.isLiteral() && expB.isLiteral();
}
@Override
public Optional<String> returnType() {
return returnType;
}
@Override
public String expression() {
return expression;
}
};
}
use of com.dexels.navajo.document.Selection in project navajo by Dexels.
the class BasePropertyImpl method isEqual.
@Override
public final boolean isEqual(Property p) {
if (!getName().equals(p.getName())) {
return false;
}
if ((this.getType() != null && p.getType() != null) && !this.getType().equals(p.getType())) {
return false;
}
// Check for date properties.
if (p.getType().equals(Property.DATE_PROPERTY)) {
// If both values are null they're equal.
if (p.getTypedValue() == null && this.getTypedValue() == null) {
return true;
}
// If only one of them is null they're not equal.
if (p.getTypedValue() == null || this.getTypedValue() == null) {
return false;
}
java.util.Date myDate = (java.util.Date) getTypedValue();
java.util.Date otherDate = (java.util.Date) p.getTypedValue();
return dateFormat2.get().format(myDate).equals(dateFormat2.get().format(otherDate));
} else // Check for selection properties.
if (p.getType().equals(Property.SELECTION_PROPERTY)) {
try {
List<Selection> l = p.getAllSelectedSelections();
List<Selection> me = this.getAllSelectedSelections();
// equal.
if (me.size() != l.size()) {
return false;
}
for (int j = 0; j < l.size(); j++) {
Selection other = l.get(j);
boolean match = false;
for (int k = 0; k < me.size(); k++) {
Selection mysel = me.get(k);
if (mysel.getValue().equals(other.getValue())) {
match = true;
k = me.size() + 1;
}
}
if (!match) {
return false;
}
}
return true;
} catch (Exception e) {
logger.warn("Error: ", e);
return false;
}
} else if (p.getType().equals(Property.BINARY_PROPERTY)) {
// If both values are null they're equal.
if (p.getTypedValue() == null && this.getTypedValue() == null) {
return true;
}
// If only one of them is null they're not equal.
if (p.getTypedValue() == null || this.getTypedValue() == null) {
return false;
}
return ((Binary) this.getTypedValue()).isEqual((Binary) p.getTypedValue());
} else // Else I am some other property.
{
// If both values are null they're equal.
if (p.getValue() == null && this.getValue() == null) {
return true;
}
// If only one of them is null they're not equal.
if (p.getValue() == null || this.getValue() == null) {
return false;
}
return p.getValue().equals(this.getValue());
}
}
use of com.dexels.navajo.document.Selection in project navajo by Dexels.
the class BasePropertyImpl method setSelected.
@Override
public final void setSelected(String value) {
if (!"+".equals(getCardinality())) {
ArrayList<Selection> al = getAllSelections();
for (int i = 0; i < al.size(); i++) {
BaseSelectionImpl s = (BaseSelectionImpl) al.get(i);
s.setSelected(false);
}
}
String oldSel = null;
Selection sel = getSelected();
if (sel != null) {
oldSel = sel.getValue();
}
Selection s = getSelectionByValue(value);
firePropertyChanged("selection", oldSel, value);
s.setSelected(true);
}
use of com.dexels.navajo.document.Selection in project navajo by Dexels.
the class BasePropertyImpl method setSelected.
@Override
public void setSelected(String[] s) {
if (!getType().equals(SELECTION_PROPERTY)) {
throw NavajoFactory.getInstance().createNavajoException("Setting selected of non-selection property!");
}
setAllSelected(false);
for (int i = 0; i < s.length; i++) {
Selection st = getSelectionByValue(s[i]);
st.setSelected(true);
}
}
use of com.dexels.navajo.document.Selection in project navajo by Dexels.
the class BasePropertyImpl method updateExpressionSelections.
private void updateExpressionSelections(List<Selection> list) {
removeAllSelections();
for (int i = 0; i < list.size(); i++) {
Selection s = list.get(i);
Selection copy = NavajoFactory.getInstance().createSelection(getRootDoc(), s.getName(), s.getValue(), false);
addSelection(copy);
}
}
Aggregations