Top Description Inners Fields Constructors Methods
org.apache.poi.ss.formula.functions

public final Class LookupUtils

extends Object
Class Inheritance
Annotations
@Internal
Imports
java.util.HashMap, .HashSet, .Iterator, .Map, .NoSuchElementException, java.util.regex.Matcher, .Pattern, org.apache.poi.ss.formula.TwoDEval, org.apache.poi.ss.formula.eval.BlankEval, .BoolEval, .ErrorEval, .EvaluationException, .MissingArgEval, .NumberEval, .NumericValueEval, .OperandResolver, .RefEval, .StringEval, .ValueEval, org.apache.poi.util.Internal

Common functionality used by VLOOKUP, HLOOKUP, LOOKUP and MATCH

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
LookupUtils.BinarySearchIndexes

Encapsulates some standard binary search functionality so the unusual Excel behaviour can be clearly distinguished.

private static class
private static class
public static class
LookupUtils.CompareResult

Enumeration to support 4 valued comparison results.

public static interface
private abstract static class
public static enum
private static class
private static class
public static enum
private static class
private static class
private static class
public static interface
LookupUtils.ValueVector

Represents a single row or column within an AreaEval.

Field Summary

Modifier and TypeField and Description
private static Map<Integer, LookupUtils.MatchMode>
private static Map<Integer, LookupUtils.SearchMode>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static int
public static LookupUtils.ValueVector
createColumnVector(TwoDEval tableArray, int relativeColumnIndex)

pack-priv static LookupUtils.LookupValueComparer
createLookupComparer(ValueEval lookupValue, boolean matchExact, boolean isMatchFunction)

public static LookupUtils.ValueVector
createRowVector(TwoDEval tableArray, int relativeRowIndex)

private static LookupUtils.LookupValueComparer
createTolerantLookupComparer(ValueEval lookupValue, boolean matchExact, boolean isMatchFunction)

public static LookupUtils.ValueVector

Returns:

null if the supplied area is neither a single row nor a single column
createVector
(TwoDEval ae)

public static LookupUtils.ValueVector
private static int
findLastIndexInRunOfEqualValues(LookupUtils.LookupValueComparer lookupComparer, LookupUtils.ValueVector vector, int firstFoundIndex, int maxIx)

Once the binary search has found a single match, (V/H)LOOKUP steps one by one over subsequent values to choose the last matching item.

private static int

Returns:

usually -1, signifying that the BinarySearchIndex has been narrowed to the new mid index. Zero or greater signifies that an exact match for the lookup value was found
handleMidValueTypeMismatch
(LookupUtils.LookupValueComparer lookupComparer, LookupUtils.ValueVector vector, LookupUtils.BinarySearchIndexes bsi, int
'mid' index (value which has the wrong type)
midIx
,
boolean
the data is sorted in reverse order
reverse
)

Excel seems to handle mismatched types initially by just stepping 'mid' ix forward to the first compatible value.

public static int
lookupFirstIndexOfValue(ValueEval lookupValue, LookupUtils.ValueVector vector, boolean isRangeLookup)

private static int

Returns:

zero based index into the vector, -1 if value cannot be found
lookupFirstIndexOfValue
(LookupUtils.LookupValueComparer
the value to be found in column or row vector
lookupComparer
,
LookupUtils.ValueVector
the values to be searched. For VLOOKUP this is the first column of the tableArray. For HLOOKUP this is the first row of the tableArray.
vector
,
LookupUtils.MatchMode matchMode)

Finds first (lowest index) matching occurrence of specified value.

private static int
private static int

Returns:

zero based index into the vector, -1 if value cannot be found
lookupLastIndexOfValue
(LookupUtils.LookupValueComparer
the value to be found in column or row vector
lookupComparer
,
LookupUtils.ValueVector
the values to be searched. For VLOOKUP this is the first column of the tableArray. For HLOOKUP this is the first row of the tableArray.
vector
,
LookupUtils.MatchMode matchMode)

Finds last (greatest index) matching occurrence of specified value.

public static LookupUtils.MatchMode
matchMode(int m)

private static int
performBinarySearch(LookupUtils.ValueVector vector, LookupUtils.LookupValueComparer lookupComparer)

Excel has funny behaviour when the some elements in the search vector are the wrong type.

public static boolean
resolveRangeLookupArg(ValueEval
must not be null
rangeLookupArg
,
int srcCellRow, int srcCellCol)

Resolves the last (optional) parameter (range_lookup) to the VLOOKUP and HLOOKUP functions.

public static int

Returns:

column or row index as a zero-based value, never negative.
resolveRowOrColIndexArg
(ValueEval rowColIndexArg, int srcCellRow, int srcCellCol)

Processes the third argument to VLOOKUP, or HLOOKUP (col_index_num or row_index_num respectively).

public static TwoDEval
resolveTableArrayArg(ValueEval eval)

The second argument (table_array) should be an area ref, but can actually be a cell ref, in which case it is interpreted as a 1x1 area ref.

public static LookupUtils.SearchMode
searchMode(int s)

public static int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait