Class Wildcard
public class Wildcard extends IntegerListGenerator
10**
is expanded into the set
{1000, 1001, 1010, 1011}
.- Author:
- Zachary Kurmas
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Wildcard.Pair<T,U>
A class to hold a pair of values. -
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_MAX_RETURN_SIZE
Limit on the size of the output. -
Constructor Summary
Constructors Constructor Description Wildcard()
-
Method Summary
Modifier and Type Method Description long[]
generateLongArray(long base, long wildcards, long notused)
Generate an array oflong
integers based on an integer with some of its bits designated as "wildcards".long[]
generateLongArray(java.lang.String str)
Generate an array oflong
integers based on an integer with some of its bits designated as "wildcards".int
getMaxReturnSize()
Returns the maximum size of the array that will be generated.long[]
getWildcardMasks(long wildcards)
Generates the set of masks specified bywildcards
.static java.lang.String
longPairToWildcardString(long base, long wildcards)
Generate aString
describing the set of integers to be generated bygenerateLongArray(String)
givenbase
andwildcards
.void
setMaxReturnSize(int new_mrs)
Sets a new upper bound for size of the array to be generated.static Wildcard.Pair<java.lang.Long,java.lang.Long>
wildcardStringToLongPair(java.lang.String str)
Convert aString
describing a set of integers (e.g., "0101X00XX01") into the pair oflong
s used bygenerateLongArray(long, long, long)
.Methods inherited from class edu.gvsu.kurmasz.warszawa.listgen.IntegerListGenerator
generateIntArray, generateIntList, generateLongList
-
Field Details
-
DEFAULT_MAX_RETURN_SIZE
public static final int DEFAULT_MAX_RETURN_SIZELimit on the size of the output. In the worst case, a wildcard mask of-1
will produce an array containing 232 elements. This is not illegal in Java; but, will almost certainly exhaust the computer's virtual memory. To prevent this, we set a default upper limit.- See Also:
- Constant Field Values
-
-
Constructor Details
-
Wildcard
public Wildcard()
-
-
Method Details
-
setMaxReturnSize
public void setMaxReturnSize(int new_mrs)Sets a new upper bound for size of the array to be generated.- Parameters:
new_mrs
- new maximum array size returned. Must be>= 1
.- Throws:
java.lang.IllegalArgumentException
- ifnew_mrs
≤0
.
-
getMaxReturnSize
public int getMaxReturnSize()Returns the maximum size of the array that will be generated.- Returns:
- the maximum size of the array that will be generated.
-
longPairToWildcardString
public static java.lang.String longPairToWildcardString(long base, long wildcards)Generate aString
describing the set of integers to be generated bygenerateLongArray(String)
givenbase
andwildcards
.- Parameters:
base
-wildcards
-- Returns:
- a
String
describing the set of integers to be generated bygenerateLongArray(String)
-
wildcardStringToLongPair
public static Wildcard.Pair<java.lang.Long,java.lang.Long> wildcardStringToLongPair(java.lang.String str)Convert aString
describing a set of integers (e.g., "0101X00XX01") into the pair oflong
s used bygenerateLongArray(long, long, long)
. Wildcards may be designated as "X", "x", "*", or "?". Leading and trailing whitespace will be ignored. Internal whitespace is an error.- Parameters:
str
- AString
describing a set of integers by marking certain bits as "wildcards" withX
s.- Returns:
- the pair of
long
s used bygenerateLongArray(long, long, long)
. - Throws:
java.lang.IllegalArgumentException
- ifstr
contains characters other than "0", "1", or valid wildcard characters.
-
generateLongArray
public long[] generateLongArray(long base, long wildcards, long notused)Generate an array oflong
integers based on an integer with some of its bits designated as "wildcards". For example, the binary value10**
is expanded into the set{1000, 1001, 1010, 1011}
(which is returned as the array{8, 9, 10, 11}
).Because the parameters to the generation methods are integers, and not
Strings
, we must use two parameters: One to specify the value of the "fixed" bits, and the other to specify the locations of the wildcards. In the example above, the first parameter would be8
(1000 in binary) and the second parameter would be3
(11 in binary). The second parameter tells us that the last two bits are wildcards. The first parameter tells us the values of those bits that are not wildcards (in this case that the second two bits are 10).Here are some example inputs and outputs:
-
generateLongArray(x, 0) = {x}
for allx
. (No bits are wildcards.) -
generateLongArray(0, 1) = {0, 1}
. The least significant bit is the only wildcard. -
generateLongArray(1, 1) = {0, 1}
. The least significant bit is the only wildcard. Notice that if a bit is specified as a wildcard, it doesn't matter what the corresponding bit in the "fixed" parameter is. -
generateLongArray(52, 1) = {52, 53}
. The least significant bit is the only wildcard. -
generateLongArray(53, 1) = {52, 53}
. The least significant bit is the only wildcard. -
generateLongArray(0, 3) = {0, 1, 2, 3}
. -
generateLongArray(4, 3), = {4, 5, 6 , 7}
. generateLongArray(9, 18) = {9, 11, 25, 27}
. (9 = 01001b
and18 = 10010b
. Together, they define the pattern "*10*1
". The pattern produces{01001, 01011, 11001,11011}
.)
If trying to figure out how to use
base
andwildcards
gives you a headache, check outwildcardStringToLongPair(String)
andlongPairToWildcardString(long, long)
.- Specified by:
generateLongArray
in classIntegerListGenerator
- Parameters:
base
- an integer specifying the bits that are considered "fixed".wildcards
- an integer whose "1" bits identify the location of the "wildcards".notused
- not used.- Returns:
- an array of
long
integers. - Throws:
java.lang.IllegalArgumentException
- ofwildcards
defines too many values.
-
-
generateLongArray
public long[] generateLongArray(java.lang.String str)Generate an array oflong
integers based on an integer with some of its bits designated as "wildcards". For example,"10**"
is expanded into the set{1000, 1001, 1010, 1011}
(which is returned as the array{8, 9, 10, 11}
).- Parameters:
str
- A description of the set of values to return- Returns:
- an array of
long
integers.
-
getWildcardMasks
public long[] getWildcardMasks(long wildcards)Generates the set of masks specified bywildcards
. In particular, each bit inwildcards
with a value of 1 is a wildcard. Thus ifwildcards
containsn
bits with a value of 1, it specifies a set of2^n
masks. For example the input 5 (binary101b
) specifies 4 masks:000
,001
,100
, and101
.- Parameters:
wildcards
- a long integer whose bits with value 1 specify the location of wildcards.- Returns:
- a set of masks that implement the wildcards.
- Throws:
java.lang.IllegalArgumentException
- ofwildcards
defines too many values.
-