From 146a0fb8b0e90f9196e569152f649baf60d6cc8f Mon Sep 17 00:00:00 2001
From: Joaquín Reñé <jrene@curisit.net>
Date: Tue, 07 Oct 2025 14:52:57 +0000
Subject: [PATCH] #4410 - Comments on classes

---
 securis/src/main/java/net/curisit/securis/utils/Config.java |  186 +++++++++++++++++++++++++++++-----------------
 1 files changed, 118 insertions(+), 68 deletions(-)

diff --git a/securis/src/main/java/net/curisit/securis/utils/Config.java b/securis/src/main/java/net/curisit/securis/utils/Config.java
index 1d43249..a2e4c35 100644
--- a/securis/src/main/java/net/curisit/securis/utils/Config.java
+++ b/securis/src/main/java/net/curisit/securis/utils/Config.java
@@ -1,3 +1,6 @@
+/*
+ * Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved.
+ */
 package net.curisit.securis.utils;
 
 import java.io.IOException;
@@ -11,17 +14,31 @@
 import org.apache.logging.log4j.Logger;
 
 /**
- * Class that loads and serves global config parameters.
+ * Config
+ * <p>
+ * Class that loads and serves global config parameters from a classpath properties file
+ * and, as a fallback, from environment variables.
+ *
+ * Initialization:
+ *  - Static initializer loads {@link #KEY_CONFIG_FILE} from classpath (fails hard if missing).
+ *
+ * Accessors:
+ *  - {@link #get(String)} / {@link #get(String, String)}
+ *  - Integer variants: {@link #getInt(String)} / {@link #getInt(String, int)}
+ *  - Namespaced helpers: by prefix/domain, and sequential lists via {@link #getListByPrefix(String)}.
+ *
+ * Thread-safety: static-only utility; internal state is read-only after init.
  * 
- * @author rsanchez
+ * @author JRA
+ * Last reviewed by JRA on Oct 5, 2025.
  */
 public class Config {
 
     private static final Logger LOG = LogManager.getLogger(Config.class);
 
     /**
-     * Key used to store config file resource location. In a web application,
-     * can be set as initial parameter in a servlet loaded on startup
+     * Resource path of the application properties file (in classpath).
+     * E.g. "/securis-server.properties".
      */
     public static final String KEY_CONFIG_FILE = "/securis-server.properties";
 
@@ -37,12 +54,12 @@
     }
 
     /**
-     * Loads application global parameters from a classpath resource
-     * 
-     * @param resource
-     *            : Resource location in classpath, i.e:
-     *            "/resource/cp-securis.conf"
-     * @throws IOException
+     * loadParameters
+     * <p>
+     * Loads application global parameters from a classpath resource.
+     *
+     * @param resource Classpath location (e.g. "/resource/cp-securis.conf").
+     * @throws IOException If the resource cannot be found or read.
      */
     public static void loadParameters(String resource) throws IOException {
 
@@ -51,7 +68,6 @@
 
         params = new Properties();
         try {
-
             params.load(fileis);
             LOG.debug("Params loaded OK from {}", resource);
         } catch (IOException e) {
@@ -59,84 +75,112 @@
             params = null;
             throw e;
         }
-
     }
 
+    /**
+     * getByDomain
+     * <p>
+     * Convenience accessor for domain-suffixed parameters (param.domain).
+     *
+     * @param domain     Domain suffix.
+     * @param paramname  Base parameter name.
+     * @return String value or null if not present.
+     */
     public static String getByDomain(String domain, String paramname) {
         return getByDomain(domain, paramname, null);
     }
 
+    /**
+     * getByPrefix
+     * <p>
+     * Returns parameter value from "{prefix}.{param}" or falls back to the plain "{param}".
+     *
+     * @param prefix    Namespace prefix.
+     * @param paramname Parameter name.
+     * @return Resolved value or null.
+     */
     public static String getByPrefix(String prefix, String paramname) {
         return get(prefix + "." + paramname, get(paramname));
     }
 
+    /**
+     * getByPrefix
+     * <p>
+     * Returns parameter value from "{prefix}.{param}" or provided default (which itself
+     * falls back to "{param}" or its default).
+     *
+     * @param prefix     Namespace prefix.
+     * @param paramname  Parameter name.
+     * @param defaultVal Default value if none resolved.
+     * @return Resolved value.
+     */
     public static String getByPrefix(String prefix, String paramname, String defaultVal) {
         return get(prefix + "." + paramname, get(paramname, defaultVal));
     }
 
+    /**
+     * getByDomain
+     * <p>
+     * Returns value from "{param}.{domain}" or provided default.
+     *
+     * @param domain     domain suffix.
+     * @param paramname  base name.
+     * @param defaultval fallback if not found.
+     * @return resolved string.
+     */
     public static String getByDomain(String domain, String paramname, String defaultval) {
         return get(paramname + "." + domain, defaultval);
     }
 
+    /**
+     * getIntByDomain
+     * <p>
+     * Integer variant of {@link #getByDomain(String, String)} with fallback to plain param.
+     */
     public static int getIntByDomain(String domain, String paramname) {
         return getInt(paramname + "." + domain, getInt(paramname));
     }
 
