@Test public void testOverwriteWithItself() { TestPojo pojo1 = new TestPojo(100, "foo"); pojo1.overwrite(pojo1); assertEquals(100, pojo1.id); assertEquals("foo", pojo1.value); }
@NonNull @SuppressWarnings("unchecked") public T overwrite(@NonNull final T other) { checkNotNull(other, "Can't overwrite with null value"); if (equals(other)) { return (T) this; } for (Field field : getTypeParameterClass().getDeclaredFields()) { final int modifiers = field.getModifiers(); if (hasIllegalAccessModifiers(modifiers)) { continue; } if (!Modifier.isPublic(modifiers) || Modifier.isFinal(modifiers)) { field.setAccessible(true); } try { if (!isEmpty(field, other)) { field.set(this, field.get(other)); } } catch (IllegalAccessException e) { Log.e(TAG, "Failed set at " + field.getName(), e); } } return (T) this; }
OverwritablePojo { @NonNull @SuppressWarnings("unchecked") public T overwrite(@NonNull final T other) { checkNotNull(other, "Can't overwrite with null value"); if (equals(other)) { return (T) this; } for (Field field : getTypeParameterClass().getDeclaredFields()) { final int modifiers = field.getModifiers(); if (hasIllegalAccessModifiers(modifiers)) { continue; } if (!Modifier.isPublic(modifiers) || Modifier.isFinal(modifiers)) { field.setAccessible(true); } try { if (!isEmpty(field, other)) { field.set(this, field.get(other)); } } catch (IllegalAccessException e) { Log.e(TAG, "Failed set at " + field.getName(), e); } } return (T) this; } }
OverwritablePojo { @NonNull @SuppressWarnings("unchecked") public T overwrite(@NonNull final T other) { checkNotNull(other, "Can't overwrite with null value"); if (equals(other)) { return (T) this; } for (Field field : getTypeParameterClass().getDeclaredFields()) { final int modifiers = field.getModifiers(); if (hasIllegalAccessModifiers(modifiers)) { continue; } if (!Modifier.isPublic(modifiers) || Modifier.isFinal(modifiers)) { field.setAccessible(true); } try { if (!isEmpty(field, other)) { field.set(this, field.get(other)); } } catch (IllegalAccessException e) { Log.e(TAG, "Failed set at " + field.getName(), e); } } return (T) this; }  }
OverwritablePojo { @NonNull @SuppressWarnings("unchecked") public T overwrite(@NonNull final T other) { checkNotNull(other, "Can't overwrite with null value"); if (equals(other)) { return (T) this; } for (Field field : getTypeParameterClass().getDeclaredFields()) { final int modifiers = field.getModifiers(); if (hasIllegalAccessModifiers(modifiers)) { continue; } if (!Modifier.isPublic(modifiers) || Modifier.isFinal(modifiers)) { field.setAccessible(true); } try { if (!isEmpty(field, other)) { field.set(this, field.get(other)); } } catch (IllegalAccessException e) { Log.e(TAG, "Failed set at " + field.getName(), e); } } return (T) this; }  @NonNull @SuppressWarnings("unchecked") T overwrite(@NonNull final T other); @Override boolean equals(Object o); }
OverwritablePojo { @NonNull @SuppressWarnings("unchecked") public T overwrite(@NonNull final T other) { checkNotNull(other, "Can't overwrite with null value"); if (equals(other)) { return (T) this; } for (Field field : getTypeParameterClass().getDeclaredFields()) { final int modifiers = field.getModifiers(); if (hasIllegalAccessModifiers(modifiers)) { continue; } if (!Modifier.isPublic(modifiers) || Modifier.isFinal(modifiers)) { field.setAccessible(true); } try { if (!isEmpty(field, other)) { field.set(this, field.get(other)); } } catch (IllegalAccessException e) { Log.e(TAG, "Failed set at " + field.getName(), e); } } return (T) this; }  @NonNull @SuppressWarnings("unchecked") T overwrite(@NonNull final T other); @Override boolean equals(Object o);  }