use of com.googlecode.aviator.runtime.type.AviatorString in project aviatorscript by killme2008.
the class StringJoinFunction method join.
private AviatorObject join(final Map<String, Object> env, final AviatorObject arg1, final Object target, final String split) {
Class<?> clazz = target.getClass();
StringBuilder sb = new StringBuilder(50);
if (Collection.class.isAssignableFrom(clazz)) {
boolean wasFirst = true;
for (Object obj : (Collection<?>) target) {
wasFirst = append(sb, split, wasFirst, obj);
}
} else if (clazz.isArray()) {
int length = ArrayUtils.getLength(target);
boolean wasFirst = true;
for (int i = 0; i < length; i++) {
Object obj = ArrayUtils.get(target, i);
wasFirst = append(sb, split, wasFirst, obj);
}
} else {
throw new IllegalArgumentException(arg1.desc(env) + " is not a seq");
}
return new AviatorString(sb.toString());
}
use of com.googlecode.aviator.runtime.type.AviatorString in project aviatorscript by killme2008.
the class Date2StringFunction method call.
@Override
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
Date date = (Date) arg1.getValue(env);
String format = FunctionUtils.getStringValue(arg2, env);
SimpleDateFormat dateFormat = DateFormatCache.getOrCreateDateFormat(format);
return new AviatorString(dateFormat.format(date));
}
use of com.googlecode.aviator.runtime.type.AviatorString in project aviatorscript by killme2008.
the class PrintlnFunctionUnitTest method testCall_WithTwoArgument.
@Test
public void testCall_WithTwoArgument() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Map<String, Object> env = new HashMap<String, Object>();
env.put("out", out);
this.fun.call(env, new AviatorJavaType("out"), new AviatorString("hello"));
out.flush();
out.close();
String lineSeparator = System.getProperty("line.separator");
byte[] data = out.toByteArray();
assertEquals("hello" + lineSeparator, new String(data));
}
use of com.googlecode.aviator.runtime.type.AviatorString in project aviatorscript by killme2008.
the class String2DateFunctionUnitTest method testCall_NotDate.
@Test(expected = ClassCastException.class)
public void testCall_NotDate() {
assertEquals("string_to_date", function.getName());
function.call(null, AviatorRuntimeJavaType.valueOf(1), new AviatorString("yyyyMMdd"));
}
use of com.googlecode.aviator.runtime.type.AviatorString in project aviatorscript by killme2008.
the class PrintFunctionUnitTest method testCall_WithTwoArgument.
@Test
public void testCall_WithTwoArgument() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Map<String, Object> env = new HashMap<String, Object>();
env.put("out", out);
this.fun.call(env, new AviatorJavaType("out"), new AviatorString("hello"));
out.flush();
out.close();
byte[] data = out.toByteArray();
assertEquals("hello", new String(data));
}
Aggregations