RuleHelper extends Helper implements SessionManager { public <T> T cast(Object obj, Class<T> clz) { if (!clz.isAssignableFrom(obj.getClass())) { return null; } return clz.cast(obj); } protected  RuleHelper(Rule rule); String getRuleName(); TraceCollector collector(); String createUUID(); String getID(String type, Object obj); boolean isInstanceOf(Object obj, Class<?> clz); T cast(Object obj, Class<T> clz); String simpleClassName(Object obj); String toString(Object obj); int hashCode(Object obj); String formatSQL(Object obj, Object expr); String faultName(Object fault); String faultDescription(Object fault); String removeSuffix(String original, String suffix); String removeAfter(String original, String marker); ArrayBuilder createArrayBuilder(); Map<String, String> getHeaders(String type, Object target); @Override boolean activate(String uri, String operation, String id); @Override boolean activate(String uri, String operation); @Override boolean isActive(); @Override void deactivate(); @Override void retainNode(String id); @Override void releaseNode(String id); @Override Node retrieveNode(String id); @Override void initiateCorrelation(String id); @Override boolean isCorrelated(String id); @Override void correlate(String id); @Override void completeCorrelation(String id, boolean allowSpawn); @Override void unlink(); @Override void suppress(); @Override void ignoreNode(); @Override void assertComplete(); String getTraceId(); String getTransactionName(); String getLevel(); void initInBuffer(Object obj); boolean isInBufferActive(Object obj); void appendInBuffer(Object obj, byte[] data, int offset, int len, boolean close); void recordInBuffer(Object obj); void initOutBuffer(Object obj); boolean isOutBufferActive(Object obj); void appendOutBuffer(Object obj, byte[] data, int offset, int len, boolean close); void recordOutBuffer(Object obj); boolean isInProcessed(); boolean isInContentProcessed(); boolean isOutProcessed(); boolean isOutContentProcessed(); OutputStream createInOutputStream(OutputStream os); OutputStream createInOutputStream(OutputStream os, String linkId); OutputStream createOutOutputStream(OutputStream os); OutputStream createOutOutputStream(OutputStream os, String linkId); InputStream createInInputStream(InputStream is); InputStream createOutInputStream(InputStream is); @Override void setState(Object context, String name, Object value, boolean session); @Override Object getState(Object context, String name, boolean session); static final String BINARY_SQL_MARKER; }
@Test public void testCast() { RuleHelper helper = new RuleHelper(null); String str = helper.<String> cast("hello", String.class); assertEquals("hello", str); }
@Test public void testCastIncorrect() { RuleHelper helper = new RuleHelper(null); TestObject1 to1 = new TestObject1(); TestObject2 to2 = helper.<TestObject2> cast(to1, TestObject2.class); assertNull(to2); }