@Test public void testClassLoadingType() { TestObj testObj = new TestObj(); assertEquals(500, TestObj.kControlLoopPeriod,0); assertEquals(500, TestObj.kNetworkTableUpdateRate,0); AbstractSystemSettingsUtils.copyOverValues(PracticeBotSystemSettings.getInstance(), testObj); assertEquals(0.01, TestObj.kControlLoopPeriod,0); assertEquals(0.01, TestObj.kNetworkTableUpdateRate,0); }
public static void copyOverValues(Object fromObject, Object destinationObject) { if(fromObject == null || destinationObject == null) { return; } Field [] allFields = fromObject.getClass().getFields(); Map<String,Object>baseClassMap = Arrays.stream(allFields).filter(aField->Modifier.isStatic(aField.getModifiers())).collect(Collectors.toMap(aField->aField.getName(), aField->{ try { return aField.get(destinationObject); } catch(Exception e) { System.err.println("Unable to get field: " + aField.getName() +" from obj: " + destinationObject.getClass()); e.printStackTrace(); return null; } } )); baseClassMap.forEach((key,val)->System.out.println(key+", " + val)); Arrays.stream(destinationObject.getClass().getFields()).filter(aField->Modifier.isStatic(aField.getModifiers())).forEach(aField->{ Object value = baseClassMap.get(aField.getName()); if(value != null) { try { System.out.println("Setting field: " + aField.getName() +" to: " + value); aField.set(destinationObject, value); } catch(Exception e) { System.err.println("Unable to set the field: " + aField.getName()+" on object: "+ destinationObject.getClass()); e.printStackTrace(); } } }); }
AbstractSystemSettingsUtils { public static void copyOverValues(Object fromObject, Object destinationObject) { if(fromObject == null || destinationObject == null) { return; } Field [] allFields = fromObject.getClass().getFields(); Map<String,Object>baseClassMap = Arrays.stream(allFields).filter(aField->Modifier.isStatic(aField.getModifiers())).collect(Collectors.toMap(aField->aField.getName(), aField->{ try { return aField.get(destinationObject); } catch(Exception e) { System.err.println("Unable to get field: " + aField.getName() +" from obj: " + destinationObject.getClass()); e.printStackTrace(); return null; } } )); baseClassMap.forEach((key,val)->System.out.println(key+", " + val)); Arrays.stream(destinationObject.getClass().getFields()).filter(aField->Modifier.isStatic(aField.getModifiers())).forEach(aField->{ Object value = baseClassMap.get(aField.getName()); if(value != null) { try { System.out.println("Setting field: " + aField.getName() +" to: " + value); aField.set(destinationObject, value); } catch(Exception e) { System.err.println("Unable to set the field: " + aField.getName()+" on object: "+ destinationObject.getClass()); e.printStackTrace(); } } }); } }
AbstractSystemSettingsUtils { public static void copyOverValues(Object fromObject, Object destinationObject) { if(fromObject == null || destinationObject == null) { return; } Field [] allFields = fromObject.getClass().getFields(); Map<String,Object>baseClassMap = Arrays.stream(allFields).filter(aField->Modifier.isStatic(aField.getModifiers())).collect(Collectors.toMap(aField->aField.getName(), aField->{ try { return aField.get(destinationObject); } catch(Exception e) { System.err.println("Unable to get field: " + aField.getName() +" from obj: " + destinationObject.getClass()); e.printStackTrace(); return null; } } )); baseClassMap.forEach((key,val)->System.out.println(key+", " + val)); Arrays.stream(destinationObject.getClass().getFields()).filter(aField->Modifier.isStatic(aField.getModifiers())).forEach(aField->{ Object value = baseClassMap.get(aField.getName()); if(value != null) { try { System.out.println("Setting field: " + aField.getName() +" to: " + value); aField.set(destinationObject, value); } catch(Exception e) { System.err.println("Unable to set the field: " + aField.getName()+" on object: "+ destinationObject.getClass()); e.printStackTrace(); } } }); } private  AbstractSystemSettingsUtils(); }
AbstractSystemSettingsUtils { public static void copyOverValues(Object fromObject, Object destinationObject) { if(fromObject == null || destinationObject == null) { return; } Field [] allFields = fromObject.getClass().getFields(); Map<String,Object>baseClassMap = Arrays.stream(allFields).filter(aField->Modifier.isStatic(aField.getModifiers())).collect(Collectors.toMap(aField->aField.getName(), aField->{ try { return aField.get(destinationObject); } catch(Exception e) { System.err.println("Unable to get field: " + aField.getName() +" from obj: " + destinationObject.getClass()); e.printStackTrace(); return null; } } )); baseClassMap.forEach((key,val)->System.out.println(key+", " + val)); Arrays.stream(destinationObject.getClass().getFields()).filter(aField->Modifier.isStatic(aField.getModifiers())).forEach(aField->{ Object value = baseClassMap.get(aField.getName()); if(value != null) { try { System.out.println("Setting field: " + aField.getName() +" to: " + value); aField.set(destinationObject, value); } catch(Exception e) { System.err.println("Unable to set the field: " + aField.getName()+" on object: "+ destinationObject.getClass()); e.printStackTrace(); } } }); } private  AbstractSystemSettingsUtils(); static void loadPracticeSettings(SystemSettings sysSettings); static void copyOverValues(Object fromObject, Object destinationObject); static Map<String,String> getAllCurrentPropsAndValues(Object obj); static boolean isPracticeBot(); }
AbstractSystemSettingsUtils { public static void copyOverValues(Object fromObject, Object destinationObject) { if(fromObject == null || destinationObject == null) { return; } Field [] allFields = fromObject.getClass().getFields(); Map<String,Object>baseClassMap = Arrays.stream(allFields).filter(aField->Modifier.isStatic(aField.getModifiers())).collect(Collectors.toMap(aField->aField.getName(), aField->{ try { return aField.get(destinationObject); } catch(Exception e) { System.err.println("Unable to get field: " + aField.getName() +" from obj: " + destinationObject.getClass()); e.printStackTrace(); return null; } } )); baseClassMap.forEach((key,val)->System.out.println(key+", " + val)); Arrays.stream(destinationObject.getClass().getFields()).filter(aField->Modifier.isStatic(aField.getModifiers())).forEach(aField->{ Object value = baseClassMap.get(aField.getName()); if(value != null) { try { System.out.println("Setting field: " + aField.getName() +" to: " + value); aField.set(destinationObject, value); } catch(Exception e) { System.err.println("Unable to set the field: " + aField.getName()+" on object: "+ destinationObject.getClass()); e.printStackTrace(); } } }); } private  AbstractSystemSettingsUtils(); static void loadPracticeSettings(SystemSettings sysSettings); static void copyOverValues(Object fromObject, Object destinationObject); static Map<String,String> getAllCurrentPropsAndValues(Object obj); static boolean isPracticeBot();  }