private ClientBuilder getClientBuilder() { if (clientBuilder == null) { clientBuilder = clientBuilder(); } return BeanUtils.copy(clientBuilder); }
BeanUtils.idx(httpRequest, "receiver", httpTextReceiver);
public static double idxDouble( Object object, String path ) { String[] properties = propertyPathAsStringArray(path); return getPropertyDouble( object, properties ); }
/** * Get property value * * @param object object * @param path in dotted notation * @return int */ public static int idxInt( Object object, String path ) { String[] properties = propertyPathAsStringArray(path); return getPropertyInt( object, properties ); }
public static float idxFloat( Object object, String path ) { String[] properties = propertyPathAsStringArray(path); return getPropertyFloat( object, properties ); }
public static long idxLong( Object object, String path ) { String[] properties = propertyPathAsStringArray(path); return getPropertyLong( object, properties ); }
public static float getPropertyFloat( final Object root, final String... properties ) { final String lastProperty = properties[ properties.length - 1 ]; if ( isDigits( lastProperty ) ) { return Conversions.toFloat(getPropertyValue(root, properties)); } Object object = baseForGetProperty( root, properties ); Map<String, FieldAccess> fields = getFieldsFromObject( object ); FieldAccess field = fields.get( lastProperty ); if ( field.type() == Typ.flt ) { return field.getFloat( object ); } else { return Conversions.toFloat( field.getValue( object ) ); } }
public static FieldAccess getPropertyPathField( final Class root, final String... properties ) { Class cls = baseForGetProperty( root, properties ); Map<String, FieldAccess> fields = getFieldsFromObject( cls ); final String lastProperty = properties[ properties.length - 1 ]; FieldAccess field = fields.get( lastProperty ); return field; }
/** * Calculate a sum of a property from a list. * @param inputList input list * @param propertyPath to item we want to sum * @return sum */ public static long sum( Collection<?> inputList, String propertyPath ) { if (inputList.size() == 0 ) { return 0; } long sum = 0l; if (propertyPath.contains(".") || propertyPath.contains("[")) { String[] properties = StringScanner.splitByDelimiters(propertyPath, ".[]"); for (Object o : inputList) { sum+=BeanUtils.getPropertyInt(o, properties); } } else { Map<String, FieldAccess> fields = BeanUtils.getFieldsFromObject(inputList.iterator().next()); FieldAccess fieldAccess = fields.get(propertyPath); for (Object o : inputList) { sum += fieldAccess.getInt(o); } } return sum; }
@Override public Object parse( Reader reader ) { if (reader instanceof StringReader) { try { String str = BeanUtils.idxStr(reader, "str"); int length = BeanUtils.idxInt(reader, "length"); int next = BeanUtils.idxInt(reader, "next"); if (str!= null && next == 0 && length == str.length()) { return parse(str); } } catch (Exception ex) { //Boon.logger("JSON PARSER").fatal(ex); //throw new IllegalStateException(ex); } } characterSource = new ReaderCharacterSource ( reader ); return this.decodeValue (); }
/** * Creates a primitive list based on an input list and a property path * * @param inputList input list * @param propertyPath property path * @return primitive list */ public static DoubleList toDoubleList(Collection<?> inputList, String propertyPath) { if (inputList.size() == 0) { return new DoubleList(0); } DoubleList outputList = new DoubleList(inputList.size()); if (propertyPath.contains(".") || propertyPath.contains("[")) { String[] properties = StringScanner.splitByDelimiters(propertyPath, ".[]"); for (Object o : inputList) { outputList.add(BeanUtils.getPropertyDouble(o, properties)); } } else { Map<String, FieldAccess> fields = BeanUtils.getFieldsFromObject(inputList.iterator().next()); FieldAccess fieldAccess = fields.get(propertyPath); for (Object o : inputList) { outputList.add(fieldAccess.getDouble(o)); } } return outputList; }
/** * Creates a primitive list based on an input list and a property path * * @param inputList input list * @param propertyPath property path * @return primitive list */ public static FloatList toFloatList(Collection<?> inputList, String propertyPath) { if (inputList.size() == 0) { return new FloatList(0); } FloatList outputList = new FloatList(inputList.size()); if (propertyPath.contains(".") || propertyPath.contains("[")) { String[] properties = StringScanner.splitByDelimiters(propertyPath, ".[]"); for (Object o : inputList) { outputList.add(BeanUtils.getPropertyFloat(o, properties)); } } else { Map<String, FieldAccess> fields = BeanUtils.getFieldsFromObject(inputList.iterator().next()); FieldAccess fieldAccess = fields.get(propertyPath); for (Object o : inputList) { outputList.add(fieldAccess.getFloat(o)); } } return outputList; }
/** * Creates a primitive list based on an input list and a property path * * @param inputList input list * @param propertyPath property path * @return primitive list */ public static LongList toLongList(Collection<?> inputList, String propertyPath) { if (inputList.size() == 0) { return new LongList(0); } LongList outputList = new LongList(inputList.size()); if (propertyPath.contains(".") || propertyPath.contains("[")) { String[] properties = StringScanner.splitByDelimiters(propertyPath, ".[]"); for (Object o : inputList) { outputList.add(BeanUtils.getPropertyLong(o, properties)); } } else { Map<String, FieldAccess> fields = BeanUtils.getFieldsFromObject(inputList.iterator().next()); FieldAccess fieldAccess = fields.get(propertyPath); for (Object o : inputList) { outputList.add(fieldAccess.getLong(o)); } } return outputList; }
@Test public void test() throws Exception { Todo todo = new Todo(); todo.name = "todo"; Category category = new Category(); category.name = "category"; Genre genre = new Genre(); genre.name = "genre"; category.genre = genre; todo.category = category; BoonJsonMapper boonJsonMapper = new BoonJsonMapper(); String json = boonJsonMapper.toJson(todo); Map<String, Object> jsonMap = boonJsonMapper.fromJsonMap(json, String.class, Object.class); String value = BeanUtils.idxStr(jsonMap, "category.genre.name"); assertEquals("genre", value); assertEquals(String.class, jsonMap.get("name").getClass()); }
public static FieldAccess getField( Object object, String name ) { Map<String, FieldAccess> fields = getFieldsFromObject( object ); if ( fields != null) { return fields.get(name); } else { return null; } }
public static float getPropertyFloat( final Object root, final String... properties ) { final String lastProperty = properties[ properties.length - 1 ]; if ( isDigits( lastProperty ) ) { return Conversions.toFloat(getPropertyValue(root, properties)); } Object object = baseForGetProperty( root, properties ); Map<String, FieldAccess> fields = getFieldsFromObject( object ); FieldAccess field = fields.get( lastProperty ); if ( field.type() == Typ.flt ) { return field.getFloat( object ); } else { return Conversions.toFloat( field.getValue( object ) ); } }
public static FieldAccess getPropertyPathField( final Class root, final String... properties ) { Class cls = baseForGetProperty( root, properties ); Map<String, FieldAccess> fields = getFieldsFromObject( cls ); final String lastProperty = properties[ properties.length - 1 ]; FieldAccess field = fields.get( lastProperty ); return field; }
/** * Calculate a sum of a property from a list. * @param inputList input list * @param propertyPath to item we want to sum * @return sum */ public static long sum( Collection<?> inputList, String propertyPath ) { if (inputList.size() == 0 ) { return 0; } long sum = 0l; if (propertyPath.contains(".") || propertyPath.contains("[")) { String[] properties = StringScanner.splitByDelimiters(propertyPath, ".[]"); for (Object o : inputList) { sum+=BeanUtils.getPropertyInt(o, properties); } } else { Map<String, FieldAccess> fields = BeanUtils.getFieldsFromObject(inputList.iterator().next()); FieldAccess fieldAccess = fields.get(propertyPath); for (Object o : inputList) { sum += fieldAccess.getInt(o); } } return sum; }
@Override public Object parse( Reader reader ) { if (reader instanceof StringReader) { try { String str = BeanUtils.idxStr(reader, "str"); int length = BeanUtils.idxInt(reader, "length"); int next = BeanUtils.idxInt(reader, "next"); if (str!= null && next == 0 && length == str.length()) { return parse(str); } } catch (Exception ex) { //Boon.logger("JSON PARSER").fatal(ex); //throw new IllegalStateException(ex); } } characterSource = new ReaderCharacterSource ( reader ); return this.decodeValue (); }
/** * Get property value * * @param object object * @param path in dotted notation * @return int */ public static int idxInt( Object object, String path ) { String[] properties = propertyPathAsStringArray(path); return getPropertyInt( object, properties ); }