2 * Copyright (c) 2019-2020. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.scanner;
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.util.Properties;
24 * ChessHogScanner properties holder.
26 * @author Dmitry Samoshin aka gotty
28 public class ScannerProperties {
30 /** Properties file. */
31 private static final String PROPERTIES_FILE = "scanner.properties";
34 private static final Properties PROPERTIES;
37 * Static properties initialization.
40 PROPERTIES = new Properties();
41 readProperties(PROPERTIES_FILE, PROPERTIES, true);
45 * @param propsFile Properties file name.
46 * @param props Properties.
47 * @param throwExc Flag indicating whether to throw an exception or not.
49 public static void readProperties(String propsFile, Properties props, boolean throwExc) {
50 try (InputStream is = ScannerProperties.class.getClassLoader().getResourceAsStream(propsFile))
54 throw new RuntimeException(
55 String.format("Failed to find properties file: %s", propsFile)
62 } catch (IOException cause) {
63 throw new RuntimeException(
64 String.format("Failed to read properties file: %s", propsFile),
71 * Empty string for not found properties.
73 private static final String EMPTY = "";
76 * Gets string property value.
78 * @param key Property key.
79 * @return Property value (possibly empty string, but never {@code null}).
81 public static String get(String key) {
82 return PROPERTIES.getProperty(key, EMPTY);
86 * Gets boolean property value.
88 * @param key Property key.
89 * @return Property value ({@code false} by default).
91 public static boolean is(String key) {
92 return Boolean.parseBoolean(
93 PROPERTIES.getProperty(key, Boolean.FALSE.toString())
98 * Zero integer for not found properties.
100 private static final String ZERO = "0";
103 * Gets integer property value.
105 * @param key Property key.
106 * @return Property value ({@code 0} by default).
108 public static int getInt(String key) {
109 return Integer.parseInt(
110 PROPERTIES.getProperty(key, ZERO)
115 * Private constructor.
117 private ScannerProperties() {