Skip to content

Commit

Permalink
Add type to getList
Browse files Browse the repository at this point in the history
Add type to getList, now attempt to get any type
  • Loading branch information
virustotalop committed Aug 1, 2020
1 parent 81548db commit 75b2a04
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
25 changes: 12 additions & 13 deletions src/main/java/com/clubobsidian/wrappy/ConfigurationSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,48 +97,47 @@ public Pattern getPattern(String path) {
}

public List<String> getStringList(String path) {
return new NodeHelper<String>(this.node).getList(path, String.class);
return this.getList(path, String.class);
}

public List<Integer> getIntegerList(String path) {
return new NodeHelper<Integer>(this.node).getList(path, Integer.class);
return this.getList(path, Integer.class);
}

public List<Long> getLongList(String path) {
return new NodeHelper<Long>(this.node).getList(path, Long.class);
return this.getList(path, Long.class);
}

public List<Float> getFloatList(String path) {
return new NodeHelper<Float>(this.node).getList(path, Float.class);
return this.getList(path, Float.class);
}

public List<Boolean> getBooleanList(String path) {
return new NodeHelper<Boolean>(this.node).getList(path, Boolean.class);
return this.getList(path, Boolean.class);
}

public List<Double> getDoubleList(String path) {
return new NodeHelper<Double>(this.node).getList(path, Double.class);
return this.getList(path, Double.class);
}

public List<URI> getURIList(String path) {
return new NodeHelper<URI>(this.node).getList(path, URI.class);
return this.getList(path, URI.class);
}

public List<URL> getURLList(String path) {
return new NodeHelper<URL>(this.node).getList(path, URL.class);
return this.getList(path, URL.class);
}

public List<UUID> getUUIDList(String path) {
return new NodeHelper<UUID>(this.node).getList(path, UUID.class);
return this.getList(path, UUID.class);
}

public List<Pattern> getPatternList(String path) {
return new NodeHelper<Pattern>(this.node).getList(path, Pattern.class);
return this.getList(path, Pattern.class);
}

@SuppressWarnings({ "unchecked", "rawtypes" })
public List getList(String path, Class<?> clazz) {
return new NodeHelper(this.node).getList(path, clazz);
public <T> List<T> getList(String path, Class<T> clazz) {
return new NodeHelper<T>(this.node).getList(path, clazz);
}

public ConfigurationSection createConfigurationSection(String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,39 +125,34 @@ public void testGetDoubleList() {

@Test
public void testGenericIntegerList() {
@SuppressWarnings("unchecked")
List<Integer> list = config.getList("integer-list", Integer.class);
assertTrue("Config getIntegerList 1 index is not 7", list.get(1) == 7);
assertTrue("Config getIntegerList size is not 2", list.size() == 2);
}

@Test
public void testGenericLongList() {
@SuppressWarnings("unchecked")
List<Long> list = config.getList("long-list", Long.class);
assertTrue("Config getIntegerList 1 index is not 5", list.get(0) == 5);
assertTrue("Config getIntegerList size is not 1", list.size() == 1);
}

@Test
public void testGenericFloatList() {
@SuppressWarnings("unchecked")
List<Float> list = config.getList("float-list", Float.class);
assertTrue("Config getFloatList 1 index is not greater than 0", list.get(0) > 0);
assertTrue("Config getFloatList size is not 1", list.size() == 1);
}

@Test
public void testGenericBooleanList() {
@SuppressWarnings("unchecked")
List<Boolean> list = config.getList("boolean-list", Boolean.class);
assertFalse("Config getBooleanList 1 index is not false", list.get(1));
assertTrue("Config getBooleanList size is not 2", list.size() == 2);
}

@Test
public void testGenericDoubleList() {
@SuppressWarnings("unchecked")
List<Double> list = config.getList("double-list", Double.class);
assertTrue("Config getDoubleList 1 index is not > 1 && < 2", list.get(0) > 1 && list.get(0) < 2);
assertTrue("Config getDoubleList size is not 1", list.size() == 1);
Expand Down

0 comments on commit 75b2a04

Please sign in to comment.