Class Utils
java.lang.Object
org.lfenergy.compas.sct.commons.util.Utils
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
blanksFirstComparator
(String s1, String s2) Comparator for String Difference withCharSequence.compare(CharSequence, CharSequence)
is that blank strings are considered equals and inferior to any not blank String.static <T> T
copySclElement
(T object, Class<T> clazz) creates a copy of Scl elementstatic String
entering()
Generic messagestatic boolean
equalsOrBothBlank
(String s1, String s2) Checks if strings are equals or both blank.static <T,
R> boolean equalsOrNotSet
(T o1, T o2, Predicate<T> isSet, Function<T, R> getValue) Test if two fields with primitive values are equals or are both not set.static String
extractField
(String s, String regexDelimiter, int index) Split string s using regexDelimiter into an array, and return element at given index.static Optional<AbstractLNAdapter<?>>
getActiveLNodeSource
(LDeviceAdapter lDeviceAdapter, LDEPFSettingData setting) provides Active LN Object that satisfies the LDEPF settings attributes (lnClass, lnInst, prefix)static Optional<LDeviceAdapter>
getActiveSourceLDevice
(IEDAdapter iedAdapter, LDEPFSettingData setting) provides Active LDevice for LDEPF setting's inst attributestatic boolean
Checks if two ExtRefs fed by same Control Blockstatic boolean
isIcdHeaderMatch
(IEDAdapter iedAdapter, LDEPFSettingData setting) verify whether the IED satisfies the LDEPF settings for the private element `TCompasICDHeader`static boolean
isValidDataTypeTemplate
(AbstractLNAdapter<?> lnAdapter, LDEPFSettingData setting) verify whether the LN satisfies the LDEPF settings for Data Type Template elements.static String
leaving()
Generic message for leaving a methode callstatic String
Generic message for leaving a methode call, its calculates CPU time taken by methode executionstatic boolean
lnClassEquals
(List<String> lnClass1, String lnClass2) Check if lnClass as List os the same as lnClass as a String.static String
longToMacAddress
(long macAddress) Converts long representation of a MAC-Address, by converting it to hexadecimal and separating every 2 characters by a hyphen(-).macAddressSequence
(String startInclusive, String endInclusive) Create a new Iterator that provides all ordered MAC-Addresses value included in given range.static long
macAddressToLong
(String macAddress) Converts a MAC-Address to its long representation, by concatenating the digits and converting it from hexadecimal to long.static String
Remove all digits at the end of the string, if anystatic PrimitiveIterator.OfLong
sequence
(long startInclusive, long endInclusive) Create a new Iterator that provides all ordered long value in the given rangestatic String
toHex
(long number, int length) Convert number to hexadecimal, with uppercase letters (A to F) and a minimum length (using left padding with zero when necessary).static String
xpathAttributeFilter
(String name, String value) Builds stringstatic String
xpathAttributeFilter
(String name, Collection<String> value) Builds string
-
Method Details
-
entering
Generic message- Returns:
- >>> Entering: :: + methode name
-
leaving
Generic message for leaving a methode call, its calculates CPU time taken by methode execution- Parameters:
startTime
- methode call start time- Returns:
- message with methode name and duration
-
leaving
Generic message for leaving a methode call- Returns:
- >>> Entering: :: + methode name
-
equalsOrNotSet
Test if two fields with primitive values are equals or are both not set.- Parameters:
o1
- object to compareo2
- object to compareisSet
- predicate that returns if fields is setgetValue
- getter that return the unboxed field- Returns:
- true if both fields are set and are equals, or if both fields are not set. False otherwise.
-
xpathAttributeFilter
Builds string- Parameters:
name
- name to displayvalue
- value to display- Returns:
- not (name) or name=value
-
xpathAttributeFilter
Builds string- Parameters:
name
- name to displayvalue
- values to display- Returns:
- not (name) or name=values
-
equalsOrBothBlank
Checks if strings are equals or both blank. Blank means : null, empty string or whitespaces (as defined byCharacter.isWhitespace(char)
) only string.- Parameters:
s1
- first strings2
- seconde string- Returns:
- true if strings are equals or both blank, false otherwise
- See Also:
-
StringUtils.isBlank(CharSequence)
-
blanksFirstComparator
Comparator for String Difference withCharSequence.compare(CharSequence, CharSequence)
is that blank strings are considered equals and inferior to any not blank String. Blank means : null, empty string or whitespaces (as defined byCharacter.isWhitespace(char)
) only string. Note: this comparator imposes orderings that are inconsistent with equals.- Parameters:
s1
- first String to compares2
- second String to compare- Returns:
- when s1 and s2 are not blank, same result as
CharSequence.compare(CharSequence, CharSequence)
, zero when s1 and s2 are both blanks, negative integer when s1 is blank and s2 is not, positive integer when s1 is not blank but s2 is. - See Also:
-
Comparator.compare(Object, Object)
StringUtils.isBlank(CharSequence)
Comparator.nullsFirst(Comparator)
-
removeTrailingDigits
Remove all digits at the end of the string, if any- Parameters:
s
- input string- Returns:
- s without digits at the end. Guarantees that the last character of the return value is not a digit. If s is composed only of digits, the result is an empty string
- See Also:
-
extractField
Split string s using regexDelimiter into an array, and return element at given index.- Parameters:
s
- string to splitregexDelimiter
- delimiterindex
- index of the element in the split array (0 being the first element). If index is a negative integer, position is counted from the end (-1 behind the last element).- Returns:
- the element at position index in the split array, or null if index is out of bound
- See Also:
-
lnClassEquals
Check if lnClass as List os the same as lnClass as a String. For some reason, xjc plugin generates a List<String> instead of a String for the lnClass attribute. When marshalling an XML file, lnClass is represented as a List with a single element.- Parameters:
lnClass1
- lnClass attribute value represented as a listlnClass2
- lnClass attribute value represented as a String- Returns:
- true if lnClass2 is blank and lnClass1 is either null, empty or contains a blank String.
true if lnClass2 is not blank and lnClass1 contains lnClass2.
false otherwise.
Blank means : null, empty string or whitespaces (as defined by
Character.isWhitespace(char)
) only string. - Throws:
IllegalArgumentException
- when lnClass1 contains more than one element
-
sequence
Create a new Iterator that provides all ordered long value in the given range- Parameters:
startInclusive
- the first long in the range (inclusive)endInclusive
- the last long in the range (inclusive). Cannot exceed Long.MAX_VALUE - 1.- Returns:
- new Iterator. When endInclusive < startInclusive, return an empty iterator.
-
macAddressSequence
Create a new Iterator that provides all ordered MAC-Addresses value included in given range. See macAddressToLong for the format of MAC-Addresses range, and see longToMacAddress for the format of MAC-Addresses output- Parameters:
startInclusive
- the first MAC-Address in the range (inclusive)endInclusive
- the last MAC-Address in the range (inclusive)- Returns:
- new Iterator
- See Also:
-
longToMacAddress
Converts long representation of a MAC-Address, by converting it to hexadecimal and separating every 2 characters by a hyphen(-). See macAddressToLong for the reversing method.- Parameters:
macAddress
- a long between 0 and 0xFFFFFFFFFFFF- Returns:
- MAC address separated by hyphens(-). Letters are uppercase (A to F)
- See Also:
-
macAddressToLong
Converts a MAC-Address to its long representation, by concatenating the digits and converting it from hexadecimal to long. See longToMacAddress for the reversing method.- Parameters:
macAddress
- macAddress should be 6 groups of 2 hexadecimal digits (0 to 9 and A to F or a to f) separated by hyphens(–) or colons(:)- Returns:
- long between 0 and 0xFFFFFFFFFFFF representing this MAC-Address
- See Also:
-
toHex
Convert number to hexadecimal, with uppercase letters (A to F) and a minimum length (using left padding with zero when necessary).- Parameters:
number
- number to be converted in hexadecimallength
- minimum length of resulting string. When hexadecimal form of number does not reach length, left padding with "0" is done.- Returns:
- hexadecimal, with uppercase letters (A to F) and minimum length of length. Note that the length of return value can exceed "length" parameter when number hexadecimal form is longer than "length" parameter.
-
copySclElement
creates a copy of Scl element- Type Parameters:
T
- type of the object- Parameters:
object
- object to copyclazz
- class type of the object- Returns:
- copy of the object
-
isExtRefFeedBySameControlBlock
Checks if two ExtRefs fed by same Control Block- Parameters:
t1
- extref to comparet2
- extref to compare- Returns:
- true if the two ExtRef are fed by same Control Block, otherwise false
-
isIcdHeaderMatch
verify whether the IED satisfies the LDEPF settings for the private element `TCompasICDHeader` -
getActiveSourceLDevice
public static Optional<LDeviceAdapter> getActiveSourceLDevice(IEDAdapter iedAdapter, LDEPFSettingData setting) provides Active LDevice for LDEPF setting's inst attribute -
getActiveLNodeSource
public static Optional<AbstractLNAdapter<?>> getActiveLNodeSource(LDeviceAdapter lDeviceAdapter, LDEPFSettingData setting) provides Active LN Object that satisfies the LDEPF settings attributes (lnClass, lnInst, prefix) -
isValidDataTypeTemplate
public static boolean isValidDataTypeTemplate(AbstractLNAdapter<?> lnAdapter, LDEPFSettingData setting) verify whether the LN satisfies the LDEPF settings for Data Type Template elements.
-