java.lang.Object
org.lfenergy.compas.sct.commons.util.Utils

public final class Utils extends Object
  • Method Details

    • entering

      public static String entering()
      Generic message
      Returns:
      >>> Entering: :: + methode name
    • leaving

      public static String leaving(Long startTime)
      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

      public static String leaving()
      Generic message for leaving a methode call
      Returns:
      >>> Entering: :: + methode name
    • equalsOrNotSet

      public 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.
      Parameters:
      o1 - object to compare
      o2 - object to compare
      isSet - predicate that returns if fields is set
      getValue - 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

      public static String xpathAttributeFilter(String name, String value)
      Builds string
      Parameters:
      name - name to display
      value - value to display
      Returns:
      not (name) or name=value
    • xpathAttributeFilter

      public static String xpathAttributeFilter(String name, Collection<String> value)
      Builds string
      Parameters:
      name - name to display
      value - values to display
      Returns:
      not (name) or name=values
    • equalsOrBothBlank

      public static boolean equalsOrBothBlank(String s1, String s2)
      Checks if strings are equals or both blank. Blank means : null, empty string or whitespaces (as defined by Character.isWhitespace(char)) only string.
      Parameters:
      s1 - first string
      s2 - seconde string
      Returns:
      true if strings are equals or both blank, false otherwise
      See Also:
      • StringUtils.isBlank(CharSequence)
    • blanksFirstComparator

      public static int blanksFirstComparator(String s1, String s2)
      Comparator for String Difference with CharSequence.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 by Character.isWhitespace(char)) only string. Note: this comparator imposes orderings that are inconsistent with equals.
      Parameters:
      s1 - first String to compare
      s2 - 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:
    • removeTrailingDigits

      public static String removeTrailingDigits(String s)
      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

      public static String extractField(String s, String regexDelimiter, int index)
      Split string s using regexDelimiter into an array, and return element at given index.
      Parameters:
      s - string to split
      regexDelimiter - delimiter
      index - 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

      public static boolean lnClassEquals(List<String> lnClass1, String lnClass2)
      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 list
      lnClass2 - 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

      public static PrimitiveIterator.OfLong sequence(long startInclusive, long endInclusive)
      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

      public static Iterator<String> macAddressSequence(String startInclusive, String endInclusive)
      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

      public 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(-). 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

      public static long macAddressToLong(String macAddress)
      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

      public static 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).
      Parameters:
      number - number to be converted in hexadecimal
      length - 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

      public static <T> T copySclElement(T object, Class<T> clazz)
      creates a copy of Scl element
      Type Parameters:
      T - type of the object
      Parameters:
      object - object to copy
      clazz - class type of the object
      Returns:
      copy of the object
    • isExtRefFeedBySameControlBlock

      public static boolean isExtRefFeedBySameControlBlock(TExtRef t1, TExtRef t2)
      Checks if two ExtRefs fed by same Control Block
      Parameters:
      t1 - extref to compare
      t2 - extref to compare
      Returns:
      true if the two ExtRef are fed by same Control Block, otherwise false
    • isIcdHeaderMatch

      public static boolean isIcdHeaderMatch(IEDAdapter iedAdapter, LDEPFSettingData setting)
      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.