Settings.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Settings
  2. //
  3. // Douglas Thrift
  4. //
  5. // Settings.java
  6. /* Copyright 2011 Douglas Thrift
  7. *
  8. * This file is part of Big Screen Bot.
  9. *
  10. * Big Screen Bot is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * Big Screen Bot is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with Big Screen Bot. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. package net.douglasthrift.bigscreenbot;
  24. import java.io.FileNotFoundException;
  25. import java.io.FileReader;
  26. import java.io.IOException;
  27. import java.util.Arrays;
  28. import java.util.List;
  29. import java.util.Properties;
  30. public class Settings extends Properties
  31. {
  32. private static final String SETTINGS = "bigscreenbot.properties";
  33. public boolean getBooleanProperty(String key, boolean defaultValue)
  34. {
  35. String value = getProperty(key);
  36. if (value != null)
  37. return Boolean.parseBoolean(value);
  38. else
  39. return defaultValue;
  40. }
  41. public int getIntegerProperty(String key, int defaultValue)
  42. {
  43. String value = getProperty(key);
  44. if (value != null)
  45. return Integer.parseInt(value);
  46. else
  47. return defaultValue;
  48. }
  49. public List<String> getListProperty(String key)
  50. {
  51. String value = getProperty(key);
  52. if (value != null)
  53. return Arrays.asList(value.split("\\s"));
  54. else
  55. return null;
  56. }
  57. public void load() throws FileNotFoundException, IOException
  58. {
  59. FileReader reader = null;
  60. try
  61. {
  62. reader = new FileReader(SETTINGS);
  63. load(reader);
  64. }
  65. finally
  66. {
  67. if (reader != null)
  68. reader.close();
  69. }
  70. }
  71. }
  72. // vim: expandtab