Package games.stendhal.common
Class MathHelper
java.lang.Object
games.stendhal.common.MathHelper
Helper functions for various mathematical tasks.
-
Field Summary
Modifier and TypeFieldDescriptionstatic long
static long
static long
static long
static int
static int
static int
static int
static int
static int
static int
static int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic float
clamp(float value, float minValue, float maxValue)
Limit a float value to a specific range.static int
clamp(int value, int minValue, int maxValue)
Limit an integer value to a specific range.static double
parseDouble(String s)
Parses a double safely, returning 0 if nothing can be sanely parsed from it.static double
parseDoubleDefault(String s, double def)
Parses a double safely, returning a default if nothing can be sanely parsed from it.static int
parses an integer safely, returning 0 if nothing can be sanely parsed.static int
parseIntDefault(String s, int def)
parses an integer safely.static long
parses a long safely, returning 0 if nothing can be sanely parsed.static long
parseLongDefault(String s, long def)
parses a long safely.
-
Field Details
-
MILLISECONDS_IN_ONE_MINUTE
public static final long MILLISECONDS_IN_ONE_MINUTE- See Also:
- Constant Field Values
-
MILLISECONDS_IN_ONE_HOUR
public static final long MILLISECONDS_IN_ONE_HOUR- See Also:
- Constant Field Values
-
MILLISECONDS_IN_ONE_DAY
public static final long MILLISECONDS_IN_ONE_DAY- See Also:
- Constant Field Values
-
MILLISECONDS_IN_ONE_WEEK
public static final long MILLISECONDS_IN_ONE_WEEK- See Also:
- Constant Field Values
-
SECONDS_IN_ONE_MINUTE
public static final int SECONDS_IN_ONE_MINUTE- See Also:
- Constant Field Values
-
SECONDS_IN_ONE_HOUR
public static final int SECONDS_IN_ONE_HOUR- See Also:
- Constant Field Values
-
SECONDS_IN_ONE_DAY
public static final int SECONDS_IN_ONE_DAY- See Also:
- Constant Field Values
-
SECONDS_IN_ONE_WEEK
public static final int SECONDS_IN_ONE_WEEK- See Also:
- Constant Field Values
-
MINUTES_IN_ONE_HOUR
public static final int MINUTES_IN_ONE_HOUR- See Also:
- Constant Field Values
-
MINUTES_IN_ONE_DAY
public static final int MINUTES_IN_ONE_DAY- See Also:
- Constant Field Values
-
MINUTES_IN_ONE_WEEK
public static final int MINUTES_IN_ONE_WEEK- See Also:
- Constant Field Values
-
TURNS_IN_ONE_MINUTE
public static final int TURNS_IN_ONE_MINUTE- See Also:
- Constant Field Values
-
-
Constructor Details
-
MathHelper
public MathHelper()
-
-
Method Details
-
parseDoubleDefault
Parses a double safely, returning a default if nothing can be sanely parsed from it.- Parameters:
s
- the string to parsedef
- the default value- Returns:
- double corresponding to s, or def if s can not be parsed to a double
-
parseDouble
Parses a double safely, returning 0 if nothing can be sanely parsed from it.- Parameters:
s
- the string to parse- Returns:
- double corresponding to s, or 0 if s can not be parsed to a double
-
parseIntDefault
parses an integer safely. returning a default if nothing can be sanely parsed from it- Parameters:
s
- the string to parsedef
- the default to set- Returns:
- An integer
-
parseInt
parses an integer safely, returning 0 if nothing can be sanely parsed. from it- Parameters:
s
- to parse- Returns:
- An integer
-
parseLongDefault
parses a long safely. returning a default if nothing can be sanely parsed from it- Parameters:
s
- the string to parsedef
- the default to set- Returns:
- An integer
-
parseLong
parses a long safely, returning 0 if nothing can be sanely parsed. from it- Parameters:
s
- to parse- Returns:
- An integer
-
clamp
public static int clamp(int value, int minValue, int maxValue)Limit an integer value to a specific range.- Parameters:
value
- value to be limitedminValue
- minimum value. Should be <= maxValue.maxValue
- maximum value. Should be >= minValue.- Returns:
- if value is in range [minValue, maxValue], value is returned. Otherwise if value > maxValue, maxValue is returned, if value < minValue, minValue is returned.
-
clamp
public static float clamp(float value, float minValue, float maxValue)Limit a float value to a specific range.- Parameters:
value
- value to be limitedminValue
- minimum value. Should be <= maxValue.maxValue
- maximum value. Should be >= minValue.- Returns:
- if value is in range [minValue, maxValue], value is returned. Otherwise if value > maxValue, maxValue is returned, if value < minValue, minValue is returned.
-