Class JKCollectionUtil

java.lang.Object
com.jk.core.util.JKCollectionUtil

public class JKCollectionUtil extends Object
This class is a utility class used for working with collections and properties.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Details

    • JKCollectionUtil

      public JKCollectionUtil()
  • Method Details

    • fixPropertiesKeys

      public static void fixPropertiesKeys(Properties prop)
      This method fixes the keys of properties by converting them to lower-case and replacing underscores with hyphens.

      This method also fixes property values by replacing predefined variables with their corresponding values.

      Parameters:
      prop - Specifies the properties to be fixed.
    • fixPropertyValue

      public static String fixPropertyValue(String value)
      This method fixes a property value by replacing predefined variables with their corresponding values.
      Parameters:
      value - Specifies the value to be fixed.
      Returns:
      the fixed value.
    • fixPropertyKey

      public static String fixPropertyKey(String name)
      This method fixes a property key by converting it to lower-case and replacing underscores with hyphens.
      Parameters:
      name - Specifies the key to be fixed.
      Returns:
      the fixed key.
    • gatRandomItem

      public static Object gatRandomItem(List items)
      This method retrieves a random item from the provided list.
      Parameters:
      items - Specifies the list from which to retrieve an item.
      Returns:
      the random item from the list.
    • unifyReferences

      public static void unifyReferences(Hashtable hash, List list)
      This method unifies references within a list using a provided hash table.

      This method replaces references in the list with unified references from the hash table.

      Parameters:
      hash - Specifies the hash table containing unified references.
      list - Specifies the list in which to unify references.
    • unifyReferences

      public static Object unifyReferences(Hashtable hash, Object object)
      This method unifies a reference using a hash table.

      This method checks the provided hash table for a unified reference matching the given object's hash code.

      If a unified reference is found in the hash table, it returns that reference; otherwise, it adds the object to the hash table and returns the object itself.

      Parameters:
      hash - Specifies the hash table used to store unified references.
      object - Specifies the object to unify the reference for.
      Returns:
      the unified reference for the given object.
    • toString

      public static String toString(List<?> list)
      This method converts a List to its string representation.
      Parameters:
      list - Specifies the list to be converted to a string.
      Returns:
      the string representation of the list.
    • toString

      public static String toString(List<?> list, boolean includeBrackets)
      This method converts a List to its string representation with optional inclusion of brackets.
      Parameters:
      list - Specifies the list to be converted to a string.
      includeBrackets - Indicated whether to include brackets in the string representation.
      Returns:
      the string representation of the list.
    • toString

      public static String toString(Properties properties)
      This method converts a Properties object to its string representation.
      Parameters:
      properties - Specifies the Properties object to be converted to a string.
      Returns:
      the string representation of the Properties object.
    • sortHashTable

      public static List<Map.Entry> sortHashTable(Hashtable<?,?> hash, boolean asc)
      This method sorts the entries of a Hash table based on values and keys.
      Parameters:
      hash - Specifies the Hash table containing entries to be sorted.
      asc - Indicatees whether to sort in ascending order (true) or descending order (false).
      Returns:
      a List of Map.Entry objects sorted based on values and keys.
    • formatProperties

      public static String formatProperties(Properties properties)
      This method formats the properties into a human-readable format.
      Parameters:
      properties - Specifies the Properties object to be formatted.
      Returns:
      the formatted string representation of the properties.
    • toProperties

      public static Properties toProperties(String propString)
      This method converts a string representation of properties into a Properties object.
      Parameters:
      propString - Specifies the string representation of properties.
      Returns:
      the Properties object containing the properties from the input string.
    • getIndex

      public static int getIndex(Set<? extends Object> set, Object value)
      This method retrieves the index of a value in a Set.
      Parameters:
      set - Specifies the set to search in.
      value - Specifies the value to search for.
      Returns:
      the index of the value in the Set, or -1 if not found.
    • getByIndex

      public static <T> T getByIndex(Set<T> set, int index)
      This method retrieves the element in a Set at the specified index.
      Type Parameters:
      T - Specifies the type of elements in the Set.
      Parameters:
      set - Specifies the Set to retrieve the element from.
      index - Specifies the index of the element to retrieve.
      Returns:
      the element at the specified index, or null if index is out of bounds.
    • secureProperties

      public static Properties secureProperties(Properties prop)
      This method creates a new Properties object with sensitive information such as passwords replaced with asterisks.
      Parameters:
      prop - Specifies the Properties object containing sensitive information.
      Returns:
      a new Properties object with sensitive information replaced by asterisks.
    • toMap

      public static Map<String,String> toMap(String mapString)
      This method converts a string representation of a map into an actual Map object.
      Parameters:
      mapString - Specifies the string representation of the map.
      Returns:
      the map object created from the string representation.