forked from nus-cs2103-AY1617S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from CS2103AUG2016-F11-C1/decouple-config-mai…
…napp Decouple Config from MainApp
- Loading branch information
Showing
10 changed files
with
81 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package seedu.todo.commons.core; | ||
|
||
import java.io.IOException; | ||
import java.util.Optional; | ||
import java.util.logging.Logger; | ||
|
||
import seedu.todo.MainApp; | ||
import seedu.todo.commons.exceptions.DataConversionException; | ||
import seedu.todo.commons.util.ConfigUtil; | ||
|
||
// @@author A0139812A | ||
public class ConfigCenter { | ||
private static final Logger logger = LogsCenter.getLogger(MainApp.class); | ||
|
||
private static ConfigCenter instance; | ||
|
||
private Config config; | ||
private String configFilePath; | ||
|
||
public static ConfigCenter getInstance() { | ||
if (instance == null) { | ||
instance = new ConfigCenter(); | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
public void setConfigFilePath(String path) { | ||
configFilePath = path; | ||
} | ||
|
||
public Config getConfig() { | ||
if (config == null) { | ||
Optional<Config> configOptional; | ||
|
||
try { | ||
configOptional = ConfigUtil.readConfig(configFilePath); | ||
config = configOptional.orElse(new Config()); | ||
} catch (DataConversionException e) { | ||
logger.warning("Config file at " + configFilePath + " is not in the correct format. " + | ||
"Using default config properties"); | ||
} | ||
} | ||
|
||
return config; | ||
} | ||
|
||
public void saveConfig(Config config) throws IOException { | ||
ConfigUtil.saveConfig(config, configFilePath); | ||
this.config = config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters