Class ValueBuddy<V,B>

java.lang.Object
valorless.rarespawns.datamodels.ValueBuddy<V,B>
Type Parameters:
V - the primary value type
B - the companion value type associated with V

public class ValueBuddy<V,B> extends Object
Simple generic pair used to keep a primary value and a related companion value together.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Companion value linked to value.
    Primary value of the pair.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ValueBuddy(V value, B buddy)
    Creates a new value pair.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <V, B> ValueBuddy<V,B>
    of(V value, B buddy)
    Factory method; equivalent to new ValueBuddy<>(value, buddy).
    static <V, B> ValueBuddy<V,B>
    parse(String input)
    Parses a comma-separated string into a ValueBuddy<String, String>.

    Methods inherited from class java.lang.Object

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

    • value

      public V value
      Primary value of the pair.
    • buddy

      public B buddy
      Companion value linked to value.
  • Constructor Details

    • ValueBuddy

      public ValueBuddy(V value, B buddy)
      Creates a new value pair.
      Parameters:
      value - primary value
      buddy - companion value associated with value
  • Method Details

    • of

      public static <V, B> ValueBuddy<V,B> of(V value, B buddy)
      Factory method; equivalent to new ValueBuddy<>(value, buddy).
      Type Parameters:
      V - the primary value type
      B - the companion value type
      Parameters:
      value - primary value
      buddy - companion value associated with value
      Returns:
      a new ValueBuddy containing the given pair
    • parse

      public static <V, B> ValueBuddy<V,B> parse(String input)
      Parses a comma-separated string into a ValueBuddy<String, String>.

      The input must contain exactly one comma; the text before the comma becomes value and the text after becomes buddy. Both parts are trimmed of surrounding whitespace before being stored.

      Note: because the generic types are erased at runtime this method always returns ValueBuddy<String, String> regardless of the type parameters declared at the call-site. The @SuppressWarnings("unchecked") annotation is present because the raw String values are cast to V and B without a runtime check.

      Type Parameters:
      V - the primary value type (must be String at runtime)
      B - the companion value type (must be String at runtime)
      Parameters:
      input - a comma-separated string in the format "value, buddy"
      Returns:
      a new ValueBuddy from the parsed pair, or null if the input does not contain exactly one comma or an exception occurs