Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add getMap and isMap in Config #1902

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/java/cn/nukkit/utils/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,18 @@ public List getList(String key, List defaultList) {
public boolean isList(String key) {
return config.isList(key);
}

public Map getMap(String key) {
return this.getMap(key, null);
}

public Map getMap(String key, List defaultList) {
return this.correct ? this.config.getMap(key, defaultList) : defaultList;
}

public boolean isMap(String key) {
return config.isMap(key);
}

public List<String> getStringList(String key) {
return config.getStringList(key);
Expand Down
36 changes: 35 additions & 1 deletion src/main/java/cn/nukkit/utils/ConfigSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,41 @@ public boolean isList(String key) {
Object val = get(key);
return val instanceof List;
}

/**
* Get Map value of config section element
*
* @param key - key (inside) current section
* @return
*/
public Map getMap(String key) {
return this.getMap(key, null);
}

/**
* Get Map value of config section element
*
* @param key - key (inside) current section
* @param defaultList - default value that will returned if section element is not exists
* @return
*/
public Map getMap(String key, List defaultList) {
return (Map) this.get(key, defaultList);
}

/**
* Check type of section element defined by key. Return true this element is Map
*
* @param key
* @return
*/
public boolean isMap(String key) {
Object val = get(key);
return val instanceof Map;
}



/**
* Get String List value of config section element
*
Expand Down Expand Up @@ -737,4 +771,4 @@ public Set<String> getKeys(boolean child) {
public Set<String> getKeys() {
return this.getKeys(true);
}
}
}