Skip to content

Commit

Permalink
Merge pull request #29 from NelminDev/main
Browse files Browse the repository at this point in the history
Generic Type
  • Loading branch information
Osiris-Team committed Aug 20, 2023
2 parents d876f31 + 2409c76 commit 6cd7a74
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/osiris/dyml/YamlSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@ public List<SmartString> getValues() {
return values;
}

/**
* See {@link #setValues(List)} for details.
*/
public <T> YamlSection setValues(T... v) {
setValues(utils.arrayToValuesList(v));
return this;
}

/**
* See {@link #setValues(List)} for details.
*/
Expand Down Expand Up @@ -422,6 +430,14 @@ public List<SmartString> getDefValues() {
return defaultValues;
}

/**
* See {@link #setDefValues(List)} for details.
*/
public <T> YamlSection setDefValues(T... v) {
setDefValues(utils.arrayToValuesList(v));
return this;
}

/**
* See {@link #setDefValues(List)} for details.
*/
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/com/osiris/dyml/utils/UtilsYamlSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class UtilsYamlSection {

/**
* Searches for a module with the same keys and returns it if it finds it, else null.
*
* @param queryModule use this modules keys to search for a matching module.
* @param queryModule use these modules keys to search for a matching module.
* @param modules the list in which to search for the module.
* @return a module containing exactly the same keys or null if it doesn't.
*/
Expand Down Expand Up @@ -98,15 +99,26 @@ public int getClosestParentIndex(List<String> keys, List<YamlSection> sections)
return index;
}

public <T> List<SmartString> arrayToValuesList(T[] array) {
List<SmartString> values = new ArrayList<>();
for (T t : array) {
values.add(new SmartString(t.toString()));
}
return values;
}

public List<SmartString> stringArrayToValuesList(String[] array) {
return stringListToValuesList(Arrays.asList(array));
return arrayToValuesList(array);
}

public List<SmartString> stringListToValuesList(List<String> list) {
return listToValuesList(list);
}

public <T> List<SmartString> listToValuesList(List<T> list) {
List<SmartString> values = new ArrayList<>();
for (String s :
list) {
values.add(new SmartString(s));
for (T t : list) {
values.add(new SmartString(t.toString()));
}
return values;
}
Expand Down

0 comments on commit 6cd7a74

Please sign in to comment.