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

public Class EvaluationConditionalFormatRule

extends Object
implements Comparable<EvaluationConditionalFormatRule>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Imports
java.text.DecimalFormat, .DecimalFormatSymbols, java.util.ArrayList, .Collections, .HashMap, .HashSet, .LinkedHashSet, .List, .Locale, .Map, .Objects, .Set, java.util.function.Function, org.apache.poi.ss.formula.eval.BlankEval, .BoolEval, .ErrorEval, .NumberEval, .RefEval, .StringEval, .ValueEval, org.apache.poi.ss.formula.functions.AggregateFunction, org.apache.poi.ss.usermodel.Cell, .CellType, .ConditionFilterData, .ConditionFilterType, .ConditionType, .ConditionalFormatting, .ConditionalFormattingRule, .ExcelNumberFormat, .Row, .Sheet, org.apache.poi.ss.util.CellRangeAddress, .CellReference, org.apache.poi.util.LocaleUtil, .StringUtil

Abstracted and cached version of a Conditional Format rule for use with a ConditionalFormattingEvaluator. This references a rule, its owning ConditionalFormatting, its priority order (lower index = higher priority in Excel), and the information needed to evaluate the rule for a given cell.

Having this all combined and cached avoids repeated access calls to the underlying structural objects, XSSF CT* objects and HSSF raw byte structures. Those objects can be referenced from here. This object will be out of sync if anything modifies the referenced structures' evaluation properties.

The assumption is that consuming applications will read the display properties once and create whatever style objects they need, caching those at the application level. Thus this class only caches values needed for evaluation, not display.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
EvaluationConditionalFormatRule.ValueAndFormat

Note

this class has a natural ordering that is inconsistent with equals.

Field Summary

Modifier and TypeField and Description
private final DecimalFormat
private final ConditionalFormatting
private final int
private final String
private final String
private final String
private final Map<CellRangeAddress, Set<EvaluationConditionalFormatRule.ValueAndFormat>>
meaningfulRegionValues

Depending on the rule type, it may want to know about certain values in the region when evaluating matches(CellReference), such as top 10, unique, duplicate, average, etc. This collection stores those if needed so they are not repeatedly calculated

private final ExcelNumberFormat
private final OperatorEnum
private final int
private final CellRangeAddress[]
private final ConditionalFormattingRule
private final int
private final Sheet
private final String
private CellRangeAddress
private final ConditionType
private final WorkbookEvaluator

Constructor Summary

AccessConstructor and Description
public
EvaluationConditionalFormatRule(WorkbookEvaluator workbookEvaluator, Sheet sheet, ConditionalFormatting formatting, int
for priority, zero based
formattingIndex
,
ConditionalFormattingRule rule, int
for priority, zero based, if this is an HSSF rule. Unused for XSSF rules
ruleIndex
,
CellRangeAddress[]
could be read from formatting, but every call creates new objects in a new array. this allows calling it once per formatting instance, and re-using the array.
regions
)

Method Summary

Modifier and TypeMethod and Description
private boolean
private boolean

Returns:

true/false using the same rules as Data Validation evaluations
checkFormula
(CellReference
needed for offsets from region anchor - may be null!
ref
,
CellRangeAddress
for adjusting relative formulas
region
)

private boolean

Returns:

if the value of the cell is valid or not for the formatting rule
checkValue
(Cell
the cell to check for
cell
,
CellRangeAddress
for adjusting relative formulas
region
)

public int

Returns:

