Class Helpers

java.lang.Object
org.cyclops.cyclopscore.helper.Helpers

public class Helpers extends Object
A collection of helper methods and fields.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    addAlphaToColor(int color, float alpha)
    Add the given alpha value to the given RGB color.
    static int
    addAlphaToColor(int color, int alpha)
    Add the given alpha value to the given RGB color.
    static int
    addSafe(int a, int b)
    Take the sum of these two values capped at Integer.MAX_VALUE.
    static int
    castSafe(long value)
    Cast a long value safely to an int.
    static org.apache.commons.lang3.tuple.Triple<Float,Float,Float>
    intToRGB(int color)
    Convert a color in integer representation to seperated r, g and b colors.
    static int
    multiplySafe(int a, int b)
    Take the multiplication of these two values capped at Integer.MAX_VALUE.
    static void
    Open the given URL in the player's browser.
    static int
    RGBAToInt(int r, int g, int b, int a)
    Convert r, g, b and a colors to an integer representation.
    static int
    rgbToBgr(int color)
    Convert the given color from RGB encoding to BGR encoding.
    static int
    rgbToBgra(int color, int alpha)
    Convert the given color from RGB encoding to BGR encoding.
    static int
    RGBToInt(int r, int g, int b)
    Convert r, g and b colors to an integer representation.
    static Object
    tryParse(String newValue, Object oldValue)
    Safe parsing of a string to it's real object type.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Helpers

      public Helpers()
  • Method Details

    • tryParse

      public static Object tryParse(String newValue, Object oldValue)
      Safe parsing of a string to it's real object type. The real object type is determined by checking the class of the oldValue.
      Parameters:
      newValue - The value to parse
      oldValue - The old value that has a certain type.
      Returns:
      The parsed newValue.
    • RGBToInt

      public static int RGBToInt(int r, int g, int b)
      Convert r, g and b colors to an integer representation.
      Parameters:
      r - red
      g - green
      b - blue
      Returns:
      integer representation of the color.
    • RGBAToInt

      public static int RGBAToInt(int r, int g, int b, int a)
      Convert r, g, b and a colors to an integer representation.
      Parameters:
      r - red
      g - green
      b - blue
      a - alpha
      Returns:
      integer representation of the color.
    • addAlphaToColor

      public static int addAlphaToColor(int color, int alpha)
      Add the given alpha value to the given RGB color.
      Parameters:
      color - The color.
      alpha - The alpha from 0-255
      Returns:
      The color with alpha.
    • addAlphaToColor

      public static int addAlphaToColor(int color, float alpha)
      Add the given alpha value to the given RGB color.
      Parameters:
      color - The color.
      alpha - The alpha from 0-1
      Returns:
      The color with alpha.
    • intToRGB

      public static org.apache.commons.lang3.tuple.Triple<Float,Float,Float> intToRGB(int color)
      Convert a color in integer representation to seperated r, g and b colors.
      Parameters:
      color - The color in integer representation.
      Returns:
      The separated r, g and b colors.
    • rgbToBgra

      public static int rgbToBgra(int color, int alpha)
      Convert the given color from RGB encoding to BGR encoding.
      Parameters:
      color - The color in RGB
      alpha - The alpha to apply
      Returns:
      The color in BGR
    • rgbToBgr

      public static int rgbToBgr(int color)
      Convert the given color from RGB encoding to BGR encoding.
      Parameters:
      color - The color in RGB
      Returns:
      The color in BGR
    • addSafe

      public static int addSafe(int a, int b)
      Take the sum of these two values capped at Integer.MAX_VALUE.
      Parameters:
      a - Integer
      b - Integer
      Returns:
      The safe sum.
    • multiplySafe

      public static int multiplySafe(int a, int b)
      Take the multiplication of these two values capped at Integer.MAX_VALUE.
      Parameters:
      a - Positive Integer
      b - Positive Integer
      Returns:
      The safe multiplication.
    • castSafe

      public static int castSafe(long value)
      Cast a long value safely to an int. If the casting would result in an overflow, return the Integer.MAX_VALUE.
      Parameters:
      value - A value to cast.
      Returns:
      The casted value.
    • openUrl

      public static void openUrl(String url)
      Open the given URL in the player's browser.
      Parameters:
      url - An URL.