本文整理汇总了Java中org.apache.commons.jexl2.JexlContext.set方法的典型用法代码示例。如果您正苦于以下问题:Java JexlContext.set方法的具体用法?Java JexlContext.set怎么用?Java JexlContext.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.jexl2.JexlContext
的用法示例。
在下文中一共展示了JexlContext.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: matches
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
private boolean matches(Key k) {
if (log.isDebugEnabled()) {
log.debug("You've reached the match function!");
}
JexlContext ctx = new MapContext();
// Add the field value from the key to the context
// String fieldValue = k.getColumnQualifier().toString().split("\0")[0];
// String fieldValue = getFieldValueFromKey(k);
keyParser.parse(k);
String fieldValue = keyParser.getFieldValue();
ctx.set(fNameString, fieldValue);
Object o = expr.evaluate(ctx);
if (o instanceof Boolean && (((Boolean) o) == true)) {
if (log.isDebugEnabled()) {
log.debug("matches:: fName: " + fName + " , fValue: " + fieldValue + " , operator: " + fOperator + " , key: " + k);
}
return true;
} else {
if (log.isDebugEnabled()) {
log.debug("NO MATCH:: fName: " + fName + " , fValue: " + fieldValue + " , operator: " + fOperator + " , key: " + k);
}
return false;
}
}
示例2: addAttrsToContext
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
public JexlContext addAttrsToContext(
final Collection<? extends AbstractAttr> attributes,
final JexlContext jexlContext) {
JexlContext context = jexlContext == null
? new MapContext() : jexlContext;
for (AbstractAttr attribute : attributes) {
List<String> attributeValues = attribute.getValuesAsStrings();
String expressionValue = attributeValues.isEmpty()
? "" : attributeValues.get(0);
LOG.debug("Add attribute {} with value {}",
new Object[]{attribute.getSchema().getName(),
expressionValue});
context.set(attribute.getSchema().getName(), expressionValue);
}
return context;
}
示例3: addDerAttrsToContext
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
public JexlContext addDerAttrsToContext(
final Collection<? extends AbstractDerAttr> derAttributes,
final Collection<? extends AbstractAttr> attributes,
final JexlContext jexlContext) {
JexlContext context = jexlContext == null
? new MapContext() : jexlContext;
for (AbstractDerAttr attribute : derAttributes) {
String expressionValue = attribute.getValue(attributes);
if (expressionValue == null) {
expressionValue = "";
}
LOG.debug("Add derived attribute {} with value {}",
new Object[]{attribute.getDerivedSchema().getName(),
expressionValue});
context.set(
attribute.getDerivedSchema().getName(), expressionValue);
}
return context;
}
示例4: isAboveThreshold
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
/**
*
*/
@Override
public boolean isAboveThreshold(MetricTimeSeries timeSeries)
{
Set<Long> timeWindowSet = timeSeries.getTimeWindowSet();
JexlEngine jexl = new JexlEngine();
JexlContext context = new MapContext();
Expression e = jexl.createExpression(this.thresholdExpr);
for(String metricName : metricNames){
long sum = 0;
for (Long timeWindow : timeWindowSet) {
sum += timeSeries.get(timeWindow, metricName).longValue();
}
context.set(metricName, sum);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(metricName + " = " + sum);
}
}
return ((Boolean)e.evaluate(context)).booleanValue();
}
示例5: testPower
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
@Test
public void testPower() {
JexlEngine engine = ExpressionEvalFactory.getInstance();
Expression expr = engine.createExpression("X^2");
JexlContext context = new MapContext();
// Don't need this really
context.set("A", 20);
context.set("B", 0);
ArrayList<Double> actualList = new ArrayList<>();
for (int i = -20; i < 20; i++) {
context.set("X", i);
Double result = (Double) expr.evaluate(context);
actualList.add(result);
System.out.println(result + ",");
}
Double[] actual = actualList.toArray(new Double[0]);
Double[] expected = {400.0, 361.0, 324.0, 289.0, 256.0, 225.0, 196.0,
169.0, 144.0, 121.0, 100.0, 81.0, 64.0, 49.0, 36.0, 25.0, 16.0,
9.0, 4.0, 1.0, 0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0,
81.0, 100.0, 121.0, 144.0, 169.0, 196.0, 225.0, 256.0, 289.0,
324.0, 361.0};
Assert.assertArrayEquals("results wrong", expected, actual);
}
示例6: _resolveAllFromSameSentence
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
private static void _resolveAllFromSameSentence(Document d, String filter, String comment) {
JexlEngine jexl = new JexlEngine();
jexl.setSilent(JEXL_SILENT);
jexl.setLenient(JEXL_LENIENT);
jexl.setDebug(JEXL_DBG);
Expression expression = jexl.createExpression(filter);
JexlContext jexlContext = new MapContext();
jexlContext.set("Filter", Filter.class);
for (Mention s: d.mentions) {
jexlContext.set("s", s);
List<Mention> tt = MentionBrowser.getAllFromSameSentence(s, expression, jexlContext);
for (Mention t : tt) {
_resolve(d, s, t, comment);
}
}
}
示例7: matches
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
private boolean matches(Key k) {
if (log.isDebugEnabled()) {
log.debug("You've reached the match function!");
}
JexlContext ctx = new MapContext();
// Add the field value from the key to the context
// String fieldValue = k.getColumnQualifier().toString().split("\0")[0];
// String fieldValue = getFieldValueFromKey(k);
keyParser.parse(k);
String fieldValue = keyParser.getFieldValue();
ctx.set(fNameString, fieldValue);
Object o = expr.evaluate(ctx);
if (o instanceof Boolean && (((Boolean) o) == true)) {
if (log.isDebugEnabled()) {
log.debug("matches:: fName: " + fName + " , fValue: " + fieldValue + " , operator: " + fOperator + " , key: " + k);
}
return true;
} else {
if (log.isDebugEnabled()) {
log.debug("NO MATCH:: fName: " + fName + " , fValue: " + fieldValue + " , operator: " + fOperator + " , key: " + k);
}
return false;
}
}
示例8: getValue
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
/**
* @see http://commons.apache.org/jexl/reference/index.html
* @param attributes the set of attributes against which evaluate this
* derived attribute
* @return the value of this derived attribute
*/
public String getValue(
final Collection<? extends AbstractAttr> attributes) {
final ConfigurableApplicationContext context =
ApplicationContextManager.getApplicationContext();
final JexlUtil jexlUtil = context.getBean(JexlUtil.class);
// Prepare context using user attributes
final JexlContext jexlContext = jexlUtil.addAttrsToContext(
attributes, null);
final AbstractAttributable owner = getOwner();
if (owner instanceof SyncopeUser) {
jexlContext.set("username",
((SyncopeUser) owner).getUsername() != null
? ((SyncopeUser) owner).getUsername() : "");
jexlContext.set("creationDate",
((SyncopeUser) owner).getCreationDate() != null
? ((SyncopeUser) owner).getDateFormatter().
format(((SyncopeUser) owner).getCreationDate()) : "");
jexlContext.set("lastLoginDate",
((SyncopeUser) owner).getLastLoginDate() != null
? ((SyncopeUser) owner).getDateFormatter().
format(((SyncopeUser) owner).getLastLoginDate()) : "");
jexlContext.set("failedLogins",
((SyncopeUser) owner).getFailedLogins() != null
? ((SyncopeUser) owner).getFailedLogins() : "");
jexlContext.set("changePwdDate",
((SyncopeUser) owner).getChangePwdDate() != null
? ((SyncopeUser) owner).getDateFormatter().
format(((SyncopeUser) owner).getChangePwdDate()) : "");
}
// Evaluate expression using the context prepared before
return jexlUtil.evaluate(
getDerivedSchema().getExpression(), jexlContext);
}
示例9: populateJexlContext
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
@Override
protected ReadonlyContext populateJexlContext(String model, StringContext context) {
JexlContext jexlContext = new MapContext();
jexlContext.set("text", model);
return new ReadonlyContext(jexlContext);
}
示例10: populateJexlContext
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
@Override
protected ReadonlyContext populateJexlContext(LoginRequest request,
LoginContext context) {
JexlContext jexlContext = new MapContext();
jexlContext.set("request", request);
return new ReadonlyContext(jexlContext);
}
示例11: qualifySubjectAddress
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
public String qualifySubjectAddress(String subjectId) {
final JexlContext context = new MapContext();
context.set("subjectId", subjectId);
final String address = subjectIdentifierExp.evaluate(context).toString();
return String.format("%[email protected]%s", address.replace(":", "-"), this.domain);
}
示例12: qualifyGroupAddress
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
public String qualifyGroupAddress(String group) {
final JexlContext context = new MapContext();
context.set("groupPath", group);
final String mailbox = groupIdentifierExp.evaluate(context).toString();
return String.format("%[email protected]%s", mailbox.replace(":", "-").toLowerCase(), this.domain);
}
示例13: _filterAgree
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
public static boolean _filterAgree(Mention s, Mention t, Expression expression, JexlContext jexlContext) {
Boolean agree = true;
try {
jexlContext.set("t", t);
agree = (Boolean) expression.evaluate(jexlContext);
} catch (Exception ex) {
System.err.println("Error evaluating jexl expression");
ex.printStackTrace(System.err);
}
return agree;
}
示例14: _resolveFirst
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
private static void _resolveFirst(Document d, String filter, String comment) {
JexlEngine jexl = new JexlEngine();
jexl.setSilent(JEXL_SILENT);
jexl.setLenient(JEXL_LENIENT);
jexl.setDebug(JEXL_DBG);
Expression expression = jexl.createExpression(filter);
JexlContext jexlContext = new MapContext();
jexlContext.set("Filter", Filter.class);
Mention t;
for (Mention s: d.mentions) {
jexlContext.set("s", s);
t = MentionBrowser.getFirst(s, expression, jexlContext);
if (t != null) _resolve(d, s, t, comment);
}
}
示例15: _resolveFirstFromSintax
import org.apache.commons.jexl2.JexlContext; //导入方法依赖的package包/类
private static void _resolveFirstFromSintax(Document d, String filter, String comment) {
JexlEngine jexl = new JexlEngine();
jexl.setSilent(JEXL_SILENT);
jexl.setLenient(JEXL_LENIENT);
jexl.setDebug(JEXL_DBG);
Expression expression = jexl.createExpression(filter);
JexlContext jexlContext = new MapContext();
jexlContext.set("Filter", Filter.class);
Mention t;
for (Mention s: d.mentions) {
jexlContext.set("s", s);
t = MentionBrowser.getFirstFromSintax(s, expression, jexlContext);
if (t != null) _resolve(d, s, t, comment);
}
}