Skip to content

Commit

Permalink
refactor: deprecate mergeProperties in favour of Maps.merge
Browse files Browse the repository at this point in the history
Related to issue #294
  • Loading branch information
aureamunoz authored and iocanel committed Jul 30, 2019
1 parent 3c9b5ee commit b5cec5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Expand Up @@ -46,6 +46,8 @@
import java.util.List;
import java.util.Map;

import static io.dekorate.utils.Maps.*;

public abstract class AbstractAnnotationProcessor extends AbstractProcessor implements WithProject {

protected static final String PACKAGE = "";
Expand Down Expand Up @@ -92,11 +94,11 @@ protected Map<String, Object> readApplicationConfig(String... resourceNames) {
for (String resourceName : resourceNames) {
try (InputStream is = new FileInputStream(getProject().getBuildInfo().getResourceDir().resolve(resourceName).toFile())) {
if (resourceName.endsWith(".properties")) {
Map<String, Object> newProps = Maps.fromProperties(is);
mergeProperties(result, newProps);
Map<String, Object> newProps = fromProperties(is);
merge(result, newProps);
} else if (resourceName.endsWith(".yml") || resourceName.endsWith(".yaml")) {
Map<String, Object> newProps = Maps.fromYaml(is);
mergeProperties(result, newProps);
Map<String, Object> newProps = fromYaml(is);
merge(result, newProps);
} else {
throw new IllegalArgumentException("Illegal resource name:" + resourceName + ". It needs to be properties or yaml file.");
}
Expand All @@ -109,6 +111,12 @@ protected Map<String, Object> readApplicationConfig(String... resourceNames) {
return result;
}

/**
* Does exactly the same thing than Maps.merge. Let's just keep Maps.merge which has a wider scope..
*
* @deprecated use {@link Maps#merge(Map, Map)} ()} instead.
*/
@Deprecated
private void mergeProperties(Map<String, Object> result, Map<String, Object> newProps) {
for(String newKey : newProps.keySet()) {
if(result.containsKey(newKey) && Map.class.isInstance(result.get(newKey)) && Map.class.isInstance(newProps.get(newKey))) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/io/dekorate/utils/Maps.java
Expand Up @@ -121,7 +121,7 @@ private static Map<String, Object> asMap(String[] keys, Object value) {
* @param existing the existing map.
* @param map the map that will be merged into the existing.
*/
private static void merge(Map<String, Object> existing, Map<String, Object> map) {
public static void merge(Map<String, Object> existing, Map<String, Object> map) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
Expand Down

0 comments on commit b5cec5e

Please sign in to comment.