@Test public void testMap() throws Exception { Object object = engine.eval("var map = {'abc': 'ABC', 'def': 'DEF', 'ghi': 'GHI'}; map"); JSMap<String, String> map = new JSMap<>(engine, object); assertThat(map.get("abc"), equalTo("ABC")); assertThat(map.keySet(), equalTo((Set<String>) Sets.newHashSet("abc", "def", "ghi"))); assertThat(map.size(), equalTo(3)); }
@SuppressWarnings("unchecked") public <T> T eval(String script, Object... args) { try { bindings.put(ARGS, args); return (T) engine.eval(script, bindings); } catch (ScriptException e) { log.info("Failed: [{}] - {}", script, e); return null; } }
JSWrapper { @SuppressWarnings("unchecked") public <T> T eval(String script, Object... args) { try { bindings.put(ARGS, args); return (T) engine.eval(script, bindings); } catch (ScriptException e) { log.info("Failed: [{}] - {}", script, e); return null; } } }
JSWrapper { @SuppressWarnings("unchecked") public <T> T eval(String script, Object... args) { try { bindings.put(ARGS, args); return (T) engine.eval(script, bindings); } catch (ScriptException e) { log.info("Failed: [{}] - {}", script, e); return null; } } JSWrapper(ScriptEngine engine, Object object); }
JSWrapper { @SuppressWarnings("unchecked") public <T> T eval(String script, Object... args) { try { bindings.put(ARGS, args); return (T) engine.eval(script, bindings); } catch (ScriptException e) { log.info("Failed: [{}] - {}", script, e); return null; } } JSWrapper(ScriptEngine engine, Object object); @SuppressWarnings("unchecked") T eval(String script, Object... args); Object unwrap(); }
JSWrapper { @SuppressWarnings("unchecked") public <T> T eval(String script, Object... args) { try { bindings.put(ARGS, args); return (T) engine.eval(script, bindings); } catch (ScriptException e) { log.info("Failed: [{}] - {}", script, e); return null; } } JSWrapper(ScriptEngine engine, Object object); @SuppressWarnings("unchecked") T eval(String script, Object... args); Object unwrap(); static final String OBJECT; static final String ARGS; }