@Test public void testSet() { Citation citation = new CitationImpl(); final PropertyAccessor accessor = createPropertyAccessor(citation); Object value = "Random number"; int index = accessor.indexOf("ISBN"); assertTrue(index >= 0); assertNull(accessor.set(index, citation, value)); assertSame(value, accessor.get(index, citation)); assertSame(value, citation.getISBN()); index = accessor.indexOf("title"); assertTrue(index >= 0); assertNull(accessor.set(index, citation, "A random title")); value = accessor.get(index, citation); assertTrue(value instanceof InternationalString); assertEquals("A random title", value.toString()); assertSame(value, citation.getTitle()); index = accessor.indexOf("alternateTitle"); assertTrue(index >= 0); value = accessor.get(index, citation); assertTrue(value instanceof Collection); assertTrue(((Collection) value).isEmpty()); value = accessor.set(index, citation, "An other title"); assertTrue(value instanceof Collection); assertEquals(1, ((Collection) value).size()); value = accessor.set(index, citation, "Yet an other title"); assertTrue(value instanceof Collection); assertEquals(2, ((Collection) value).size()); }
final Object set(final int index, final Object metadata, final Object value) throws IllegalArgumentException, ClassCastException { String key; if (index >= 0 && index < getters.length && setters != null) { final Method getter = getters[index]; final Method setter = setters[index]; if (setter != null) { final Object old = get(getter, metadata); set(getter, setter, metadata, new Object[] {value}); return old; } else { key = getter.getName(); key = key.substring(prefix(key).length()); } } else { key = String.valueOf(index); } throw new IllegalArgumentException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$1, key)); }
PropertyAccessor { final Object set(final int index, final Object metadata, final Object value) throws IllegalArgumentException, ClassCastException { String key; if (index >= 0 && index < getters.length && setters != null) { final Method getter = getters[index]; final Method setter = setters[index]; if (setter != null) { final Object old = get(getter, metadata); set(getter, setter, metadata, new Object[] {value}); return old; } else { key = getter.getName(); key = key.substring(prefix(key).length()); } } else { key = String.valueOf(index); } throw new IllegalArgumentException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$1, key)); } }
PropertyAccessor { final Object set(final int index, final Object metadata, final Object value) throws IllegalArgumentException, ClassCastException { String key; if (index >= 0 && index < getters.length && setters != null) { final Method getter = getters[index]; final Method setter = setters[index]; if (setter != null) { final Object old = get(getter, metadata); set(getter, setter, metadata, new Object[] {value}); return old; } else { key = getter.getName(); key = key.substring(prefix(key).length()); } } else { key = String.valueOf(index); } throw new IllegalArgumentException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$1, key)); } PropertyAccessor(final Class<?> implementation, final Class<?> type); }
PropertyAccessor { final Object set(final int index, final Object metadata, final Object value) throws IllegalArgumentException, ClassCastException { String key; if (index >= 0 && index < getters.length && setters != null) { final Method getter = getters[index]; final Method setter = setters[index]; if (setter != null) { final Object old = get(getter, metadata); set(getter, setter, metadata, new Object[] {value}); return old; } else { key = getter.getName(); key = key.substring(prefix(key).length()); } } else { key = String.valueOf(index); } throw new IllegalArgumentException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$1, key)); } PropertyAccessor(final Class<?> implementation, final Class<?> type); boolean shallowEquals(final Object metadata1, final Object metadata2, final boolean skipNulls); boolean shallowCopy(final Object source, final Object target, final boolean skipNulls); int hashCode(final Object metadata); int count(final Object metadata, final int max); }
PropertyAccessor { final Object set(final int index, final Object metadata, final Object value) throws IllegalArgumentException, ClassCastException { String key; if (index >= 0 && index < getters.length && setters != null) { final Method getter = getters[index]; final Method setter = setters[index]; if (setter != null) { final Object old = get(getter, metadata); set(getter, setter, metadata, new Object[] {value}); return old; } else { key = getter.getName(); key = key.substring(prefix(key).length()); } } else { key = String.valueOf(index); } throw new IllegalArgumentException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$1, key)); } PropertyAccessor(final Class<?> implementation, final Class<?> type); boolean shallowEquals(final Object metadata1, final Object metadata2, final boolean skipNulls); boolean shallowCopy(final Object source, final Object target, final boolean skipNulls); int hashCode(final Object metadata); int count(final Object metadata, final int max);  }