Skip to content
Merged
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.yahoo.bullet</groupId>
<artifactId>bullet-core</artifactId>
<version>0.2.6-SNAPSHOT</version>
<version>0.3.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>bullet-core</name>

Expand Down Expand Up @@ -193,7 +193,7 @@

<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<version>2.10.4</version>
<configuration>
<sourcepath>${project.basedir}/src/main/java</sourcepath>
</configuration>
Expand Down
288 changes: 281 additions & 7 deletions src/main/java/com/yahoo/bullet/BulletConfig.java

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions src/main/java/com/yahoo/bullet/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
package com.yahoo.bullet;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j;
import org.jvyaml.YAML;

Expand All @@ -24,7 +26,9 @@
@Slf4j
public class Config implements Serializable {
private Map<String, Object> data;

public static final String DELIMITER = ".";
private static Gson GSON = new GsonBuilder().serializeNulls().setPrettyPrinting().disableHtmlEscaping().create();

/**
* Constructor that loads a specific file and loads the settings in that file.
Expand All @@ -33,7 +37,6 @@ public class Config implements Serializable {
*/
public Config(String file) {
data = readYAML(file);
log.info("Final Configuration:\n{} ", data);
}

/**
Expand All @@ -47,7 +50,6 @@ public Config(String file, String defaultConfigurationFile) {
// Override
Map<String, Object> specificConf = readYAML(file);
data.putAll(specificConf);
log.info("Final Configuration with defaults:\n{} ", data);
}

/**
Expand Down Expand Up @@ -207,4 +209,9 @@ protected Map<String, Object> readYAML(String yamlFile) {
return new HashMap<>();
}
}

@Override
public String toString() {
return GSON.toJson(data);
}
}
28 changes: 21 additions & 7 deletions src/main/java/com/yahoo/bullet/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,27 @@
import java.util.Map;

public class Utilities {
/**
* Tries to get the object casted as the target type. If it is generic, the captured types cannot not be
* validated. Only the base object type is validated.
*
* @param entry The object to cast.
* @param clazz The class of the U.
* @param <U> The type to get the object as.
* @return The casted object of type U or null if the cast could not be done.
*/
@SuppressWarnings("unchecked")
public static <U> U getCasted(Object entry, Class<U> clazz) {
try {
return clazz.cast(entry);
} catch (ClassCastException ignored) {
}
return null;
}

/**
* Tries to get a key from a map as the target type. If it is a composite type, the internal types are not
* validated. Only the outermost object type is validated.
* Tries to get a key from a map as the target type. If it is a generic type, the captured types are not
* validated. Only the base object type is validated.
*
* @param map The non-null map that possibly contains the key.
* @param key The String key to get the value for from the map.
Expand All @@ -23,11 +41,7 @@ public class Utilities {
*/
@SuppressWarnings("unchecked")
public static <U> U getCasted(Map<String, Object> map, String key, Class<U> clazz) {
try {
return clazz.cast(map.get(key));
} catch (ClassCastException ignored) {
}
return null;
return getCasted(map.get(key), clazz);
}

/**
Expand Down
Loading