View Javadoc
1   package com.github.mygreen.supercsv.localization;
2   
3   import java.util.Objects;
4   import java.util.Optional;
5   import java.util.Properties;
6   
7   
8   /**
9    * {@link Properties}を元にメッセージを解決するためのクラス。
10   * 
11   * @version 2.0
12   * @author T.TSUCHIE
13   *
14   */
15  public class PropertiesMessageResolver implements MessageResolver {
16      
17      private Properties properties;
18      
19      /**
20       * デフォルトのコンストラクタ。
21       * <p>プロパティの中身は空です。</p>
22       */
23      public PropertiesMessageResolver() {
24          this.properties = new Properties();
25      }
26      
27      /**
28       * プロパティを指定してインスタンスを作成する。
29       * @param properties
30       * @throws NullPointerException properties is null.
31       */
32      public PropertiesMessageResolver(final Properties properties) {
33          Objects.requireNonNull(properties, "properties should not be null.");
34          
35          this.properties = properties;
36      }
37      
38      /**
39       * {@inheritDoc}
40       */
41      @Override
42      public Optional<String> getMessage(final String code) {
43          return Optional.ofNullable(properties.getProperty(code));
44      }
45      
46      /**
47       * 
48       * @return 設定されているプロパティを取得する。
49       */
50      public Properties getProperties() {
51          return properties;
52      }
53      
54      /**
55       * プロパティを設定する
56       * @param properties 設定されているプロパティ
57       */
58      public void setProperties(Properties properties) {
59          this.properties = properties;
60      }
61      
62  }