|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--xbn.XBNObject | +--xbn.util.UtilInt
Random functions to analyze and manipulate ints.
Source code: UtilInt.java. Unit tests: xbn_junit.util.JUTUtilInt.java.
Fields inherited from class xbn.XBNObject |
bFALSE_IN_PRODUCTION, bTRUE_IN_PRODUCTION, sCNSTR, sES, sLINE_SEP |
Constructor Summary | |
UtilInt()
Create a UtilInt. |
Method Summary | |
boolean |
areRangeBoundsValid(int i_min,
boolean b_nfrcMin,
int i_max,
boolean b_nfrcMax)
Are the bounds for this range valid? |
boolean |
areRangeBoundsValid(int i_min,
boolean b_nfrcMin,
int i_max,
boolean b_nfrcMax,
boolean b_actuallyCheck)
Are the bounds for this range valid? |
boolean |
areRangeBoundsValid(int i_min,
int i_max)
Are the bounds for this range valid? |
int |
getDigitLength(int i_number)
How many digits in length is the provided number? |
int |
getIdxNEToLmnt0(int[] a_int)
What is the first array index containing an int not equal to element zero? |
boolean |
isBetween(int i_number,
int i_min,
int i_max)
Is the number between min and max, but not equal to either bound?. |
boolean |
isBetweenInclusive(int i_number,
int i_min,
int i_max)
Is the number between min and max, or equal to one of the bounds?. |
boolean |
isGTOEMin(int i_number,
int i_min,
boolean b_nfrcMin)
Is the number greater than or equal to the minimum-possible value? |
boolean |
isInRange(int i_number,
int i_min,
boolean b_nfrcMin,
int i_max,
boolean b_nfrcMax)
Is the number in the range? |
boolean |
isInRange(int i_number,
int i_min,
boolean b_nfrcMin,
int i_max,
boolean b_nfrcMax,
boolean b_validateRange)
Is the number in the range? |
boolean |
isLTOEMax(int i_number,
int i_max,
boolean b_nfrcMax)
Is the number less than or equal to the maimum-possible value? |
Methods inherited from class xbn.XBNObject |
getXMsgPrefix, sop, sopl, sopl, throwAX, throwAXIfBadStr, throwAXIfNull, throwAXSpoof |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public UtilInt()
Create a UtilInt. This constructor does nothing.
Method Detail |
public final boolean isBetween(int i_number, int i_min, int i_max)
Is the number between min and max, but not equal to either bound?. If so, return true. Otherwise return false.
Equal to isInRange(i_number, (i_min + 1), true, (i_max - 1), true)
public final boolean isBetweenInclusive(int i_number, int i_min, int i_max)
Is the number between min and max, or equal to one of the bounds?. If so, return true. Otherwise return false.
Equal to isInRange(i_number, i_min, true, i_max, true)
public final boolean areRangeBoundsValid(int i_min, int i_max)
Are the bounds for this range valid?
Equal to areRangeBoundsValid(i_min, true, i_max, true, true)
public final boolean areRangeBoundsValid(int i_min, boolean b_nfrcMin, int i_max, boolean b_nfrcMax)
Are the bounds for this range valid?
Equal to areRangeBoundsValid(i_min, b_nfrcMin, i_max, b_nfrcMax, true)
public final boolean areRangeBoundsValid(int i_min, boolean b_nfrcMin, int i_max, boolean b_nfrcMax, boolean b_actuallyCheck)
Are the bounds for this range valid?
i_min
- The minimum bound of the range. Only used if b_nfrcMin is "true".b_nfrcMin
- If "true", then i_min is used. If "false", i_min is ignored.i_max
- The maximum bound of the range. Only used if b_nfrcMax is "true".b_nfrcMax
- If "true", then i_max is used. If "false", i_max is ignored.b_actuallyCheck
- If "true" then do check these bounds, and return true/false based on their validity. If "false", exit the function immediately (and return true). This is needed for external code that can guarantee that the bounds are valid, and don't want to redundantly check each time that isInRange is called.public final boolean isInRange(int i_number, int i_min, boolean b_nfrcMin, int i_max, boolean b_nfrcMax)
Is the number in the range?
Equal to isInRange(i_number, i_min, b_nfrcMin, i_max, b_nfrcMax, true)
public final boolean isInRange(int i_number, int i_min, boolean b_nfrcMin, int i_max, boolean b_nfrcMax, boolean b_validateRange)
Is the number in the range?
i_number
- The number to analyze.i_min
- The minimum bound of the range. If...b_nfrcMin
- If "true", then i_min is used. If "false", i_min is ignored.i_max
- The maximum bound of the range. If...b_nfrcMax
- If "true", then i_max is used. If "false", i_max is ignored.b_validateRange
- If "true" then validate the range (with areRangeBoundsValid) before analyzing i_number. If the bounds are bad, throw an AssertException. If "false", then it is expected that the range has been validated before this function is called. Use at your own risk, as unpredictable results may occur.(isGTOEMin(i_number, i_min, b_nfrcMin) && isLTOEMax(i_number, i_min, b_nfrcMin))
.public final boolean isGTOEMin(int i_number, int i_min, boolean b_nfrcMin)
Is the number greater than or equal to the minimum-possible value?
i_number
- The number to analyze.i_min
- If b_nfrcMin is "true", this may be any number. If b_nfrcMin is "false" this is ignored.public final boolean isLTOEMax(int i_number, int i_max, boolean b_nfrcMax)
Is the number less than or equal to the maimum-possible value?
i_number
- The number to analyze.i_max
- If b_nfrcMax is "true", this may be any number. If b_nfrcMax is "false" this is ignored.public int getDigitLength(int i_number)
How many digits in length is the provided number?
An alternative method for determining the number of digits is to convert the number to a string, and then get the string's length (although you need to anticipate the possible dash, with negative numbers):
((new Integer(i_number)).toString()).length()
This was an intriguing thing for me to figure out. The answer to "how many digits does my number contain" is "how many times can you divide ten into it?..plus one". Take a look at the code.
i_number
- The number you want to know the amount of digits in. Trailing zeros (zeros on the left side of the number) are ignored, however, the number zero is considered a one-digit number.public final int getIdxNEToLmnt0(int[] a_int)
What is the first array index containing an int not equal to element zero?
This is useful in unit tests that tests multiple versions of the same function, when you want to ensure that each returns the same value.
a_int
- The int array to analyze. May not be null or equal to zero elements in length.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1997-2003, Jeff Epstein, All Rights Reserved. See top of source code files for copyright notice.
http://sourceforge.net/projects/xbnjava