static int getCodeFromRequestMapping(Annotated annotated) { final AnnotationData requestMapping = getAnnotationData(annotated); if (requestMapping != null) { Object value = requestMapping.getValues().get("code"); return Conversions.toInt(value); } else { return -1; } }
public static Date toDateUS(String string) { String[] split = StringScanner.splitByChars(string, new char[]{'.', '\\', '/', ':'}); if (split.length == 3) { return Dates.getUSDate(toInt(split[0]), toInt(split[1]), toInt(split[2])); } else if (split.length >= 6) { return Dates.getUSDate(toInt(split[0]), toInt(split[1]), toInt(split[2]), toInt(split[3]), toInt(split[4]), toInt(split[5]) ); } else { Exceptions.die(String.format("Not able to parse %s into a US date", string)); return null; } }
public static short toShort(Object obj, final short shortDefault) { if (obj.getClass() == short.class) { return short.class.cast(obj); } else if (obj instanceof Number) { return ((Number) obj).shortValue(); } else { return (short) toInt(obj, shortDefault); } }
public static Date toEuroDate(String string) { String[] split = StringScanner.splitByChars(string, new char[]{'.', '\\', '/', ':'}); if (split.length == 3) { return Dates.getEuroDate(toInt(split[0]), toInt(split[1]), toInt(split[2])); } else if (split.length >= 6) { return Dates.getEuroDate(toInt(split[0]), toInt(split[1]), toInt(split[2]), toInt(split[3]), toInt(split[4]), toInt(split[5]) ); } else { Exceptions.die(String.format("Not able to parse %s into a Euro date", string)); return null; } }
public static short toShort(Object obj, final short shortDefault) { if (obj.getClass() == short.class) { return short.class.cast(obj); } else if (obj instanceof Number) { return ((Number) obj).shortValue(); } else { return (short) toInt(obj, shortDefault); } }
public static byte toByte(Object obj, byte defaultByte) { if (obj.getClass() == byte.class) { return byte.class.cast(obj); } else if (obj instanceof Number) { return ((Number) obj).byteValue(); } else { return (byte) toInt(obj, defaultByte); } }
public static byte toByte(Object obj, byte defaultByte) { if (obj.getClass() == byte.class) { return byte.class.cast(obj); } else if (obj instanceof Number) { return ((Number) obj).byteValue(); } else { return (byte) toInt(obj, defaultByte); } }
@Override public final int getInt( Object obj ) { if ( obj instanceof Map ) { Map map = ( Map ) obj; return Conversions.toInt( map.get( name ) ); } Exceptions.die("Object must be a map"); return -1; }
@Override public int parseInt ( byte[] jsonBytes, Charset charset ) { return Conversions.toInt ( parse ( jsonBytes, charset ) ); }
@Override public int parseInt ( char[] chars ) { return Conversions.toInt ( parse ( chars ) ); }
@Override public int parseInt ( CharSequence jsonSeq ) { return Conversions.toInt ( parse ( jsonSeq ) ); }
@Override public int parseInt ( InputStream input ) { return Conversions.toInt ( parse ( input ) ); }
public static <K, V> int toInt( Map<K, V> map, K key ) { V value = map.get(key); int v = Conversions.toInt ( value, Integer.MIN_VALUE ); if ( v == Integer.MIN_VALUE ) { Exceptions.die("Cannot convert", key, "into int value", value); } return v; }
public static <K, V> int toInt( Map<K, V> map, K key ) { V value = map.get(key); int v = Conversions.toInt ( value, Integer.MIN_VALUE ); if ( v == Integer.MIN_VALUE ) { Exceptions.die("Cannot convert", key, "into int value", value); } return v; }
@Override public int parseInt ( byte[] jsonBytes ) { return Conversions.toInt ( parse ( jsonBytes ) ); }
@Override public int parseInt ( CharSequence jsonSeq ) { return Conversions.toInt ( parse ( jsonSeq ) ); }
@Override public int parseInt ( InputStream input ) { return Conversions.toInt ( parse ( input ) ); }
@Override public int parseInt ( byte[] jsonBytes ) { return Conversions.toInt ( parse ( jsonBytes ) ); }
static int getCodeFromRequestMapping(Annotated annotated) { final AnnotationData requestMapping = getAnnotationData(annotated); if (requestMapping != null) { Object value = requestMapping.getValues().get("code"); return Conversions.toInt(value); } else { return -1; } }
@Test public void testResponses() throws Exception { call = MethodCallBuilder.methodCallBuilder().setAddress("/foo/adder").setName("add").setBody(Lists.list(1, 2)).build(); serviceBundle.addServiceObject("/adder", adderService); serviceBundle.call(call); serviceBundle.flushSends(); Sys.sleep(1000); responseReceiveQueue = serviceBundle.responses().receiveQueue(); serviceBundle.flush(); Sys.sleep(200); response = responseReceiveQueue.pollWait(); responseBody = response.body(); int sum = Conversions.toInt(responseBody); Assert.assertEquals("Sum should be 3", 3, sum); serviceBundle.stop(); }