public class Misc
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static double |
defaultMaxRelativeDiffDouble
The default maximum
relative difference that two doubles can have in
order to be deemed nearly equal . |
static float |
defaultMaxRelativeDiffFloat
The default maximum
relative difference that two floats can have in
order to be deemed nearly equal . |
static int |
objectSize
Estimates object size in bytes
|
static int |
referenceSize
Estimates pointer size in bytes
|
Constructor and Description |
---|
Misc() |
Modifier and Type | Method and Description |
---|---|
static double |
absoluteDifference(double a,
double b)
The absolute difference between two doubles, i.e.
|
static float |
absoluteDifference(float a,
float b)
The absolute difference between two floats, i.e.
|
static boolean |
compare(byte[] raw1,
byte[] raw2,
java.util.Formatter f) |
static boolean |
compare(float[] raw1,
float[] raw2,
java.util.Formatter f) |
static boolean |
compare(int[] raw1,
int[] raw2,
java.util.Formatter f) |
static int |
compare(int x,
int y)
Deprecated.
use Integer.compare(x, y)
|
static int |
compare(long x,
long y)
Deprecated.
use Long.compare(x, y)
|
static java.util.List |
getList(java.lang.Iterable ii)
Deprecated.
use ImmutableList.copyOf(iterator) or Lists.newArrayList(iterator)
|
static int |
getSize(java.lang.Iterable ii)
Deprecated.
use Iterables.size(Iterable it)
|
static boolean |
nearlyEquals(double a,
double b)
AbsoluteDifference is less than
defaultMaxRelativeDiffDouble . |
static boolean |
nearlyEquals(double a,
double b,
double maxRelDiff)
RelativeDifference is less than maxRelDiff.
|
static boolean |
nearlyEquals(float a,
float b)
AbsoluteDifference is less than
defaultMaxRelativeDiffFloat . |
static boolean |
nearlyEquals(float a,
float b,
float maxRelDiff)
RelativeDifference is less than maxRelDiff.
|
static boolean |
nearlyEqualsAbs(double a,
double b,
double maxAbsDiff)
AbsoluteDifference is less than maxAbsDiff.
|
static boolean |
nearlyEqualsAbs(float a,
float b,
float maxAbsDiff)
AbsoluteDifference is less than maxAbsDiff.
|
static double |
relativeDifference(double a,
double b)
Same as
relativeDifference(float, float) , but for doubles. |
static float |
relativeDifference(float a,
float b)
Returns the relative difference between two numbers, i.e.
|
static java.lang.String |
showBits(byte[] bytes) |
static java.lang.String |
showBytes(byte[] buff)
Deprecated.
use Arrays.toString(arr)
|
static void |
showBytes(byte[] buff,
java.util.Formatter f)
Deprecated.
use Arrays.toString(arr)
|
static java.lang.String |
showInts(int[] inta)
Deprecated.
use Arrays.toString(arr)
|
static void |
showInts(int[] inta,
java.util.Formatter f)
Deprecated.
use Arrays.toString(arr)
|
static java.lang.String |
showInts(java.util.List<java.lang.Integer> intList)
Deprecated.
use List.toString()
|
static java.lang.String |
stackTraceToString(java.lang.StackTraceElement[] stackTrace)
Deprecated.
do not use
|
public static final int referenceSize
public static final int objectSize
public static final float defaultMaxRelativeDiffFloat
relative difference
that two floats can have in
order to be deemed nearly equal
.public static final double defaultMaxRelativeDiffDouble
relative difference
that two doubles can have in
order to be deemed nearly equal
.public static float absoluteDifference(float a, float b)
|a - b|
.public static double absoluteDifference(double a, double b)
|a - b|
.public static float relativeDifference(float a, float b)
|a - b| / max(|a|, |b|)
.
For cases where a == 0
, b == 0
, or a
and b
are extremely close, traditional
relative difference calculation breaks down. So, in those instances, we compute the difference relative to
Float.MIN_NORMAL
, i.e. |a - b| / Float.MIN_NORMAL
.
a
- first number.b
- second number.public static double relativeDifference(double a, double b)
relativeDifference(float, float)
, but for doubles.public static boolean nearlyEquals(float a, float b)
defaultMaxRelativeDiffFloat
.public static boolean nearlyEquals(float a, float b, float maxRelDiff)
public static boolean nearlyEquals(double a, double b)
defaultMaxRelativeDiffDouble
.public static boolean nearlyEquals(double a, double b, double maxRelDiff)
public static boolean nearlyEqualsAbs(float a, float b, float maxAbsDiff)
public static boolean nearlyEqualsAbs(double a, double b, double maxAbsDiff)
@Deprecated public static java.lang.String showInts(int[] inta)
public static java.lang.String showInts(java.util.List<java.lang.Integer> intList)
public static void showInts(int[] inta, java.util.Formatter f)
public static java.lang.String showBytes(byte[] buff)
public static void showBytes(byte[] buff, java.util.Formatter f)
public static java.lang.String showBits(byte[] bytes)
public static boolean compare(byte[] raw1, byte[] raw2, java.util.Formatter f)
public static boolean compare(float[] raw1, float[] raw2, java.util.Formatter f)
public static boolean compare(int[] raw1, int[] raw2, java.util.Formatter f)
@Deprecated public static int compare(int x, int y)
@Deprecated public static int compare(long x, long y)
@Deprecated public static java.lang.String stackTraceToString(java.lang.StackTraceElement[] stackTrace)
@Deprecated public static int getSize(java.lang.Iterable ii)
@Deprecated public static java.util.List getList(java.lang.Iterable ii)