public abstract class DictionaryBinarySearch
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static int |
DIVERGENT_SEARCH_STEPS
The number of steps to take when performing the divergent search,
if you find that values which exist are still not being found, try
increasing the number of steps
|
Constructor and Description |
---|
DictionaryBinarySearch() |
Modifier and Type | Method and Description |
---|---|
private static int |
divergentSearch(java.lang.String value,
java.lang.String[] sortedData,
int idx,
java.text.Collator c)
Performs a divergent search which searches for the value in opposite
directions from the index given, the number of steps in each direction
to take is determined by the constant DIVERGENT_SEARCH_STEPS.
|
private static int |
divergentSearch(java.lang.String value,
java.lang.String[] sortedData,
int idx,
java.util.regex.Pattern p,
java.text.Collator c)
Performs a divergent search which searches for the value in opposite
directions from the index given, the number of steps in each direction
to take is determined by the constant DIVERGENT_SEARCH_STEPS.
|
private static int |
multiLangSearch(java.lang.String value,
java.lang.String[] sortedData,
java.text.Collator c) |
private static int |
multiLangSearch(java.lang.String value,
java.lang.String[] sortedData,
java.util.regex.Pattern p,
java.text.Collator c) |
static int |
search(java.lang.String value,
java.lang.String[] sortedData,
java.text.Collator c)
Searches for the value specified and returns the index where the first
instance of the value provided is found in the sorted array of data.
|
static int |
search(java.lang.String value,
java.lang.String[] sortedData,
java.util.regex.Pattern p,
java.text.Collator c)
Searches for the value specified and returns the index where the first
instance of the value provided is found in the sorted array of data.
|
private static final int DIVERGENT_SEARCH_STEPS
public static int search(java.lang.String value, java.lang.String[] sortedData, java.text.Collator c) throws java.lang.IllegalArgumentException
value
- The value to search for in the sorted data providedsortedData
- The sorted data to search throughc
- The comparator to use for performing comparisonsjava.lang.IllegalArgumentException
- If the data is not sorted or the value is null
TODO Add support to check if the data provided is not sorted and throw an exception
if it isn'tpublic static int search(java.lang.String value, java.lang.String[] sortedData, java.util.regex.Pattern p, java.text.Collator c) throws java.lang.IllegalArgumentException
value
- The value to search for in the sorted data providedsortedData
- The sorted data to search throughp
- The pattern to refine searching for the value within the datac
- The comparator to use for performing comparisonsjava.lang.IllegalArgumentException
- If the data is not sorted or the value is null
TODO Add support to check if the data provided is not sorted and throw an exception
if it isn'tprivate static int multiLangSearch(java.lang.String value, java.lang.String[] sortedData, java.text.Collator c)
value
- The value to search for in the sorted data providedsortedData
- The sorted data to search throughp
- The pattern to refine searching for the value within the datac
- The comparator to use for performing comparisonssearch(String, String[], Collator)
private static int multiLangSearch(java.lang.String value, java.lang.String[] sortedData, java.util.regex.Pattern p, java.text.Collator c)
value
- The value to search for in the sorted data providedsortedData
- The sorted data to search throughp
- The pattern to refine searching for the value within the datac
- The comparator to use for performing comparisonssearch(String, String[], Pattern, Collator)
private static int divergentSearch(java.lang.String value, java.lang.String[] sortedData, int idx, java.text.Collator c)
value
- The value to search for in the sorted data providedsortedData
- The sorted data to search throughidx
- The index to start the divergent search fromc
- The comparator to use for performing comparisonsprivate static int divergentSearch(java.lang.String value, java.lang.String[] sortedData, int idx, java.util.regex.Pattern p, java.text.Collator c)
value
- The value to search for in the sorted data providedsortedData
- The sorted data to search throughidx
- The index to start the divergent search fromp
- The pattern to refine searching for the value within the datac
- The comparator to use for performing comparisons