@Test public void merge() throws InvocationTargetException, IllegalAccessException { StringFieldMetadata custom = new StringFieldMetadata(); List<String> tokens = Arrays.asList("a", "b"); String fullPath = "fString.new"; custom.setFullPath(fullPath); custom.setTokens(tokens); StringFieldMetadata updated = FieldMetadataUtils.merge(custom, MetadataConstants.DEFAULT_STRING_META); LOGGER.info("{}", updated); assertEquals(updated.getFullPath(), fullPath); assertEquals(updated.getTokens(), tokens); assertTrue(updated.getTokens() != tokens); }
@SuppressWarnings("unchecked") public static <T extends FieldMetadata> T merge(T from, T to) throws IllegalStateException { try { T clone; clone = (T) invokeConstructor(from.getClass()); updateObject(to, clone); updateObject(from, clone); return clone; } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex) { throw new IllegalStateException("Failed to clone bean", ex); } }
FieldMetadataUtils { @SuppressWarnings("unchecked") public static <T extends FieldMetadata> T merge(T from, T to) throws IllegalStateException { try { T clone; clone = (T) invokeConstructor(from.getClass()); updateObject(to, clone); updateObject(from, clone); return clone; } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex) { throw new IllegalStateException("Failed to clone bean", ex); } } }
FieldMetadataUtils { @SuppressWarnings("unchecked") public static <T extends FieldMetadata> T merge(T from, T to) throws IllegalStateException { try { T clone; clone = (T) invokeConstructor(from.getClass()); updateObject(to, clone); updateObject(from, clone); return clone; } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex) { throw new IllegalStateException("Failed to clone bean", ex); } } private  FieldMetadataUtils(); }
FieldMetadataUtils { @SuppressWarnings("unchecked") public static <T extends FieldMetadata> T merge(T from, T to) throws IllegalStateException { try { T clone; clone = (T) invokeConstructor(from.getClass()); updateObject(to, clone); updateObject(from, clone); return clone; } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex) { throw new IllegalStateException("Failed to clone bean", ex); } } private  FieldMetadataUtils(); @SuppressWarnings("unchecked") static T diff(T from, T to); @SuppressWarnings("unchecked") static T merge(T from, T to); static void updateObject(T from, T to); }
FieldMetadataUtils { @SuppressWarnings("unchecked") public static <T extends FieldMetadata> T merge(T from, T to) throws IllegalStateException { try { T clone; clone = (T) invokeConstructor(from.getClass()); updateObject(to, clone); updateObject(from, clone); return clone; } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex) { throw new IllegalStateException("Failed to clone bean", ex); } } private  FieldMetadataUtils(); @SuppressWarnings("unchecked") static T diff(T from, T to); @SuppressWarnings("unchecked") static T merge(T from, T to); static void updateObject(T from, T to);  }