Class Integers

java.lang.Object
com.pnfsoftware.jeb.util.primitives.Integers

public class Integers extends Object
Utility methods for ints
  • Constructor Details

    • Integers

      public Integers()
  • Method Details

    • toUnsignedString

      public static String toUnsignedString(int value)
      Convert an int to its unsigned decimal string representation.
      Parameters:
      value - int value
      Returns:
      the unsigned decimal representation of value
    • safeInt

      public static int safeInt(Integer v)
      Safe unbox an Integer to zero when null.
      Parameters:
      v - an Integer object
      Returns:
      the integer value, 0 if null
    • safeInt

      public static Integer safeInt(Integer v, int defaultValue)
      Safe unbox an Integer to defaultValue when null.
      Parameters:
      v - an Integer object
      defaultValue - default value if null
      Returns:
      the integer value, defaultValue if null
    • min

      public static Integer min(Collection<Integer> c)
      Retrieve the smallest integer in a collection.
      Parameters:
      c - collection to scan
      Returns:
      the smallest value, or null if the collection is empty
    • max

      public static Integer max(Collection<Integer> c)
      Retrieve the greatest integer in a collection.
      Parameters:
      c - collection to scan
      Returns:
      the greatest value, or null if the collection is empty
    • formatIntegerCollection

      public static String formatIntegerCollection(Collection<Integer> collection, Integer radix, String pfx, String sfx)
      Format a collection of ints.
      Parameters:
      collection - collection of ints
      radix - optional radix, default=10
      pfx - optional prefix, default=none
      sfx - optional suffix, default=none
      Returns:
      the formatted collection
    • formatHexIntegerCollection

      public static String formatHexIntegerCollection(Collection<Integer> list)
      Format a collection of ints.
      Parameters:
      list - collection of ints
      Returns:
      the formatted hexadecimal collection
    • formatIntegerCollection

      public static String formatIntegerCollection(Collection<Integer> collection, Integer radix, String pfx, String sfx, String separator)
      Format a collection of ints.
      Parameters:
      collection - collection of ints
      radix - optional, default=10
      pfx - optional, default=none
      sfx - optional, default=none
      separator - optional separator, default=", "
      Returns:
      the formatted collection
    • range

      public static Iterable<Integer> range(int start, int end, int step)
      Generate an iterable range of integers.
      Parameters:
      start - first value, inclusive
      end - exclusive
      step - increment (can be negative, cannot be zero)
      Returns:
      an iterable range
    • range

      public static Iterable<Integer> range(int start, int end)
      Generate an incremental range of integers.
      Parameters:
      start - first value, inclusive
      end - exclusive
      Returns:
      an iterable range
    • range

      public static Iterable<Integer> range(int cnt)
      Generate an incremental range of integers from 0 to the provided count.
      Parameters:
      cnt - exclusive upper bound
      Returns:
      an iterable range from 0 to cnt