comparison based on sheet name, formatting index, and rule priority
compareTo
(EvaluationConditionalFormatRule
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Per Excel Help, XSSF rule priority is sheet-wide, not just within the owning ConditionalFormatting object.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Defined as equal sheet name and formatting and rule indexes

private Set<EvaluationConditionalFormatRule.ValueAndFormat>
public Set<EvaluationConditionalFormatRule.ValueAndFormat>
private Set<EvaluationConditionalFormatRule.ValueAndFormat>
private Set<EvaluationConditionalFormatRule.ValueAndFormat>
private EvaluationConditionalFormatRule.ValueAndFormat
public ConditionalFormatting

Returns:

the formatting
getFormatting
()

public int

Returns:

conditional formatting index
getFormattingIndex
()

public String

Returns:

the formula1
getFormula1
()

public String

Returns:

the formula2
getFormula2
()

private Set<EvaluationConditionalFormatRule.ValueAndFormat>

Returns:

the meaningful values in the range of cells specified
getMeaningfulValues
(CellRangeAddress region, boolean withText, Function<List<EvaluationConditionalFormatRule.ValueAndFormat>, Set<EvaluationConditionalFormatRule.ValueAndFormat>>
instances evaluate the values for a region and return the positive matches for the function type.
func
)

from testing, Excel only operates on numbers and dates (which are stored as numbers) in the range.

public ExcelNumberFormat

Returns:

Excel number format string to apply to matching cells, or null to keep the cell default
getNumberFormat
()

public OperatorEnum

Returns:

the operator
getOperator
()

public int

Returns:

the priority
getPriority
()

public CellRangeAddress[]

Returns:

the regions
getRegions
()

public ConditionalFormattingRule

Returns:

the rule
getRule
()

public int

Returns:

rule index
getRuleIndex
()

public Sheet

Returns:

sheet
getSheet
()

public String

Returns:

condition text if any, or null
getText
()

public ConditionType

Returns:

the type
getType
()

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

pack-priv boolean

Returns:

true if this rule evaluates to true for the given cell
matches
(CellReference ref)

private ValueEval
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

decimalTextFormatback to summary
private final DecimalFormat decimalTextFormat
formattingback to summary
private final ConditionalFormatting formatting
formattingIndexback to summary
private final int formattingIndex
formula1back to summary
private final String formula1
formula2back to summary
private final String formula2
lowerTextback to summary
private final String lowerText
meaningfulRegionValuesback to summary
private final Map<CellRangeAddress, Set<EvaluationConditionalFormatRule.ValueAndFormat>> meaningfulRegionValues

Depending on the rule type, it may want to know about certain values in the region when evaluating matches(CellReference), such as top 10, unique, duplicate, average, etc. This collection stores those if needed so they are not repeatedly calculated

numberFormatback to summary
private final ExcelNumberFormat numberFormat
operatorback to summary
private final OperatorEnum operator
priorityback to summary
private final int priority
regionsback to summary
private final CellRangeAddress[] regions
ruleback to summary
private final ConditionalFormattingRule rule
ruleIndexback to summary
private final int ruleIndex
sheetback to summary
private final Sheet sheet
textback to summary
private final String text
topLeftRegionback to summary
private CellRangeAddress topLeftRegion
typeback to summary
private final ConditionType type
workbookEvaluatorback to summary
private final WorkbookEvaluator workbookEvaluator

Constructor Detail

EvaluationConditionalFormatRuleback to summary
public EvaluationConditionalFormatRule(WorkbookEvaluator workbookEvaluator, Sheet sheet, ConditionalFormatting formatting, int formattingIndex, ConditionalFormattingRule rule, int ruleIndex, CellRangeAddress[] regions)
Parameters
formattingIndex:int

for priority, zero based

ruleIndex:int

for priority, zero based, if this is an HSSF rule. Unused for XSSF rules

regions:CellRangeAddress[]

could be read from formatting, but every call creates new objects in a new array. this allows calling it once per formatting instance, and re-using the array.

Method Detail

checkFilterback to summary
private boolean checkFilter(Cell cell, CellReference ref, CellRangeAddress region)
checkFormulaback to summary
private boolean checkFormula(CellReference ref, CellRangeAddress region)
Parameters
ref:CellReference

needed for offsets from region anchor - may be null!

region:CellRangeAddress

for adjusting relative formulas

Returns:boolean

true/false using the same rules as Data Validation evaluations

checkValueback to summary
private boolean checkValue(Cell cell, CellRangeAddress region)
Parameters
cell:Cell

the cell to check for

region:CellRangeAddress

for adjusting relative formulas

Returns:boolean

if the value of the cell is valid or not for the formatting rule

compareToback to summary
public int compareTo(EvaluationConditionalFormatRule o)

Implements java.lang.Comparable.compareTo.

Per Excel Help, XSSF rule priority is sheet-wide, not just within the owning ConditionalFormatting object. This can be seen by creating 4 rules applying to two different ranges and examining the XML.

HSSF priority is based on definition/persistence order.

Parameters
o:EvaluationConditionalFormatRule

Doc from java.lang.Comparable.compareTo.

the object to be compared.

Returns:int

comparison based on sheet name, formatting index, and rule priority

Annotations
@Override
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Defined as equal sheet name and formatting and rule indexes

Parameters
obj:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
evaluateAboveAverageback to summary
private Set<EvaluationConditionalFormatRule.ValueAndFormat> evaluateAboveAverage(List<EvaluationConditionalFormatRule.ValueAndFormat> allValues)
evaluateDuplicateValuesback to summary
public Set<EvaluationConditionalFormatRule.ValueAndFormat> evaluateDuplicateValues(List<EvaluationConditionalFormatRule.ValueAndFormat> allValues)
evaluateTop10back to summary
private Set<EvaluationConditionalFormatRule.ValueAndFormat> evaluateTop10(List<EvaluationConditionalFormatRule.ValueAndFormat> allValues)
evaluateUniqueValuesback to summary
private Set<EvaluationConditionalFormatRule.ValueAndFormat> evaluateUniqueValues(List<EvaluationConditionalFormatRule.ValueAndFormat> allValues)
getCellValueback to summary
private EvaluationConditionalFormatRule.ValueAndFormat getCellValue(Cell cell)
getFormattingback to summary
public ConditionalFormatting getFormatting()
Returns:ConditionalFormatting

the formatting

getFormattingIndexback to summary
public int getFormattingIndex()
Returns:int

conditional formatting index

getFormula1back to summary
public String getFormula1()
Returns:String

the formula1

getFormula2back to summary
public String getFormula2()
Returns:String

the formula2

getMeaningfulValuesback to summary
private Set<EvaluationConditionalFormatRule.ValueAndFormat> getMeaningfulValues(CellRangeAddress region, boolean withText, Function<List<EvaluationConditionalFormatRule.ValueAndFormat>, Set<EvaluationConditionalFormatRule.ValueAndFormat>> func)

from testing, Excel only operates on numbers and dates (which are stored as numbers) in the range. numbers stored as text are ignored, but numbers formatted as text are treated as numbers.

Parameters
func:Function<List<EvaluationConditionalFormatRule.ValueAndFormat>, Set<EvaluationConditionalFormatRule.ValueAndFormat>>

instances evaluate the values for a region and return the positive matches for the function type.

Returns:Set<EvaluationConditionalFormatRule.ValueAndFormat>

the meaningful values in the range of cells specified

getNumberFormatback to summary
public ExcelNumberFormat getNumberFormat()
Returns:ExcelNumberFormat

Excel number format string to apply to matching cells, or null to keep the cell default

getOperatorback to summary
public OperatorEnum getOperator()
Returns:OperatorEnum

the operator

getPriorityback to summary
public int getPriority()
Returns:int

the priority

getRegionsback to summary
public CellRangeAddress[] getRegions()
Returns:CellRangeAddress[]

the regions

getRuleback to summary
public ConditionalFormattingRule getRule()
Returns:ConditionalFormattingRule

the rule

getRuleIndexback to summary
public int getRuleIndex()
Returns:int

rule index

getSheetback to summary
public Sheet getSheet()
Returns:Sheet

sheet

getTextback to summary
public String getText()
Returns:String

condition text if any, or null

getTypeback to summary
public ConditionType getType()
Returns:ConditionType

the type

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
matchesback to summary
pack-priv boolean matches(CellReference ref)
Returns:boolean

true if this rule evaluates to true for the given cell

unwrapEvalback to summary
private ValueEval unwrapEval(ValueEval eval)
org.apache.poi.ss.formula back to summary

protected Class EvaluationConditionalFormatRule.ValueAndFormat

extends Object
implements Comparable<EvaluationConditionalFormatRule.ValueAndFormat>
Class Inheritance
  • java.lang.Object
  • org.apache.poi.ss.formula.EvaluationConditionalFormatRule.ValueAndFormat
All Implemented Interfaces
java.lang.Comparable

Note

this class has a natural ordering that is inconsistent with equals.

Field Summary

Modifier and TypeField and Description
private final DecimalFormat
private final String
private final String
private final Double

Constructor Summary

AccessConstructor and Description
public
public
ValueAndFormat(String value, String format)

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

value comparison
compareTo
(EvaluationConditionalFormatRule.ValueAndFormat
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Note

this class has a natural ordering that is inconsistent with equals.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public String
public Double
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

decimalTextFormatback to summary
private final DecimalFormat decimalTextFormat
formatback to summary
private final String format
stringback to summary
private final String string
valueback to summary
private final Double value

Constructor Detail

ValueAndFormatback to summary
public ValueAndFormat(Double value, String format, DecimalFormat df)
ValueAndFormatback to summary
public ValueAndFormat(String value, String format)

Method Detail

compareToback to summary
public int compareTo(EvaluationConditionalFormatRule.ValueAndFormat o)

Implements java.lang.Comparable.compareTo.

Note

this class has a natural ordering that is inconsistent with equals.

Parameters
o:EvaluationConditionalFormatRule.ValueAndFormat

Doc from java.lang.Comparable.compareTo.

the object to be compared.

Returns:int

value comparison

Annotations
@Override
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getStringback to summary
public String getString()
getValueback to summary
public Double getValue()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isNumberback to summary
public boolean isNumber()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object