Package valorless.rarespawns.datamodels
Class ValueBuddy<V,B>
java.lang.Object
valorless.rarespawns.datamodels.ValueBuddy<V,B>
- Type Parameters:
V- the primary value typeB- the companion value type associated withV
Simple generic pair used to keep a primary value and a related companion value together.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <V,B> ValueBuddy <V, B> of(V value, B buddy) Factory method; equivalent tonew ValueBuddy<>(value, buddy).static <V,B> ValueBuddy <V, B> Parses a comma-separated string into aValueBuddy<String, String>.
-
Field Details
-
value
Primary value of the pair. -
buddy
Companion value linked tovalue.
-
-
Constructor Details
-
ValueBuddy
Creates a new value pair.- Parameters:
value- primary valuebuddy- companion value associated withvalue
-
-
Method Details
-
of
Factory method; equivalent tonew ValueBuddy<>(value, buddy).- Type Parameters:
V- the primary value typeB- the companion value type- Parameters:
value- primary valuebuddy- companion value associated withvalue- Returns:
- a new
ValueBuddycontaining the given pair
-
parse
Parses a comma-separated string into aValueBuddy<String, String>.The input must contain exactly one comma; the text before the comma becomes
valueand the text after becomesbuddy. 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 rawStringvalues are cast toVandBwithout a runtime check.- Type Parameters:
V- the primary value type (must beStringat runtime)B- the companion value type (must beStringat runtime)- Parameters:
input- a comma-separated string in the format"value, buddy"- Returns:
- a new
ValueBuddyfrom the parsed pair, ornullif the input does not contain exactly one comma or an exception occurs
-