mirror of https://github.com/apache/poi.git
findbugs fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1791679 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
253df55d8f
commit
2ae14e62db
|
@ -109,7 +109,10 @@ public class ConditionalFormattingEvaluator {
|
||||||
protected List<EvaluationConditionalFormatRule> getRules(Sheet sheet) {
|
protected List<EvaluationConditionalFormatRule> getRules(Sheet sheet) {
|
||||||
final String sheetName = sheet.getSheetName();
|
final String sheetName = sheet.getSheetName();
|
||||||
List<EvaluationConditionalFormatRule> rules = formats.get(sheetName);
|
List<EvaluationConditionalFormatRule> rules = formats.get(sheetName);
|
||||||
if (rules == null && ! formats.containsKey(sheetName)) {
|
if (rules == null) {
|
||||||
|
if (formats.containsKey(sheetName)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
final SheetConditionalFormatting scf = sheet.getSheetConditionalFormatting();
|
final SheetConditionalFormatting scf = sheet.getSheetConditionalFormatting();
|
||||||
final int count = scf.getNumConditionalFormattings();
|
final int count = scf.getNumConditionalFormattings();
|
||||||
rules = new ArrayList<EvaluationConditionalFormatRule>(count);
|
rules = new ArrayList<EvaluationConditionalFormatRule>(count);
|
||||||
|
@ -149,12 +152,17 @@ public class ConditionalFormattingEvaluator {
|
||||||
public List<EvaluationConditionalFormatRule> getConditionalFormattingForCell(final CellReference cellRef) {
|
public List<EvaluationConditionalFormatRule> getConditionalFormattingForCell(final CellReference cellRef) {
|
||||||
String sheetName = cellRef.getSheetName();
|
String sheetName = cellRef.getSheetName();
|
||||||
Sheet sheet = null;
|
Sheet sheet = null;
|
||||||
if (sheetName == null) sheet = workbook.getSheetAt(workbook.getActiveSheetIndex());
|
if (sheetName == null) {
|
||||||
else sheet = workbook.getSheet(sheetName);
|
sheet = workbook.getSheetAt(workbook.getActiveSheetIndex());
|
||||||
|
} else {
|
||||||
|
sheet = workbook.getSheet(sheetName);
|
||||||
|
}
|
||||||
|
|
||||||
final Cell cell = SheetUtil.getCell(sheet, cellRef.getRow(), cellRef.getCol());
|
final Cell cell = SheetUtil.getCell(sheet, cellRef.getRow(), cellRef.getCol());
|
||||||
|
|
||||||
if (cell == null) return Collections.emptyList();
|
if (cell == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
return getConditionalFormattingForCell(cell, cellRef);
|
return getConditionalFormattingForCell(cell, cellRef);
|
||||||
}
|
}
|
||||||
|
@ -202,7 +210,9 @@ public class ConditionalFormattingEvaluator {
|
||||||
boolean stopIfTrue = false;
|
boolean stopIfTrue = false;
|
||||||
for (EvaluationConditionalFormatRule rule : getRules(cell.getSheet())) {
|
for (EvaluationConditionalFormatRule rule : getRules(cell.getSheet())) {
|
||||||
|
|
||||||
if (stopIfTrue) continue; // a previous rule matched and wants no more evaluations
|
if (stopIfTrue) {
|
||||||
|
continue; // a previous rule matched and wants no more evaluations
|
||||||
|
}
|
||||||
|
|
||||||
if (rule.matches(cell)) {
|
if (rule.matches(cell)) {
|
||||||
rules.add(rule);
|
rules.add(rule);
|
||||||
|
@ -268,13 +278,19 @@ public class ConditionalFormattingEvaluator {
|
||||||
for (CellRangeAddress region : rule.getRegions()) {
|
for (CellRangeAddress region : rule.getRegions()) {
|
||||||
for (int r = region.getFirstRow(); r <= region.getLastRow(); r++) {
|
for (int r = region.getFirstRow(); r <= region.getLastRow(); r++) {
|
||||||
final Row row = sheet.getRow(r);
|
final Row row = sheet.getRow(r);
|
||||||
if (row == null) continue; // no cells to check
|
if (row == null) {
|
||||||
|
continue; // no cells to check
|
||||||
|
}
|
||||||
for (int c = region.getFirstColumn(); c <= region.getLastColumn(); c++) {
|
for (int c = region.getFirstColumn(); c <= region.getLastColumn(); c++) {
|
||||||
final Cell cell = row.getCell(c);
|
final Cell cell = row.getCell(c);
|
||||||
if (cell == null) continue;
|
if (cell == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
List<EvaluationConditionalFormatRule> cellRules = getConditionalFormattingForCell(cell);
|
List<EvaluationConditionalFormatRule> cellRules = getConditionalFormattingForCell(cell);
|
||||||
if (cellRules.contains(rule)) cells.add(cell);
|
if (cellRules.contains(rule)) {
|
||||||
|
cells.add(cell);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,9 +185,14 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
* Defined as equal sheet name and formatting and rule indexes
|
* Defined as equal sheet name and formatting and rule indexes
|
||||||
* @see java.lang.Object#equals(java.lang.Object)
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj == null) return false;
|
if (obj == null) {
|
||||||
if (! obj.getClass().equals(this.getClass())) return false;
|
return false;
|
||||||
|
}
|
||||||
|
if (! obj.getClass().equals(this.getClass())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
final EvaluationConditionalFormatRule r = (EvaluationConditionalFormatRule) obj;
|
final EvaluationConditionalFormatRule r = (EvaluationConditionalFormatRule) obj;
|
||||||
return getSheet().getSheetName().equalsIgnoreCase(r.getSheet().getSheetName())
|
return getSheet().getSheetName().equalsIgnoreCase(r.getSheet().getSheetName())
|
||||||
&& getFormattingIndex() == r.getFormattingIndex()
|
&& getFormattingIndex() == r.getFormattingIndex()
|
||||||
|
@ -203,21 +208,29 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
* @param o
|
* @param o
|
||||||
* @return comparison based on sheet name, formatting index, and rule priority
|
* @return comparison based on sheet name, formatting index, and rule priority
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int compareTo(EvaluationConditionalFormatRule o) {
|
public int compareTo(EvaluationConditionalFormatRule o) {
|
||||||
int cmp = getSheet().getSheetName().compareToIgnoreCase(o.getSheet().getSheetName());
|
int cmp = getSheet().getSheetName().compareToIgnoreCase(o.getSheet().getSheetName());
|
||||||
if (cmp != 0) return cmp;
|
if (cmp != 0) {
|
||||||
|
return cmp;
|
||||||
|
}
|
||||||
|
|
||||||
final int x = getPriority();
|
final int x = getPriority();
|
||||||
final int y = o.getPriority();
|
final int y = o.getPriority();
|
||||||
// logic from Integer.compare()
|
// logic from Integer.compare()
|
||||||
cmp = (x < y) ? -1 : ((x == y) ? 0 : 1);
|
cmp = (x < y) ? -1 : ((x == y) ? 0 : 1);
|
||||||
if (cmp != 0) return cmp;
|
if (cmp != 0) {
|
||||||
|
return cmp;
|
||||||
|
}
|
||||||
|
|
||||||
cmp = new Integer(getFormattingIndex()).compareTo(new Integer(o.getFormattingIndex()));
|
cmp = new Integer(getFormattingIndex()).compareTo(new Integer(o.getFormattingIndex()));
|
||||||
if (cmp != 0) return cmp;
|
if (cmp != 0) {
|
||||||
|
return cmp;
|
||||||
|
}
|
||||||
return new Integer(getRuleIndex()).compareTo(new Integer(o.getRuleIndex()));
|
return new Integer(getRuleIndex()).compareTo(new Integer(o.getRuleIndex()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hash = sheet.getSheetName().hashCode();
|
int hash = sheet.getSheetName().hashCode();
|
||||||
hash = 31 * hash + formattingIndex;
|
hash = 31 * hash + formattingIndex;
|
||||||
|
@ -239,7 +252,10 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (region == null) return false; // cell not in range of this rule
|
if (region == null) {
|
||||||
|
// cell not in range of this rule
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
final ConditionType ruleType = getRule().getConditionType();
|
final ConditionType ruleType = getRule().getConditionType();
|
||||||
|
|
||||||
|
@ -276,7 +292,9 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
|| (DataValidationEvaluator.isType(cell,CellType.STRING)
|
|| (DataValidationEvaluator.isType(cell,CellType.STRING)
|
||||||
&& (cell.getStringCellValue() == null || cell.getStringCellValue().isEmpty())
|
&& (cell.getStringCellValue() == null || cell.getStringCellValue().isEmpty())
|
||||||
)
|
)
|
||||||
) return false;
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ValueEval eval = unwrapEval(workbookEvaluator.evaluate(rule.getFormula1(), ConditionalFormattingEvaluator.getRef(cell), region));
|
ValueEval eval = unwrapEval(workbookEvaluator.evaluate(rule.getFormula1(), ConditionalFormattingEvaluator.getRef(cell), region));
|
||||||
|
|
||||||
|
@ -328,8 +346,12 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
ValueEval comp = unwrapEval(workbookEvaluator.evaluate(rule.getFormula1(), ConditionalFormattingEvaluator.getRef(cell), region));
|
ValueEval comp = unwrapEval(workbookEvaluator.evaluate(rule.getFormula1(), ConditionalFormattingEvaluator.getRef(cell), region));
|
||||||
|
|
||||||
// Copied for now from DataValidationEvaluator.ValidationEnum.FORMULA#isValidValue()
|
// Copied for now from DataValidationEvaluator.ValidationEnum.FORMULA#isValidValue()
|
||||||
if (comp instanceof BlankEval) return true;
|
if (comp instanceof BlankEval) {
|
||||||
if (comp instanceof ErrorEval) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (comp instanceof ErrorEval) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (comp instanceof BoolEval) {
|
if (comp instanceof BoolEval) {
|
||||||
return ((BoolEval) comp).getBooleanValue();
|
return ((BoolEval) comp).getBooleanValue();
|
||||||
}
|
}
|
||||||
|
@ -343,7 +365,9 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
|
|
||||||
private boolean checkFilter(Cell cell, CellRangeAddress region) {
|
private boolean checkFilter(Cell cell, CellRangeAddress region) {
|
||||||
final ConditionFilterType filterType = rule.getConditionFilterType();
|
final ConditionFilterType filterType = rule.getConditionFilterType();
|
||||||
if (filterType == null) return false;
|
if (filterType == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: this could/should be delegated to the Enum type, but that's in the usermodel package,
|
// TODO: this could/should be delegated to the Enum type, but that's in the usermodel package,
|
||||||
// we may not want evaluation code there. Of course, maybe the enum should go here in formula,
|
// we may not want evaluation code there. Of course, maybe the enum should go here in formula,
|
||||||
|
@ -357,19 +381,29 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
// numbers stored as text are ignored, but numbers formatted as text are treated as numbers.
|
// numbers stored as text are ignored, but numbers formatted as text are treated as numbers.
|
||||||
|
|
||||||
final ValueAndFormat cv10 = getCellValue(cell);
|
final ValueAndFormat cv10 = getCellValue(cell);
|
||||||
if (! cv10.isNumber()) return false;
|
if (! cv10.isNumber()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return getMeaningfulValues(region, false, new ValueFunction() {
|
return getMeaningfulValues(region, false, new ValueFunction() {
|
||||||
|
@Override
|
||||||
public Set<ValueAndFormat> evaluate(List<ValueAndFormat> allValues) {
|
public Set<ValueAndFormat> evaluate(List<ValueAndFormat> allValues) {
|
||||||
List<ValueAndFormat> values = allValues;
|
List<ValueAndFormat> values = allValues;
|
||||||
final ConditionFilterData conf = rule.getFilterConfiguration();
|
final ConditionFilterData conf = rule.getFilterConfiguration();
|
||||||
|
|
||||||
if (! conf.getBottom()) Collections.sort(values, Collections.reverseOrder());
|
if (! conf.getBottom()) {
|
||||||
else Collections.sort(values);
|
Collections.sort(values, Collections.reverseOrder());
|
||||||
|
} else {
|
||||||
|
Collections.sort(values);
|
||||||
|
}
|
||||||
|
|
||||||
int limit = (int) conf.getRank();
|
int limit = (int) conf.getRank();
|
||||||
if (conf.getPercent()) limit = allValues.size() * limit / 100;
|
if (conf.getPercent()) {
|
||||||
if (allValues.size() <= limit) return new HashSet<ValueAndFormat>(allValues);
|
limit = allValues.size() * limit / 100;
|
||||||
|
}
|
||||||
|
if (allValues.size() <= limit) {
|
||||||
|
return new HashSet<ValueAndFormat>(allValues);
|
||||||
|
}
|
||||||
|
|
||||||
return new HashSet<ValueAndFormat>(allValues.subList(0, limit));
|
return new HashSet<ValueAndFormat>(allValues.subList(0, limit));
|
||||||
}
|
}
|
||||||
|
@ -378,6 +412,7 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
// Per Excel help, "duplicate" means matching value AND format
|
// Per Excel help, "duplicate" means matching value AND format
|
||||||
// https://support.office.com/en-us/article/Filter-for-unique-values-or-remove-duplicate-values-ccf664b0-81d6-449b-bbe1-8daaec1e83c2
|
// https://support.office.com/en-us/article/Filter-for-unique-values-or-remove-duplicate-values-ccf664b0-81d6-449b-bbe1-8daaec1e83c2
|
||||||
return getMeaningfulValues(region, true, new ValueFunction() {
|
return getMeaningfulValues(region, true, new ValueFunction() {
|
||||||
|
@Override
|
||||||
public Set<ValueAndFormat> evaluate(List<ValueAndFormat> allValues) {
|
public Set<ValueAndFormat> evaluate(List<ValueAndFormat> allValues) {
|
||||||
List<ValueAndFormat> values = allValues;
|
List<ValueAndFormat> values = allValues;
|
||||||
Collections.sort(values);
|
Collections.sort(values);
|
||||||
|
@ -402,6 +437,7 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
// Per Excel help, "duplicate" means matching value AND format
|
// Per Excel help, "duplicate" means matching value AND format
|
||||||
// https://support.office.com/en-us/article/Filter-for-unique-values-or-remove-duplicate-values-ccf664b0-81d6-449b-bbe1-8daaec1e83c2
|
// https://support.office.com/en-us/article/Filter-for-unique-values-or-remove-duplicate-values-ccf664b0-81d6-449b-bbe1-8daaec1e83c2
|
||||||
return getMeaningfulValues(region, true, new ValueFunction() {
|
return getMeaningfulValues(region, true, new ValueFunction() {
|
||||||
|
@Override
|
||||||
public Set<ValueAndFormat> evaluate(List<ValueAndFormat> allValues) {
|
public Set<ValueAndFormat> evaluate(List<ValueAndFormat> allValues) {
|
||||||
List<ValueAndFormat> values = allValues;
|
List<ValueAndFormat> values = allValues;
|
||||||
Collections.sort(values);
|
Collections.sort(values);
|
||||||
|
@ -428,6 +464,7 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
|
|
||||||
// actually ordered, so iteration order is predictable
|
// actually ordered, so iteration order is predictable
|
||||||
List<ValueAndFormat> values = new ArrayList<ValueAndFormat>(getMeaningfulValues(region, false, new ValueFunction() {
|
List<ValueAndFormat> values = new ArrayList<ValueAndFormat>(getMeaningfulValues(region, false, new ValueFunction() {
|
||||||
|
@Override
|
||||||
public Set<ValueAndFormat> evaluate(List<ValueAndFormat> allValues) {
|
public Set<ValueAndFormat> evaluate(List<ValueAndFormat> allValues) {
|
||||||
List<ValueAndFormat> values = allValues;
|
List<ValueAndFormat> values = allValues;
|
||||||
double total = 0;
|
double total = 0;
|
||||||
|
@ -449,7 +486,9 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
|
|
||||||
final ValueAndFormat cv = getCellValue(cell);
|
final ValueAndFormat cv = getCellValue(cell);
|
||||||
Double val = cv.isNumber() ? cv.getValue() : null;
|
Double val = cv.isNumber() ? cv.getValue() : null;
|
||||||
if (val == null) return false;
|
if (val == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
double avg = values.get(0).value.doubleValue();
|
double avg = values.get(0).value.doubleValue();
|
||||||
double stdDev = values.get(1).value.doubleValue();
|
double stdDev = values.get(1).value.doubleValue();
|
||||||
|
@ -464,11 +503,17 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
|
|
||||||
OperatorEnum op = null;
|
OperatorEnum op = null;
|
||||||
if (conf.getAboveAverage()) {
|
if (conf.getAboveAverage()) {
|
||||||
if (conf.getEqualAverage()) op = OperatorEnum.GREATER_OR_EQUAL;
|
if (conf.getEqualAverage()) {
|
||||||
else op = OperatorEnum.GREATER_THAN;
|
op = OperatorEnum.GREATER_OR_EQUAL;
|
||||||
|
} else {
|
||||||
|
op = OperatorEnum.GREATER_THAN;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (conf.getEqualAverage()) op = OperatorEnum.LESS_OR_EQUAL;
|
if (conf.getEqualAverage()) {
|
||||||
else op = OperatorEnum.LESS_THAN;
|
op = OperatorEnum.LESS_OR_EQUAL;
|
||||||
|
} else {
|
||||||
|
op = OperatorEnum.LESS_THAN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return op != null && op.isValid(val, comp, null);
|
return op != null && op.isValid(val, comp, null);
|
||||||
case CONTAINS_TEXT:
|
case CONTAINS_TEXT:
|
||||||
|
@ -522,17 +567,23 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
*/
|
*/
|
||||||
private Set<ValueAndFormat> getMeaningfulValues(CellRangeAddress region, boolean withText, ValueFunction func) {
|
private Set<ValueAndFormat> getMeaningfulValues(CellRangeAddress region, boolean withText, ValueFunction func) {
|
||||||
Set<ValueAndFormat> values = meaningfulRegionValues.get(region);
|
Set<ValueAndFormat> values = meaningfulRegionValues.get(region);
|
||||||
if (values != null) return values;
|
if (values != null) {
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
List<ValueAndFormat> allValues = new ArrayList<ValueAndFormat>((region.getLastColumn() - region.getFirstColumn()+1) * (region.getLastRow() - region.getFirstRow() + 1));
|
List<ValueAndFormat> allValues = new ArrayList<ValueAndFormat>((region.getLastColumn() - region.getFirstColumn()+1) * (region.getLastRow() - region.getFirstRow() + 1));
|
||||||
|
|
||||||
for (int r=region.getFirstRow(); r <= region.getLastRow(); r++) {
|
for (int r=region.getFirstRow(); r <= region.getLastRow(); r++) {
|
||||||
final Row row = sheet.getRow(r);
|
final Row row = sheet.getRow(r);
|
||||||
if (row == null) continue;
|
if (row == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (int c = region.getFirstColumn(); c <= region.getLastColumn(); c++) {
|
for (int c = region.getFirstColumn(); c <= region.getLastColumn(); c++) {
|
||||||
Cell cell = row.getCell(c);
|
Cell cell = row.getCell(c);
|
||||||
final ValueAndFormat cv = getCellValue(cell);
|
final ValueAndFormat cv = getCellValue(cell);
|
||||||
if (cv != null && (withText || cv.isNumber()) ) allValues.add(cv);
|
if (cv != null && (withText || cv.isNumber()) ) {
|
||||||
|
allValues.add(cv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -578,21 +629,25 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
public static enum OperatorEnum {
|
public static enum OperatorEnum {
|
||||||
NO_COMPARISON {
|
NO_COMPARISON {
|
||||||
/** always false/invalid */
|
/** always false/invalid */
|
||||||
|
@Override
|
||||||
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
BETWEEN {
|
BETWEEN {
|
||||||
|
@Override
|
||||||
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
||||||
return cellValue.compareTo(v1) >= 0 && cellValue.compareTo(v2) <= 0;
|
return cellValue.compareTo(v1) >= 0 && cellValue.compareTo(v2) <= 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NOT_BETWEEN {
|
NOT_BETWEEN {
|
||||||
|
@Override
|
||||||
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
||||||
return cellValue.compareTo(v1) < 0 || cellValue.compareTo(v2) > 0;
|
return cellValue.compareTo(v1) < 0 || cellValue.compareTo(v2) > 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
EQUAL {
|
EQUAL {
|
||||||
|
@Override
|
||||||
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
||||||
// need to avoid instanceof, to work around a 1.6 compiler bug
|
// need to avoid instanceof, to work around a 1.6 compiler bug
|
||||||
if (cellValue.getClass() == String.class) {
|
if (cellValue.getClass() == String.class) {
|
||||||
|
@ -602,6 +657,7 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NOT_EQUAL {
|
NOT_EQUAL {
|
||||||
|
@Override
|
||||||
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
||||||
// need to avoid instanceof, to work around a 1.6 compiler bug
|
// need to avoid instanceof, to work around a 1.6 compiler bug
|
||||||
if (cellValue.getClass() == String.class) {
|
if (cellValue.getClass() == String.class) {
|
||||||
|
@ -611,21 +667,25 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GREATER_THAN {
|
GREATER_THAN {
|
||||||
|
@Override
|
||||||
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
||||||
return cellValue.compareTo(v1) > 0;
|
return cellValue.compareTo(v1) > 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
LESS_THAN {
|
LESS_THAN {
|
||||||
|
@Override
|
||||||
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
||||||
return cellValue.compareTo(v1) < 0;
|
return cellValue.compareTo(v1) < 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GREATER_OR_EQUAL {
|
GREATER_OR_EQUAL {
|
||||||
|
@Override
|
||||||
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
||||||
return cellValue.compareTo(v1) >= 0;
|
return cellValue.compareTo(v1) >= 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
LESS_OR_EQUAL {
|
LESS_OR_EQUAL {
|
||||||
|
@Override
|
||||||
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
public <C extends Comparable<C>> boolean isValid(C cellValue, C v1, C v2) {
|
||||||
return cellValue.compareTo(v1) <= 0;
|
return cellValue.compareTo(v1) <= 0;
|
||||||
}
|
}
|
||||||
|
@ -645,7 +705,7 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
/**
|
/**
|
||||||
* Note: this class has a natural ordering that is inconsistent with equals.
|
* Note: this class has a natural ordering that is inconsistent with equals.
|
||||||
*/
|
*/
|
||||||
protected class ValueAndFormat implements Comparable<ValueAndFormat> {
|
protected static class ValueAndFormat implements Comparable<ValueAndFormat> {
|
||||||
|
|
||||||
private final Double value;
|
private final Double value;
|
||||||
private final String string;
|
private final String string;
|
||||||
|
@ -671,7 +731,11 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
|
if (!(obj instanceof ValueAndFormat)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
ValueAndFormat o = (ValueAndFormat) obj;
|
ValueAndFormat o = (ValueAndFormat) obj;
|
||||||
return ( value == o.value || value.equals(o.value))
|
return ( value == o.value || value.equals(o.value))
|
||||||
&& ( format == o.format || format.equals(o.format))
|
&& ( format == o.format || format.equals(o.format))
|
||||||
|
@ -683,18 +747,30 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
* @param o
|
* @param o
|
||||||
* @return value comparison
|
* @return value comparison
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int compareTo(ValueAndFormat o) {
|
public int compareTo(ValueAndFormat o) {
|
||||||
if (value == null && o.value != null) return 1;
|
if (value == null && o.value != null) {
|
||||||
if (o.value == null && value != null) return -1;
|
return 1;
|
||||||
|
}
|
||||||
|
if (o.value == null && value != null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
int cmp = value == null ? 0 : value.compareTo(o.value);
|
int cmp = value == null ? 0 : value.compareTo(o.value);
|
||||||
if (cmp != 0) return cmp;
|
if (cmp != 0) {
|
||||||
|
return cmp;
|
||||||
|
}
|
||||||
|
|
||||||
if (string == null && o.string != null) return 1;
|
if (string == null && o.string != null) {
|
||||||
if (o.string == null && string != null) return -1;
|
return 1;
|
||||||
|
}
|
||||||
|
if (o.string == null && string != null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return string == null ? 0 : string.compareTo(o.string);
|
return string == null ? 0 : string.compareTo(o.string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (string == null ? 0 : string.hashCode()) * 37 * 37 + 37 * (value == null ? 0 : value.hashCode()) + (format == null ? 0 : format.hashCode());
|
return (string == null ? 0 : string.hashCode()) * 37 * 37 + 37 * (value == null ? 0 : value.hashCode()) + (format == null ? 0 : format.hashCode());
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,7 +232,7 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
|
||||||
// check for emf+ embedded pdf (poor mans style :( )
|
// check for emf+ embedded pdf (poor mans style :( )
|
||||||
// Mac Excel 2011 embeds pdf files with this method.
|
// Mac Excel 2011 embeds pdf files with this method.
|
||||||
PictureData pd = source.getPictureData();
|
PictureData pd = source.getPictureData();
|
||||||
if (pd != null && pd.getPictureType() != Workbook.PICTURE_TYPE_EMF) {
|
if (pd == null || pd.getPictureType() != Workbook.PICTURE_TYPE_EMF) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.poi.xssf.binary;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -163,7 +164,8 @@ public class XSSFBHyperlinksTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TopLeftCellAddressComparator implements Comparator<CellAddress> {
|
private static class TopLeftCellAddressComparator implements Comparator<CellAddress>, Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(CellAddress o1, CellAddress o2) {
|
public int compare(CellAddress o1, CellAddress o2) {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.util.Internal;
|
import org.apache.poi.util.Internal;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
import org.apache.poi.util.LittleEndianConsts;
|
||||||
import org.apache.poi.util.RecordFormatException;
|
import org.apache.poi.util.RecordFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,11 +72,11 @@ public class HemfCommentPublic {
|
||||||
//note that raw bytes includes the public comment identifier
|
//note that raw bytes includes the public comment identifier
|
||||||
int currentOffset = 4 + 16;//4 public comment identifier, 16 for outputrect
|
int currentOffset = 4 + 16;//4 public comment identifier, 16 for outputrect
|
||||||
long countFormats = LittleEndian.getUInt(rawBytes, currentOffset);
|
long countFormats = LittleEndian.getUInt(rawBytes, currentOffset);
|
||||||
currentOffset += LittleEndian.INT_SIZE;
|
currentOffset += LittleEndianConsts.INT_SIZE;
|
||||||
List<EmrFormat> emrFormatList = new ArrayList<EmrFormat>();
|
List<EmrFormat> emrFormatList = new ArrayList<EmrFormat>();
|
||||||
for (long i = 0; i < countFormats; i++) {
|
for (long i = 0; i < countFormats; i++) {
|
||||||
emrFormatList.add(new EmrFormat(rawBytes, currentOffset));
|
emrFormatList.add(new EmrFormat(rawBytes, currentOffset));
|
||||||
currentOffset += 4 * LittleEndian.INT_SIZE;
|
currentOffset += 4 * LittleEndianConsts.INT_SIZE;
|
||||||
}
|
}
|
||||||
List<HemfMultiFormatsData> list = new ArrayList<HemfMultiFormatsData>();
|
List<HemfMultiFormatsData> list = new ArrayList<HemfMultiFormatsData>();
|
||||||
for (EmrFormat emrFormat : emrFormatList) {
|
for (EmrFormat emrFormat : emrFormatList) {
|
||||||
|
@ -86,20 +87,20 @@ public class HemfCommentPublic {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class EmrFormat {
|
private static class EmrFormat {
|
||||||
long signature;
|
long signature;
|
||||||
long version;
|
long version;
|
||||||
int size;
|
int size;
|
||||||
int offset;
|
int offset;
|
||||||
|
|
||||||
public EmrFormat(byte[] rawBytes, int currentOffset) {
|
public EmrFormat(byte[] rawBytes, int currentOffset) {
|
||||||
signature = LittleEndian.getUInt(rawBytes, currentOffset); currentOffset += LittleEndian.INT_SIZE;
|
signature = LittleEndian.getUInt(rawBytes, currentOffset); currentOffset += LittleEndianConsts.INT_SIZE;
|
||||||
version = LittleEndian.getUInt(rawBytes, currentOffset); currentOffset += LittleEndian.INT_SIZE;
|
version = LittleEndian.getUInt(rawBytes, currentOffset); currentOffset += LittleEndianConsts.INT_SIZE;
|
||||||
//spec says this must be a 32bit "aligned" typo for "signed"?
|
//spec says this must be a 32bit "aligned" typo for "signed"?
|
||||||
//realistically, this has to be an int...
|
//realistically, this has to be an int...
|
||||||
size = LittleEndian.getInt(rawBytes, currentOffset); currentOffset += LittleEndian.INT_SIZE;
|
size = LittleEndian.getInt(rawBytes, currentOffset); currentOffset += LittleEndianConsts.INT_SIZE;
|
||||||
//y, can be long, but realistically?
|
//y, can be long, but realistically?
|
||||||
offset = LittleEndian.getInt(rawBytes, currentOffset); currentOffset += LittleEndian.INT_SIZE;
|
offset = LittleEndian.getInt(rawBytes, currentOffset); currentOffset += LittleEndianConsts.INT_SIZE;
|
||||||
if (size < 0) {
|
if (size < 0) {
|
||||||
throw new RecordFormatException("size for emrformat must be > 0");
|
throw new RecordFormatException("size for emrformat must be > 0");
|
||||||
}
|
}
|
||||||
|
@ -118,12 +119,12 @@ public class HemfCommentPublic {
|
||||||
private final byte[] wmfBytes;
|
private final byte[] wmfBytes;
|
||||||
public WindowsMetafile(byte[] rawBytes) {
|
public WindowsMetafile(byte[] rawBytes) {
|
||||||
super(rawBytes);
|
super(rawBytes);
|
||||||
int offset = LittleEndian.INT_SIZE;//public comment identifier
|
int offset = LittleEndianConsts.INT_SIZE;//public comment identifier
|
||||||
int version = LittleEndian.getUShort(rawBytes, offset); offset += LittleEndian.SHORT_SIZE;
|
int version = LittleEndian.getUShort(rawBytes, offset); offset += LittleEndianConsts.SHORT_SIZE;
|
||||||
int reserved = LittleEndian.getUShort(rawBytes, offset); offset += LittleEndian.SHORT_SIZE;
|
int reserved = LittleEndian.getUShort(rawBytes, offset); offset += LittleEndianConsts.SHORT_SIZE;
|
||||||
offset += LittleEndian.INT_SIZE; //checksum
|
offset += LittleEndianConsts.INT_SIZE; //checksum
|
||||||
offset += LittleEndian.INT_SIZE; //flags
|
offset += LittleEndianConsts.INT_SIZE; //flags
|
||||||
long winMetafileSizeLong = LittleEndian.getUInt(rawBytes, offset); offset += LittleEndian.INT_SIZE;
|
long winMetafileSizeLong = LittleEndian.getUInt(rawBytes, offset); offset += LittleEndianConsts.INT_SIZE;
|
||||||
if (winMetafileSizeLong == 0L) {
|
if (winMetafileSizeLong == 0L) {
|
||||||
wmfBytes = new byte[0];
|
wmfBytes = new byte[0];
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue