Package com.jk.core.util
Class JKCollectionUtil
java.lang.Object
com.jk.core.util.JKCollectionUtil
This class is a utility class used for working with collections and
properties.
- Version:
- 1.0
- Author:
- Dr. Jalal H. Kiswani
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidfixPropertiesKeys(Properties prop) This method fixes the keys of properties by converting them to lower-case and replacing underscores with hyphens.static StringfixPropertyKey(String name) This method fixes a property key by converting it to lower-case and replacing underscores with hyphens.static StringfixPropertyValue(String value) This method fixes a property value by replacing predefined variables with their corresponding values.static StringformatProperties(Properties properties) This method formats the properties into a human-readable format.static ObjectgatRandomItem(List items) This method retrieves a random item from the provided list.static <T> TgetByIndex(Set<T> set, int index) This method retrieves the element in a Set at the specified index.static intThis method retrieves the index of a value in aSet.static PropertiessecureProperties(Properties prop) This method creates a new Properties object with sensitive information such as passwords replaced with asterisks.sortHashTable(Hashtable<?, ?> hash, boolean asc) This method sorts the entries of a Hash table based on values and keys.This method converts a string representation of a map into an actual Map object.static PropertiestoProperties(String propString) This method converts a string representation of properties into a Properties object.static StringThis method converts a List to its string representation.static StringThis method converts a List to its string representation with optional inclusion of brackets.static StringtoString(Properties properties) This method converts a Properties object to its string representation.static ObjectunifyReferences(Hashtable hash, Object object) This method unifies a reference using a hash table.static voidunifyReferences(Hashtable hash, List list) This method unifies references within a list using a provided hash table.
-
Constructor Details
-
JKCollectionUtil
public JKCollectionUtil()
-
-
Method Details
-
fixPropertiesKeys
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
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
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
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
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
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
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
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
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
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.Entryobjects sorted based on values and keys.
-
formatProperties
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
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
This method retrieves the index of a value in aSet.- 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-1if not found.
-
getByIndex
This method retrieves the element in a Set at the specified index.- Type Parameters:
T- Specifies the type of elements in theSet.- Parameters:
set- Specifies theSetto retrieve the element from.index- Specifies the index of the element to retrieve.- Returns:
- the element at the specified index, or
nullif index is out of bounds.
-
secureProperties
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
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.
-