+    /**
+     * getIntByDomain
+     * <p>
+     * Integer variant returning provided default when missing.
+     */
     public static int getIntByDomain(String domain, String paramname, int defaultval) {
         return getInt(paramname + "." + domain, defaultval);
     }
 
     /**
-     * Gets a List with all values of properties that begins with
-     * <code>prefix</code> It reads sequentially. For example:
-     * 
-     * <pre>
-     * 	securis.sort.comparator.0: net.cp.securis.comparators.ComparePttidVsPtn
-     * 	securis.sort.comparator.1: net.cp.securis.comparators.CompareFrequency
-     * 	securis.sort.comparator.2: net.cp.securis.comparators.CompareOutgoingVsIncomming
-     * 	securis.sort.comparator.3: net.cp.securis.comparators.CompareDuration 
-     * 	securis.sort.comparator.4: net.cp.securis.comparators.CompareCallVsSms
-     * </pre>
-     * 
-     * That config (for prefix: "securis.sort.comparator" ) will return a
-     * List<String> with values:
-     * 
-     * <pre>
-     * 	"net.cp.securis.comparators.ComparePttidVsPtn", 
-     * 	"net.cp.securis.comparators.CompareFrequency", 
-     * 	"net.cp.securis.comparators.CompareOutgoingVsIncomming", 
-     * 	"net.cp.securis.comparators.CompareDuration", 
-     * 	"net.cp.securis.comparators.CompareCallVsSms"
-     * </pre>
-     * 
-     * Note: If there is a gap between suffixes process will stop, that is, only
-     * will be returned properties found before gap.
-     * 
-     * @param prefix
-     * @return
+     * getListByPrefix
+     * <p>
+     * Reads sequential properties using numeric suffixes starting from 0 and stops on first gap.
+     * Example:
+     *  securis.sort.comparator.0=...
+     *  securis.sort.comparator.1=...
+     *  ...
+     *
+     * @param prefix Base prefix (e.g. "securis.sort.comparator").
+     * @return Ordered list of values until first missing index.
      */
     public static List<String> getListByPrefix(String prefix) {
         List<String> list = new ArrayList<String>();
-
         String tpl = prefix + ".{0}";
-
         int i = 0;
         String value = get(MessageFormat.format(tpl, i++));
         while (value != null) {
             list.add(value);
             value = get(MessageFormat.format(tpl, i++));
         }
-
         return list;
     }
 
     /**
-     * Gets param value in config file or environment variables
-     * 
-     * @param paramname
-     *            Global parameter's name
-     * @return Value of paramname or null if paramname is not found neither in
-     *         config file nor in environment variables
+     * get
+     * <p>
+     * Get a parameter value from the loaded properties or environment variables.
+     *
+     * @param paramname Parameter key.
+     * @return Value or null if not found anywhere.
      */
     public static String get(String paramname) {
 
@@ -149,12 +193,13 @@
     }
 
     /**
-     * Gets param value from config file or environment variables
-     * 
-     * @param paramname
-     *            Global parameter's name
-     * @param defaultval
-     * @return Value of paramname or defaultval if paramname is not found
+     * get
+     * <p>
+     * Returns parameter value or default if missing.
+     *
+     * @param paramname Key.
+     * @param defaultval Default fallback.
+     * @return value or default.
      */
     public static String get(String paramname, String defaultval) {
         String value = get(paramname);
@@ -162,12 +207,12 @@
     }
 
     /**
-     * Gets param value in config file or environment variables
-     * 
-     * @param paramname
-     *            Global parameter's name
-     * @return Integer value of paramname or -1 if paramname is not found
-     *         neither in config file nor in environment variables
+     * getInt
+     * <p>
+     * Integer accessor, returns -1 if missing.
+     *
+     * @param paramname Key.
+     * @return Parsed integer or -1.
      */
     public static int getInt(String paramname) {
         String value = get(paramname);
@@ -175,19 +220,24 @@
     }
 
     /**
-     * Gets param value from config file or environment variables
-     * 
-     * @param paramname
-     *            Global parameter's name
-     * @param defaultval
-     * @return Integer value of paramname or defaultval if paramname is not
-     *         found
+     * getInt
+     * <p>
+     * Integer accessor, returns provided default when missing.
+     *
+     * @param paramname Key.
+     * @param defaultval Default fallback.
+     * @return Parsed integer or default.
      */
     public static int getInt(String paramname, int defaultval) {
         String value = get(paramname);
         return (value == null ? defaultval : Integer.parseInt(value));
     }
 
+    /**
+     * KEYS
+     * <p>
+     * Strongly-typed keys used across the application.
+     */
     public static class KEYS {
 
         public static final String SERVER_HOSTNAME = "license.server.hostname";
@@ -205,5 +255,5 @@
         public static final String EMAIL_FROM_ADDRESS = "email.from.address";
         public static final String EMAIL_LIC_DEFAULT_SUBJECT = "email.lic.default.subject";
     }
-
 }
+

--
Gitblit v1.3.2