Top Description Fields Constructors Methods
org.apache.poi.ss.util

public final Class CellRangeUtil

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Collections, .List

Utility class that builds on CellRangeAddress Portions of this class may be moved to CellRangeAddressBase

Field Summary

Modifier and TypeField and Description
public static final int
ENCLOSES

first range encloses or is equal to the second

public static final int
INSIDE

first range is within the second range

public static final int
public static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if cell range A contains cell range B
contains
(CellRangeAddress
cell range A
crA
,
CellRangeAddress
cell range B
crB
)

Check if cell range A contains cell range B (B <= A)

Todo

move this into CellRangeAddressBase

public static CellRangeAddress

Returns:

enclosing CellRange
createEnclosingCellRange
(CellRangeAddress crA, CellRangeAddress crB)

Create an enclosing CellRange for the two cell ranges.

private static boolean

Returns:

true if a >= b
ge
(int a, int b)

private static boolean

Returns:

true if a > b
gt
(int a, int b)

public static boolean

Returns:

true if the ranges have a complete shared border (i.e. the two ranges together make a simple rectangular region.
hasExactSharedBorder
(CellRangeAddress crA, CellRangeAddress crB)

Check if the two cell ranges have a shared border.

public static int

Returns:

code which reflects how the specified range is related to this range.
Possible return codes are:
  • NO_INTERSECTION - the specified range is outside of this range;
  • OVERLAP - both ranges partially overlap
  • INSIDE - the specified range is inside of this one
  • ENCLOSES - the specified range encloses (possibly exactly the same as) this range
intersect
(CellRangeAddress crA, CellRangeAddress
- the specified range
crB
)

Get the type of intersection between two cell ranges

private static boolean

Returns:

true if a <= b
le
(int a, int b)

private static boolean

Returns:

true if a < b
lt
(int a, int b)

public static CellRangeAddress[]

Returns:

list of merged cell ranges
mergeCellRanges
(CellRangeAddress[]
the ranges to merge
cellRanges
)

Do all possible cell merges between cells of the list so that:

  • if a cell range is completely inside of another cell range, it gets removed from the list
  • if two cells have a shared border, merge them into one bigger cell range
private static List<CellRangeAddress>
private static CellRangeAddress[]

Returns:

the new range(s) to replace the supplied ones. null if no merge is possible
mergeRanges
(CellRangeAddress range1, CellRangeAddress range2)

private static CellRangeAddress[]
private static List<CellRangeAddress>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ENCLOSESback to summary
public static final int ENCLOSES

first range encloses or is equal to the second

INSIDEback to summary
public static final int INSIDE

first range is within the second range

NO_INTERSECTIONback to summary
public static final int NO_INTERSECTION
OVERLAPback to summary
public static final int OVERLAP

Constructor Detail

CellRangeUtilback to summary
private CellRangeUtil()

Method Detail

containsback to summary
public static boolean contains(CellRangeAddress crA, CellRangeAddress crB)

Check if cell range A contains cell range B (B <= A)

Todo

move this into CellRangeAddressBase

Parameters
crA:CellRangeAddress

cell range A

crB:CellRangeAddress

cell range B

Returns:boolean

true if cell range A contains cell range B

createEnclosingCellRangeback to summary
public static CellRangeAddress createEnclosingCellRange(CellRangeAddress crA, CellRangeAddress crB)

Create an enclosing CellRange for the two cell ranges.

Returns:CellRangeAddress

enclosing CellRange

geback to summary
private static boolean ge(int a, int b)
Returns:boolean

true if a >= b

gtback to summary
private static boolean gt(int a, int b)
Returns:boolean

true if a > b

hasExactSharedBorderback to summary
public static boolean hasExactSharedBorder(CellRangeAddress crA, CellRangeAddress crB)

Check if the two cell ranges have a shared border.

Returns:boolean

true if the ranges have a complete shared border (i.e. the two ranges together make a simple rectangular region.

intersectback to summary
public static int intersect(CellRangeAddress crA, CellRangeAddress crB)

Get the type of intersection between two cell ranges

Parameters
crB:CellRangeAddress

- the specified range

Returns:int

code which reflects how the specified range is related to this range.
Possible return codes are:

  • NO_INTERSECTION - the specified range is outside of this range;
  • OVERLAP - both ranges partially overlap
  • INSIDE - the specified range is inside of this one
  • ENCLOSES - the specified range encloses (possibly exactly the same as) this range
See Also
CellRangeAddressBase#intersects(CellRangeAddressBase)
leback to summary
private static boolean le(int a, int b)
Returns:boolean

true if a <= b

ltback to summary
private static boolean lt(int a, int b)
Returns:boolean

true if a < b

mergeCellRangesback to summary
public static CellRangeAddress[] mergeCellRanges(CellRangeAddress[] cellRanges)

Do all possible cell merges between cells of the list so that:

  • if a cell range is completely inside of another cell range, it gets removed from the list
  • if two cells have a shared border, merge them into one bigger cell range
Parameters
cellRanges:CellRangeAddress[]

the ranges to merge

Returns:CellRangeAddress[]

list of merged cell ranges

mergeCellRangesback to summary
private static List<CellRangeAddress> mergeCellRanges(List<CellRangeAddress> cellRangeList)
mergeRangesback to summary
private static CellRangeAddress[] mergeRanges(CellRangeAddress range1, CellRangeAddress range2)
Returns:CellRangeAddress[]

the new range(s) to replace the supplied ones. null if no merge is possible

toArrayback to summary
private static CellRangeAddress[] toArray(List<CellRangeAddress> temp)
toListback to summary
private static List<CellRangeAddress> toList(CellRangeAddress[] temp)