Class CompatUtil

java.lang.Object
io.github.douira.glsl_transformer.util.CompatUtil

public class CompatUtil extends Object
This class contains utility methods that allow maintaining Java 8 API compatability. (Even though the code is at Java 16 source compatability)
  • Constructor Details

    • CompatUtil

      public CompatUtil()
  • Method Details

    • repeat

      public static String repeat(String str, int n)
      Repeats the given string a number of times. From https://stackoverflow.com/a/1235213
      Parameters:
      str - The string to repeat
      n - The number of times to repeat the string
      Returns:
      The given string repeated n times
    • setOf

      @SafeVarargs public static <T> Set<T> setOf(T... items)
      Creates a HashSet that contains the given items. The heap pollution warning is suppressed as it is in Arrays.
      Type Parameters:
      T - The type of the items
      Parameters:
      items - The items to add to the set
      Returns:
      The set with the given items
    • setOf

      public static <T> Set<T> setOf(T item)
      Creates a HashSet that contains the given item.
      Type Parameters:
      T - The type of the item
      Parameters:
      item - The item to add to the set
      Returns:
      The set with the given item
    • setOf

      public static <T> Set<T> setOf(T itemA, T itemB)
      Creates a HashSet that contains the given items.
      Type Parameters:
      T - The type of the items
      Parameters:
      itemA - The first item to add to the set
      itemB - The second item to add to the set
      Returns:
      The set with the given items
    • listOf

      @SafeVarargs public static <T> List<T> listOf(T... items)
      Creates an ArrayList that contains the given items in the same order. This is likely cheaper for making a collection than using setOf(Object...).
      Type Parameters:
      T - The type of the items
      Parameters:
      items - The items to create the list out of
      Returns:
      The list with the given items
    • iterateStream

      public static <T> Stream<T> iterateStream(T seed, Predicate<? super T> hasNext, UnaryOperator<T> next)
      Returns a sequential ordered Stream produced by iterative application of the given next function to an initial element, conditioned on satisfying the given hasNext predicate. The stream terminates as soon as the hasNext predicate returns false.

      Stream.iterate should produce the same sequence of elements as produced by the corresponding for-loop:

      
           for (T index=seed; hasNext.test(index); index = next.apply(index)) {
               ...
           }
       

      The resulting sequence may be empty if the hasNext predicate does not hold on the seed value. Otherwise the first element will be the supplied seed value, the next element (if present) will be the result of applying the next function to the seed value, and so on iteratively until the hasNext predicate indicates that the stream should terminate.

      The action of applying the hasNext predicate to an element happens-before the action of applying the next function to that element. The action of applying the next function for one element happens-before the action of applying the hasNext predicate for subsequent elements. For any given element an action may be performed in whatever thread the library chooses.

      Type Parameters:
      T - the type of stream elements
      Parameters:
      seed - the initial element
      hasNext - a predicate to apply to elements to determine when the stream must terminate.
      next - a function to be applied to the previous element to produce a new element
      Returns:
      a new sequential Stream
      Implementation Note:
      The implementation was taken from the JDK 9 source code.