@Test public void testGetConfigDescriptor() throws IOException { AccountSession accountSession = new AccountSession(UUID.randomUUID(), Instant.now()); accountSession.setUsername("test"); TestConfig conf = manager.getConfig(TestConfig.class); ConfigDescriptor descriptor = manager.getConfigDescriptor(conf); Assert.assertEquals(1, descriptor.getItems().size()); }
public ConfigDescriptor getConfigDescriptor(Object configurationProxy) { Class<?> inter = configurationProxy.getClass().getInterfaces()[0]; ConfigGroup group = inter.getAnnotation(ConfigGroup.class); if (group == null) { throw new IllegalArgumentException("Not a config group"); } List<ConfigItemDescriptor> items = Arrays.stream(inter.getMethods()) .filter(m -> m.getParameterCount() == 0) .sorted(Comparator.comparingInt(m -> m.getDeclaredAnnotation(ConfigItem.class).position())) .map(m -> new ConfigItemDescriptor( m.getDeclaredAnnotation(ConfigItem.class), m.getReturnType() )) .collect(Collectors.toList()); return new ConfigDescriptor(group, items); }
ConfigManager { public ConfigDescriptor getConfigDescriptor(Object configurationProxy) { Class<?> inter = configurationProxy.getClass().getInterfaces()[0]; ConfigGroup group = inter.getAnnotation(ConfigGroup.class); if (group == null) { throw new IllegalArgumentException("Not a config group"); } List<ConfigItemDescriptor> items = Arrays.stream(inter.getMethods()) .filter(m -> m.getParameterCount() == 0) .sorted(Comparator.comparingInt(m -> m.getDeclaredAnnotation(ConfigItem.class).position())) .map(m -> new ConfigItemDescriptor( m.getDeclaredAnnotation(ConfigItem.class), m.getReturnType() )) .collect(Collectors.toList()); return new ConfigDescriptor(group, items); } }
ConfigManager { public ConfigDescriptor getConfigDescriptor(Object configurationProxy) { Class<?> inter = configurationProxy.getClass().getInterfaces()[0]; ConfigGroup group = inter.getAnnotation(ConfigGroup.class); if (group == null) { throw new IllegalArgumentException("Not a config group"); } List<ConfigItemDescriptor> items = Arrays.stream(inter.getMethods()) .filter(m -> m.getParameterCount() == 0) .sorted(Comparator.comparingInt(m -> m.getDeclaredAnnotation(ConfigItem.class).position())) .map(m -> new ConfigItemDescriptor( m.getDeclaredAnnotation(ConfigItem.class), m.getReturnType() )) .collect(Collectors.toList()); return new ConfigDescriptor(group, items); } ConfigManager(); }
ConfigManager { public ConfigDescriptor getConfigDescriptor(Object configurationProxy) { Class<?> inter = configurationProxy.getClass().getInterfaces()[0]; ConfigGroup group = inter.getAnnotation(ConfigGroup.class); if (group == null) { throw new IllegalArgumentException("Not a config group"); } List<ConfigItemDescriptor> items = Arrays.stream(inter.getMethods()) .filter(m -> m.getParameterCount() == 0) .sorted(Comparator.comparingInt(m -> m.getDeclaredAnnotation(ConfigItem.class).position())) .map(m -> new ConfigItemDescriptor( m.getDeclaredAnnotation(ConfigItem.class), m.getReturnType() )) .collect(Collectors.toList()); return new ConfigDescriptor(group, items); } ConfigManager(); final void switchSession(AccountSession session); void load(); T getConfig(Class<T> clazz); String getConfiguration(String groupName, String key); T getConfiguration(String groupName, String key, Class<T> clazz); void setConfiguration(String groupName, String key, String value); void setConfiguration(String groupName, String key, Object value); void unsetConfiguration(String groupName, String key); ConfigDescriptor getConfigDescriptor(Object configurationProxy); void setDefaultConfiguration(Object proxy, boolean override); }
ConfigManager { public ConfigDescriptor getConfigDescriptor(Object configurationProxy) { Class<?> inter = configurationProxy.getClass().getInterfaces()[0]; ConfigGroup group = inter.getAnnotation(ConfigGroup.class); if (group == null) { throw new IllegalArgumentException("Not a config group"); } List<ConfigItemDescriptor> items = Arrays.stream(inter.getMethods()) .filter(m -> m.getParameterCount() == 0) .sorted(Comparator.comparingInt(m -> m.getDeclaredAnnotation(ConfigItem.class).position())) .map(m -> new ConfigItemDescriptor( m.getDeclaredAnnotation(ConfigItem.class), m.getReturnType() )) .collect(Collectors.toList()); return new ConfigDescriptor(group, items); } ConfigManager(); final void switchSession(AccountSession session); void load(); T getConfig(Class<T> clazz); String getConfiguration(String groupName, String key); T getConfiguration(String groupName, String key, Class<T> clazz); void setConfiguration(String groupName, String key, String value); void setConfiguration(String groupName, String key, Object value); void unsetConfiguration(String groupName, String key); ConfigDescriptor getConfigDescriptor(Object configurationProxy); void setDefaultConfiguration(Object proxy, boolean override);  }