use of org.nutz.lang.util.Context in project nutz by nutzam.
the class El2Test method speed.
@Test
public void speed() {
SimpleSpeedTest z = new SimpleSpeedTest();
int num = 4988;
String elstr = "num + (i - 1 + 2 - 3 + 4 - 5 + 6 - 7)-z.abc(i)";
int i = 5000;
Context con = Lang.context();
con.set("num", num);
con.set("i", i);
con.set("z", z);
assertEquals(num + (i - 1 + 2 - 3 + 4 - 5 + 6 - 7) - z.abc(i), El.eval(con, elstr));
}
use of org.nutz.lang.util.Context in project nutz by nutzam.
the class El2Test method array.
/**
* 数组测试
*/
@Test
public void array() {
Context context = Lang.context();
String[] str = new String[] { "a", "b", "c" };
String[][] bb = new String[][] { { "a", "b" }, { "c", "d" } };
context.set("a", str);
context.set("b", bb);
assertEquals("b", El.eval(context, "a[1]"));
assertEquals("b", El.eval(context, "a[1].toString()"));
assertEquals("b", El.eval(context, "a[2-1]"));
assertEquals("d", El.eval(context, "b[1][1]"));
}
use of org.nutz.lang.util.Context in project nutz by nutzam.
the class El2Test method list.
/**
* list测试
*/
@Test
public void list() {
Context context = Lang.context();
List<String> list = new ArrayList<String>();
context.set("b", list);
assertEquals(0, El.eval(context, "b.size()"));
list.add("");
assertEquals(1, El.eval(context, "b.size()"));
El.eval(context, "b.add('Q\nQ')");
assertEquals(2, El.eval(context, "b.size()"));
}
use of org.nutz.lang.util.Context in project nutz by nutzam.
the class El2Test method testIssue303.
@Test
public void testIssue303() {
Context context = Lang.context();
Issue303 item = new Issue303("item");
item.child = new Issue303("child");
context.set("item", item);
assertEquals("child", El.eval(context, "item.child.getName()"));
assertEquals(0, El.eval(context, "item.list.size()"));
}
use of org.nutz.lang.util.Context in project nutz by nutzam.
the class TableName method render.
/**
* 根据当前线程的参考对象,渲染一个动态表名
*
* @param tableName
* 动态表名
* @return 渲染后的表名
*/
public static String render(Segment tableName) {
Object obj = get();
if (null == obj || !tableName.hasKey())
return tableName.toString();
Context context = Lang.context();
if (isPrimitive(obj)) {
for (String key : tableName.keys()) context.set(key, obj);
} else if (obj instanceof Context) {
for (String key : tableName.keys()) context.set(key, ((Context) obj).get(key));
} else if (obj instanceof Map<?, ?>) {
for (String key : tableName.keys()) context.set(key, ((Map<?, ?>) obj).get(key));
} else {
Mirror<?> mirror = Mirror.me(obj);
for (String key : tableName.keys()) context.set(key, mirror.getValue(obj, key));
}
return tableName.render(context).toString();
}
Aggregations