/** * If this node has list values, this function unwraps them and converts them to an appropriate type based on the * provided type. * If this node has a scalar value, this function treats it as a list with one value * * @param type The expected type * @param <T> The expected type * @return An immutable copy of the values contained */ default <T> List<T> getList(TypeToken<T> type) throws ObjectMappingException { return getList(type, ImmutableList.of()); }
public PlayerFilter(WebHook hook, ConfigurationNode config) { super(hook, config); try { players = config.getList(TypeToken.of(String.class)); } catch (ObjectMappingException e) { e.printStackTrace(); } }
public ItemTypeFilter(WebHook hook, ConfigurationNode config) { super(hook, config); try { items = config.getList(TypeToken.of(ItemType.class)); } catch (ObjectMappingException e) { e.printStackTrace(); } }
public BlockTypeFilter(WebHook hook, ConfigurationNode config) { super(hook, config); try { types = config.getList(TypeToken.of(BlockType.class)); } catch (ObjectMappingException e) { e.printStackTrace(); } }
/** * If this node has list values, this function unwraps them and converts them to an appropriate * type based on the provided function. * * <p>If this node has a scalar value, this function treats it as a list with one value.</p> * * @param type The expected type * @param <T> The expected type * @return An immutable copy of the values contained */ @NonNull default <T> List<T> getList(@NonNull TypeToken<T> type) throws ObjectMappingException { return getList(type, ImmutableList.of()); }
/** * If this node has list values, this function unwraps them and converts them to an appropriate * type based on the provided function. * * <p>If this node has a scalar value, this function treats it as a list with one value.</p> * * @param type The expected type * @param <T> The expected type * @return An immutable copy of the values contained */ @NonNull default <T> List<T> getList(@NonNull TypeToken<T> type) throws ObjectMappingException { return getList(type, ImmutableList.of()); }
@Override public WebBook deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { String id = value.getNode("id").getString(); String title = value.getNode("title").getString(); List<String> lines = value.getNode("lines").getList(TypeToken.of(String.class)); return new WebBook(id, title, lines); }
static ConfigurationTransformation threeToFour() { return ConfigurationTransformation.chain( tBuilder() .addAction(new Object[]{"worlds", WILDCARD_OBJECT, "inheritance"}, (inputPath, valueAtPath) -> { try { valueAtPath.setValue(Lists.transform(valueAtPath.getList(TypeToken.of(String.class)), input -> "world:" + input)); } catch (ObjectMappingException e) { throw new RuntimeException(e); } return new Object[]{"context-inheritance", "world:" + inputPath.get(1)}; }).build(), tBuilder() .addAction(new Object[]{"worlds"}, (inputPath, valueAtPath) -> { valueAtPath.setValue(null); return null; }).build()); }
WebHook.WebHookDataType dataType = value.getNode("dataType").getValue(TypeToken.of(WebHook.WebHookDataType.class)); boolean form = value.getNode("form").getBoolean(); List<WebHookHeader> headers = value.getNode("headers").getList(TypeToken.of(WebHookHeader.class)); boolean details = value.getNode("details").getBoolean();
@Test public void testSimpleLoading() throws IOException { URL url = getClass().getResource("/example.yml"); ConfigurationLoader loader = YAMLConfigurationLoader.builder() .setURL(url).build(); ConfigurationNode node = loader.load(); assertEquals("unicorn", node.getNode("test", "op-level").getValue()); assertEquals("dragon", node.getNode("other", "op-level").getValue()); assertEquals("dog park", node.getNode("other", "location").getValue()); Function<Object, Map<String, List>> f = o -> (HashMap<String, List>)o; List<Map<String, List>> fooList = new ArrayList<>(node.getNode("foo").getList(f)); assertEquals(0, fooList.get(0).get("bar").size()); } }
tBuilder() .addAction(new Object[]{WILDCARD_OBJECT, WILDCARD_OBJECT, WILDCARD_OBJECT, "permissions"}, (nodePath, configurationNode) -> { List<String> existing = configurationNode.getList(Object::toString); if (!existing.isEmpty()) { configurationNode.setValue(ImmutableMap.of());