summaryrefslogtreecommitdiff
path: root/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java')
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java68
1 files changed, 37 insertions, 31 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java
index 929d2994..0c5eeb40 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java
@@ -28,8 +28,10 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
+
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,8 +51,7 @@ public class KeyValueUtils {
public static final String DEFAULT_VALUE = "default";
/**
- * Convert Java properties into a Map String/String.
- * <br>
+ * Convert Java properties into a Map String/String. <br>
* <b>Important:</b> The key/values from properties must be of type String!
*
* @param properties Java {@link Properties} that should be converted
@@ -72,7 +73,7 @@ public class KeyValueUtils {
/**
* Extract the first child of an input key after a the prefix.
*
- * @param key Full input key
+ * @param key Full input key
* @param prefix Prefix
* @return Child key {String} if it exists or null
*/
@@ -82,11 +83,11 @@ public class KeyValueUtils {
final int index = idAfterPrefix.indexOf(KEY_DELIMITER);
if (index > 0) {
final String adding = idAfterPrefix.substring(0, index);
- if (!(adding.isEmpty())) {
+ if (!adding.isEmpty()) {
return adding;
}
- } else if (!(idAfterPrefix.isEmpty())) {
+ } else if (!idAfterPrefix.isEmpty()) {
return idAfterPrefix;
}
@@ -98,9 +99,10 @@ public class KeyValueUtils {
/**
* Extract the prefix from an input key.
*
- * @param key Full input key
+ * @param key Full input key
* @param suffix Suffix of this key
- * @return Prefix {String} of the key or null if input key does not ends with postfix string
+ * @return Prefix {String} of the key or null if input key does not ends with
+ * postfix string
*/
public static String getPrefixFromKey(final String key, final String suffix) {
if (key != null && suffix != null && key.endsWith(suffix)) {
@@ -118,9 +120,10 @@ public class KeyValueUtils {
/**
* Remove a prefix string from a key.
*
- * @param key Full input key
+ * @param key Full input key
* @param prefix Prefix, which should be removed
- * @return The suffix of the input key or null if the input does not starts with the prefix
+ * @return The suffix of the input key or null if the input does not starts with
+ * the prefix
*/
public static String removePrefixFromKey(final String key, String prefix) {
if (prefix == null) {
@@ -145,9 +148,10 @@ public class KeyValueUtils {
/**
* Remove a prefix string from all keys in Map String/String of key/value pairs.
*
- * @param keys Input data of key/value pairs
+ * @param keys Input data of key/value pairs
* @param prefix Prefix which should be removed
- * @return Map String/String of key/value pairs without prefix in key, but never null
+ * @return Map String/String of key/value pairs without prefix in key, but never
+ * null
*/
public static Map<String, String> removePrefixFromKeys(final Map<String, String> keys,
final String prefix) {
@@ -165,26 +169,29 @@ public class KeyValueUtils {
}
/**
- * Get a subset of key/value pairs which starts with a prefix string The Prefix is removed from
- * the key.
+ * Get a subset of key/value pairs which starts with a prefix string The Prefix
+ * is removed from the key.
*
- * @param keys Input data of key/value pairs
+ * @param keys Input data of key/value pairs
* @param prefix Prefix string
- * @return Map String/String of key/value pairs without prefix in key, but never null
+ * @return Map String/String of key/value pairs without prefix in key, but never
+ * null
*/
public static Map<String, String> getSubSetWithPrefix(final Map<String, String> keys,
final String prefix) {
return removePrefixFromKeys(keys, prefix);
}
-
/**
- * Add a prefix to key/value pairs to make the key absolute according to key namespace convention.
+ * Add a prefix to key/value pairs to make the key absolute according to key
+ * namespace convention.
*
- * @param input Input key/value pairs which should be updated
- * @param prefix Key prefix, which should be added if the key is not absolute
+ * @param input Input key/value pairs which should be updated
+ * @param prefix Key prefix, which should be added if the key is not
+ * absolute
* @param absolutIdentifier Key identifier, which indicates an absolute key
- * @return Map String/String of key/value pairs in which all keys are absolute but never null
+ * @return Map String/String of key/value pairs in which all keys are absolute
+ * but never null
*/
public static Map<String, String> makeKeysAbsolut(final Map<String, String> input,
final String prefix, final String absolutIdentifier) {
@@ -225,7 +232,7 @@ public class KeyValueUtils {
/**
* Find the highest free list counter.
*
- * @param input Array of list keys
+ * @param input Array of list keys
* @param listPrefix {String} prefix of the list
* @return {int} highest free list counter
*/
@@ -247,7 +254,7 @@ public class KeyValueUtils {
/**
* Find the highest free list counter.
*
- * @param keySet Set of list keys
+ * @param keySet Set of list keys
* @param listPrefix {String} prefix of the list
* @return {int} highest free list counter
*/
@@ -261,13 +268,12 @@ public class KeyValueUtils {
return findNextFreeListCounter(array, listPrefix);
}
-
/**
* Normalize a CSV encoded list of value of an key/value pair.
*
* <p>
- * This method removes all whitespace at the begin or the end of CSV values and remove newLine
- * signs at the end of value. The ',' is used as list delimiter
+ * This method removes all whitespace at the begin or the end of CSV values and
+ * remove newLine signs at the end of value. The ',' is used as list delimiter
* </p>
*
* @param value CSV encoded input data
@@ -289,7 +295,6 @@ public class KeyValueUtils {
return normalizedCodes;
}
-
/**
* Check a String if it is a comma separated list of values.
*
@@ -298,7 +303,8 @@ public class KeyValueUtils {
* </p>
*
* @param value CSV encoded input data
- * @return true if the input data contains a ',' and has more then 1 list element, otherwise false
+ * @return true if the input data contains a ',' and has more then 1 list
+ * element, otherwise false
*/
public static boolean isCsvValueString(final String value) {
if (StringUtils.isNotEmpty(value)) {
@@ -316,8 +322,8 @@ public class KeyValueUtils {
/**
* Convert a CSV list to a List of CSV values. <br>
* <br>
- * This method removes all whitespace at the begin or the end of CSV values and remove newLine
- * signs at the end of value. The ',' is used as list delimiter
+ * This method removes all whitespace at the begin or the end of CSV values and
+ * remove newLine signs at the end of value. The ',' is used as list delimiter
*
* @param csv CSV encoded input data
* @return List of CSV normalized values, but never null
@@ -338,8 +344,8 @@ public class KeyValueUtils {
/**
* Convert a List of String elements to a Map of Key/Value pairs. <br>
- * Every List element used as a key/value pair and the '=' sign represents the delimiter between
- * key and value
+ * Every List element used as a key/value pair and the '=' sign represents the
+ * delimiter between key and value
*
* @param elements List of key/value elements
* @return Map of Key / Value pairs, but never null