package org.apache.poi.ss.usermodel;
-
/**
* The Threshold / CFVO / Conditional Formatting Value Object.
* <p>This defines how to calculate the ranges for a conditional
*/
public interface ConditionalFormattingThreshold {
enum RangeType {
+ // IDs should match the values documented
+ // in the spec for HSSF, e.g. at
+ // https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-xls/3cc68999-c2fc-4a57-92a5-94c0720779e9
+
/** Number / Parameter */
NUMBER(1, "num"),
+
/** The minimum value from the range */
MIN(2, "min"),
+
/** The maximum value from the range */
MAX(3, "max"),
+
/** Percent of the way from the mi to the max value in the range */
PERCENT(4, "percent"),
+
/** The minimum value of the cell that is in X percentile of the range */
PERCENTILE(5, "percentile"),
+
UNALLOCATED(6, null),
+
/** Formula result */
FORMULA(7, "formula");
}
public static RangeType byId(int id) {
+ // id is mapped to ordinal()+1
+ if (id <= 0 || id > values().length) {
+ return null;
+ }
+
return values()[id-1]; // 1-based IDs
}
+
public static RangeType byName(String name) {
for (RangeType t : values()) {
- if (t.name.equals(name)) return t;
+ if (t.name == null && name == null) {
+ return t;
+ } else if (t.name != null && t.name.equals(name)) {
+ return t;
+ }
}
+
return null;
}
}
}
}
+
+ @Test
+ void testRangeType() {
+ for (RangeType rangeType : RangeType.values()) {
+ assertEquals(rangeType, RangeType.byName(rangeType.name));
+ assertEquals(rangeType, RangeType.byId(rangeType.id));
+ }
+
+ assertEquals(RangeType.UNALLOCATED, RangeType.byName(null));
+ assertNull(RangeType.byName("some other name"));
+
+ assertNull(RangeType.byId(-1));
+ assertNull(RangeType.byId(0));
+ assertNull(RangeType.byId(99));
+ }
}
\ No newline at end of file