@Test public void writePseudoPropertyValueNamedネストネストリストテスト() { Object target = new Object() { @SuppressWarnings("unused") public Object prop = new Object() { public List<String> nested = Lists.gen("", "", ""); }; }; Beans.writePseudoPropertyValueNamed("prop.nested[0]", target, "0"); Beans.writePseudoPropertyValueNamed("prop.nested[1]", target, "1"); Beans.writePseudoPropertyValueNamed("prop.nested[2]", target, "2"); String value = (String) Beans.readPseudoPropertyValueNamed("prop.nested[0]", target); assertNotNull(value); assertEquals("0", value); value = (String) Beans.readPseudoPropertyValueNamed("prop.nested[1]", target); assertNotNull(value); assertEquals("1", value); value = (String) Beans.readPseudoPropertyValueNamed("prop.nested[2]", target); assertNotNull(value); assertEquals("2", value); }
public static void writePseudoPropertyValueNamed(String propertyName, Object bean, Object newValue) { Args.checkNotBlank(propertyName); Args.checkNotNull(bean); String[] properties = propertyName.split("\\."); String propertyToWrite = propertyName; Object writable = bean; if (properties.length > 1) { writable = readPseudoPropertyValueNamed( Strings.joinBy(".", Arrays.slice(properties, 0, properties.length - 1)), bean); propertyToWrite = properties[properties.length - 1]; } Matcher matcher = ARRAY_PROPERTY_PATTERN.matcher(propertyToWrite); if (matcher.matches()) { String arrayPropertyName = matcher.group(1); Integer arrayPropertyIndex = Integer.valueOf(matcher.group(2)); Object array = readPseudoPropertyValueNamed0(arrayPropertyName, writable); writeElementAt(arrayPropertyIndex, array, newValue); } else { writePseudoPropertyValueNamed0(propertyToWrite, writable, newValue); } }
Beans { public static void writePseudoPropertyValueNamed(String propertyName, Object bean, Object newValue) { Args.checkNotBlank(propertyName); Args.checkNotNull(bean); String[] properties = propertyName.split("\\."); String propertyToWrite = propertyName; Object writable = bean; if (properties.length > 1) { writable = readPseudoPropertyValueNamed( Strings.joinBy(".", Arrays.slice(properties, 0, properties.length - 1)), bean); propertyToWrite = properties[properties.length - 1]; } Matcher matcher = ARRAY_PROPERTY_PATTERN.matcher(propertyToWrite); if (matcher.matches()) { String arrayPropertyName = matcher.group(1); Integer arrayPropertyIndex = Integer.valueOf(matcher.group(2)); Object array = readPseudoPropertyValueNamed0(arrayPropertyName, writable); writeElementAt(arrayPropertyIndex, array, newValue); } else { writePseudoPropertyValueNamed0(propertyToWrite, writable, newValue); } } }
Beans { public static void writePseudoPropertyValueNamed(String propertyName, Object bean, Object newValue) { Args.checkNotBlank(propertyName); Args.checkNotNull(bean); String[] properties = propertyName.split("\\."); String propertyToWrite = propertyName; Object writable = bean; if (properties.length > 1) { writable = readPseudoPropertyValueNamed( Strings.joinBy(".", Arrays.slice(properties, 0, properties.length - 1)), bean); propertyToWrite = properties[properties.length - 1]; } Matcher matcher = ARRAY_PROPERTY_PATTERN.matcher(propertyToWrite); if (matcher.matches()) { String arrayPropertyName = matcher.group(1); Integer arrayPropertyIndex = Integer.valueOf(matcher.group(2)); Object array = readPseudoPropertyValueNamed0(arrayPropertyName, writable); writeElementAt(arrayPropertyIndex, array, newValue); } else { writePseudoPropertyValueNamed0(propertyToWrite, writable, newValue); } } private  Beans(); }
Beans { public static void writePseudoPropertyValueNamed(String propertyName, Object bean, Object newValue) { Args.checkNotBlank(propertyName); Args.checkNotNull(bean); String[] properties = propertyName.split("\\."); String propertyToWrite = propertyName; Object writable = bean; if (properties.length > 1) { writable = readPseudoPropertyValueNamed( Strings.joinBy(".", Arrays.slice(properties, 0, properties.length - 1)), bean); propertyToWrite = properties[properties.length - 1]; } Matcher matcher = ARRAY_PROPERTY_PATTERN.matcher(propertyToWrite); if (matcher.matches()) { String arrayPropertyName = matcher.group(1); Integer arrayPropertyIndex = Integer.valueOf(matcher.group(2)); Object array = readPseudoPropertyValueNamed0(arrayPropertyName, writable); writeElementAt(arrayPropertyIndex, array, newValue); } else { writePseudoPropertyValueNamed0(propertyToWrite, writable, newValue); } } private  Beans(); static String capitalize(String capitalizee); static String decapitalize(String decapitalizee); static String decapitalize(String decapitalizee, boolean doubleUppercaseEnable); static boolean isPropertyReader(String suspect); static boolean isPropertyWriter(String suspect); static boolean isPropertyAccessor(String suspect); static String generatePropertyNameFor(String accessorName); static T make(Class<T> clazz); static PropertyDescriptor[] findPropertyDescriptorsFor(Class<?> clazz); static PropertyDescriptor findPropertyDescriptorFor(Class<?> clazz, String propertyName); static Object readPropertyValueNamed(String propertyName, Object bean); static void writePropertyValueNamed(String propertyName, Object bean, Object newValue); static Object readPseudoPropertyValueNamed(String propertyName, Object bean); static void writePseudoPropertyValueNamed(String propertyName, Object bean, Object newValue); static String[] listPseudoPropertyNames(Class<?> clazz); static Class<?> detectDeclaredPropertyType(String propertyName, Class<?> target); }
Beans { public static void writePseudoPropertyValueNamed(String propertyName, Object bean, Object newValue) { Args.checkNotBlank(propertyName); Args.checkNotNull(bean); String[] properties = propertyName.split("\\."); String propertyToWrite = propertyName; Object writable = bean; if (properties.length > 1) { writable = readPseudoPropertyValueNamed( Strings.joinBy(".", Arrays.slice(properties, 0, properties.length - 1)), bean); propertyToWrite = properties[properties.length - 1]; } Matcher matcher = ARRAY_PROPERTY_PATTERN.matcher(propertyToWrite); if (matcher.matches()) { String arrayPropertyName = matcher.group(1); Integer arrayPropertyIndex = Integer.valueOf(matcher.group(2)); Object array = readPseudoPropertyValueNamed0(arrayPropertyName, writable); writeElementAt(arrayPropertyIndex, array, newValue); } else { writePseudoPropertyValueNamed0(propertyToWrite, writable, newValue); } } private  Beans(); static String capitalize(String capitalizee); static String decapitalize(String decapitalizee); static String decapitalize(String decapitalizee, boolean doubleUppercaseEnable); static boolean isPropertyReader(String suspect); static boolean isPropertyWriter(String suspect); static boolean isPropertyAccessor(String suspect); static String generatePropertyNameFor(String accessorName); static T make(Class<T> clazz); static PropertyDescriptor[] findPropertyDescriptorsFor(Class<?> clazz); static PropertyDescriptor findPropertyDescriptorFor(Class<?> clazz, String propertyName); static Object readPropertyValueNamed(String propertyName, Object bean); static void writePropertyValueNamed(String propertyName, Object bean, Object newValue); static Object readPseudoPropertyValueNamed(String propertyName, Object bean); static void writePseudoPropertyValueNamed(String propertyName, Object bean, Object newValue); static String[] listPseudoPropertyNames(Class<?> clazz); static Class<?> detectDeclaredPropertyType(String propertyName, Class<?> target);  }