Hyperic HQ Plugin API v. 4.4.0.2

org.hyperic.util.math
Class MathUtil

java.lang.Object
  extended by org.hyperic.util.math.MathUtil

public final class MathUtil
extends java.lang.Object

This class contains some mathematic utility methods.


Field Summary
static java.lang.Integer NEGATIVE_ONE
           
static java.lang.Integer ZERO
           
 
Constructor Summary
MathUtil()
           
 
Method Summary
static int clamp(int val, int min, int max)
          Clamp a value to a range.
static long clamp(long val, long min, long max)
           
static boolean compare(java.lang.Number n1, java.lang.Number n2)
          Like StringUtil.compare, but for numbers.
static int gcd(int n, int m)
          Find the greatest common divisor of both n and m.
static int lcm(int n, int m)
          Find the least common multiple of n and m.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEGATIVE_ONE

public static final java.lang.Integer NEGATIVE_ONE

ZERO

public static final java.lang.Integer ZERO
Constructor Detail

MathUtil

public MathUtil()
Method Detail

gcd

public static int gcd(int n,
                      int m)
Find the greatest common divisor of both n and m.

Parameters:
n - first number
m - second number
Returns:
the GCD of n and m, or 1 if both numbers are 0

lcm

public static int lcm(int n,
                      int m)
Find the least common multiple of n and m.

Parameters:
n - first number
m - second number
Returns:
the LCM of n and m

compare

public static boolean compare(java.lang.Number n1,
                              java.lang.Number n2)
Like StringUtil.compare, but for numbers.

See Also:
org.hyperic.util.StringUtil#compare

clamp

public static long clamp(long val,
                         long min,
                         long max)

clamp

public static int clamp(int val,
                        int min,
                        int max)
Clamp a value to a range. If the passed value is less than the minimum, return the minimum. If it is greater than the maximum, assign the maximum. else return the passed value.


Hyperic HQ Plugin API v. 4.4.0.2

Copyright © 2004-2006 Hyperic, Inc. support@hyperic.net, All Rights Reserved.