Skip to content

Commit

Permalink
core: Improve BoundConfig's entrySet
Browse files Browse the repository at this point in the history
  • Loading branch information
TheElectronWill committed Apr 17, 2017
1 parent 0a662bc commit 039096a
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.electronwill.nightconfig.core.Config;
import com.electronwill.nightconfig.core.SimpleConfig;
import com.electronwill.nightconfig.core.utils.TransformingMap;
import com.electronwill.nightconfig.core.utils.TransformingSet;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
Expand Down Expand Up @@ -294,7 +295,7 @@ public <T> T setValue(List<String> path, Object value) {
throw new UnsupportedOperationException("Cannot add elements to a bound config");
} else if (searchResult.hasFieldInfos()) {
return (T)searchResult.fieldInfos.setValue(searchResult.parentConfig.object, value,
bypassFinal);
bypassFinal);
} else {
throw new UnsupportedOperationException(
"Cannot modify non-field elements of a bound config");
Expand All @@ -307,7 +308,8 @@ public <T> T removeValue(List<String> path) {
if (searchResult == null) {
return null;// Nothing to do
} else if (searchResult.hasFieldInfos()) {
return (T)searchResult.fieldInfos.removeValue(searchResult.parentConfig.object, bypassFinal);
return (T)searchResult.fieldInfos.removeValue(searchResult.parentConfig.object,
bypassFinal);
} else {
SimpleConfig copy = new SimpleConfig(searchResult.subConfig);
searchResult.subConfig.clear();
Expand Down Expand Up @@ -351,23 +353,23 @@ public Map<String, Object> valueMap() {

@Override
public Set<? extends Entry> entrySet() {
Function<Object, Object> readTransfo = object -> new Entry() {
Function<Map.Entry<String, Object>, Entry> readTransfo = entry -> new Entry() {
@Override
public Object setValue(Object value) {
return null;
public <T> T setValue(Object value) {
return BoundConfig.this.setValue(entry.getKey(), value);
}

@Override
public String getKey() {
return null;
return entry.getKey();
}

@Override
public <T> T getValue() {
return null;
return (T)entry.getValue();
}
};
return null;
return new TransformingSet<>(dataMap.entrySet(), readTransfo, o -> null, o -> o);
}

@Override
Expand Down

0 comments on commit 039096a

Please sign in to comment.