Package org.apache.lucene.spatial.prefix.tree

# Class NumberRangePrefixTree.NRCell

java.lang.Object
org.apache.lucene.spatial.prefix.tree.CellIterator
org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.NRCell

All Implemented Interfaces:
  `Cloneable`, `Comparable<NumberRangePrefixTree.UnitNRShape>`, `Iterator<Cell>`, `Cell`, `NumberRangePrefixTree.NRShape`, `NumberRangePrefixTree.UnitNRShape`, `org.locationtech.spatial4j.shape.Shape`

Enclosing class:
  `NumberRangePrefixTree`

protected class NumberRangePrefixTree.NRCell extends CellIterator implements Cell, NumberRangePrefixTree.UnitNRShape
Most of the PrefixTree implementation is in this one class, which is both the Cell, the CellIterator, and the Shape to reduce object allocation. It's implemented as a re-used array/stack of Cells at adjacent levels, that all have a reference back to the cell array to traverse. They also share a common BytesRef for the term.

NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

## Field Summary

### Fields inherited from class org.apache.lucene.spatial.prefix.tree.CellIterator

`nextCell, thisCell`

## Method Summary

Modifier and Type
Method
Description
`NumberRangePrefixTree.UnitNRShape`
`clone()`
Deep clone
`int`
`compareTo(NumberRangePrefixTree.UnitNRShape o)`
`int`
`compareToNoLeaf(Cell fromCell)`
Equivalent to `this.getTokenBytesNoLeaf(null).compareTo(fromCell.getTokenBytesNoLeaf(null))`.
`boolean`
`equals(Object obj)`
`double`
`getArea(org.locationtech.spatial4j.context.SpatialContext ctx)`
`org.locationtech.spatial4j.shape.Rectangle`
`getBoundingBox()`
`org.locationtech.spatial4j.shape.Shape`
`getBuffered(double distance, org.locationtech.spatial4j.context.SpatialContext ctx)`
`org.locationtech.spatial4j.shape.Point`
`getCenter()`
`org.locationtech.spatial4j.context.SpatialContext`
`getContext()`
`int`
`getLevel()`
Level 0 is the world (and has no parent), from then on a higher level means a smaller cell than the level before it.
`CellIterator`
`getNextLevelCells(org.locationtech.spatial4j.shape.Shape shapeFilter)`
Gets the cells at the next grid cell level underneath this one, optionally filtered by `shapeFilter`.
`NumberRangePrefixTree.UnitNRShape`
`getShape()`
Gets the shape for this cell; typically a Rectangle.
`NumberRangePrefixTree.NRCell`
`getShapeAtLevel(int level)`
Gets an ancestor at the specified level.
`org.locationtech.spatial4j.shape.SpatialRelation`
`getShapeRel()`
Gets the relationship this cell has with the shape from which it was filtered from, assuming it came from a `CellIterator`.
`BytesRef`
`getTokenBytesNoLeaf(BytesRef result)`
Returns the bytes for this cell, without a leaf set.
`BytesRef`
`getTokenBytesWithLeaf(BytesRef result)`
Returns the bytes for this cell, with a leaf byte if this is a leaf cell.
`int`
`getValAtLevel(int level)`
Gets the value at the specified level of this unit.
`boolean`
`hasArea()`
`int`
`hashCode()`
`boolean`
`hasNext()`
`boolean`
`isEmpty()`
`boolean`
`isLeaf()`
Some cells are flagged as leaves, which are indexed as such.
`boolean`
`isPrefixOf(Cell c)`
Returns if the target term is within/underneath this cell; not necessarily a direct descendant.
`org.locationtech.spatial4j.shape.SpatialRelation`
`relate(NumberRangePrefixTree.SpanUnitsNRShape spanShape)`
`org.locationtech.spatial4j.shape.SpatialRelation`
`relate(NumberRangePrefixTree.UnitNRShape lv)`
`org.locationtech.spatial4j.shape.SpatialRelation`
`relate(org.locationtech.spatial4j.shape.Shape shape)`
`NumberRangePrefixTree.UnitNRShape`
`roundToLevel(int targetLevel)`
Returns this shape rounded to the target level.
`void`
`setLeaf()`
Set this cell to be a leaf.
`void`
`setShapeRel(org.locationtech.spatial4j.shape.SpatialRelation rel)`
See `Cell.getShapeRel()`.
`String`
`toString()`
The result should be parseable by `NumberRangePrefixTree.parseShape(String)`.
`String`
`toStringDebug()`
Configure your IDE to use this.

### Methods inherited from class org.apache.lucene.spatial.prefix.tree.CellIterator

`next, nextFrom, remove, thisCell`

### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.util.Iterator

`forEachRemaining`

## Method Details

### getLevel

public int getLevel()
Description copied from interface: `Cell`
Level 0 is the world (and has no parent), from then on a higher level means a smaller cell than the level before it.

Specified by:
  `getLevel` in interface `Cell`
Specified by:
  `getLevel` in interface `NumberRangePrefixTree.UnitNRShape`

### getShapeRel

public org.locationtech.spatial4j.shape.SpatialRelation getShapeRel()
Description copied from interface: `Cell`
Gets the relationship this cell has with the shape from which it was filtered from, assuming it came from a `CellIterator`. Arguably it belongs there but it's very convenient here.

Specified by:
  `getShapeRel` in interface `Cell`

### setShapeRel

public void setShapeRel(org.locationtech.spatial4j.shape.SpatialRelation rel)
Description copied from interface: `Cell`
See `Cell.getShapeRel()`.

Specified by:
  `setShapeRel` in interface `Cell`

### isLeaf

public boolean isLeaf()
Description copied from interface: `Cell`
Some cells are flagged as leaves, which are indexed as such. A leaf cell is either within some shape or it both intersects and the cell is at an accuracy threshold such that no smaller cells for the shape will be represented.

Specified by:
  `isLeaf` in interface `Cell`

### setLeaf

public void setLeaf()
Description copied from interface: `Cell`
Set this cell to be a leaf. Warning: never call on a cell initialized to reference the same bytes from termsEnum, which should be treated as immutable. Note: not supported at level 0.

Specified by:
  `setLeaf` in interface `Cell`

### getShape

public NumberRangePrefixTree.UnitNRShape getShape()
Description copied from interface: `Cell`
Gets the shape for this cell; typically a Rectangle.

Specified by:
  `getShape` in interface `Cell`

### getTokenBytesNoLeaf

public BytesRef getTokenBytesNoLeaf(BytesRef result)
Description copied from interface: `Cell`
Returns the bytes for this cell, without a leaf set. The bytes should sort before `Cell.getTokenBytesWithLeaf(org.apache.lucene.util.BytesRef)`. The result param is used to save object allocation, though its bytes aren't used.

Specified by:
  `getTokenBytesNoLeaf` in interface `Cell`
Parameters:
  `result` - where the result goes, or null to create new

### getTokenBytesWithLeaf

public BytesRef getTokenBytesWithLeaf(BytesRef result)
Description copied from interface: `Cell`
Returns the bytes for this cell, with a leaf byte if this is a leaf cell. The result param is used to save object allocation, though its bytes aren't used.

Specified by:
  `getTokenBytesWithLeaf` in interface `Cell`
Parameters:
  `result` - where the result goes, or null to create new

### isPrefixOf

public boolean isPrefixOf(Cell c)
Description copied from interface: `Cell`
Returns if the target term is within/underneath this cell; not necessarily a direct descendant.

Specified by:
  `isPrefixOf` in interface `Cell`
Parameters:
  `c` - the term

### compareToNoLeaf

public int compareToNoLeaf(Cell fromCell)
Description copied from interface: `Cell`
Equivalent to `this.getTokenBytesNoLeaf(null).compareTo(fromCell.getTokenBytesNoLeaf(null))`.

Specified by:
  `compareToNoLeaf` in interface `Cell`

### getNextLevelCells

public CellIterator getNextLevelCells(org.locationtech.spatial4j.shape.Shape shapeFilter)
Description copied from interface: `Cell`
Gets the cells at the next grid cell level underneath this one, optionally filtered by `shapeFilter`. The returned cells should have `Cell.getShapeRel()` set to their relation with `shapeFilter`. In addition, for non-points `Cell.isLeaf()` must be true when that relation is WITHIN.

IMPORTANT: Cells returned from this iterator can be shared, as well as the bytes.

Precondition: Never called when getLevel() == maxLevel.

Specified by:
  `getNextLevelCells` in interface `Cell`
Parameters:
  `shapeFilter` - an optional filter for the returned cells.
Returns:
  A set of cells (no dups), sorted. Not Modifiable.

### hasNext

public boolean hasNext()

Specified by:
  `hasNext` in interface `Iterator<Cell>`

### getValAtLevel

public int getValAtLevel(int level)
Description copied from interface: `NumberRangePrefixTree.UnitNRShape`
Gets the value at the specified level of this unit. level must be >= 0 and <= getLevel().

Specified by:
  `getValAtLevel` in interface `NumberRangePrefixTree.UnitNRShape`

### getShapeAtLevel

public NumberRangePrefixTree.NRCell getShapeAtLevel(int level)
Description copied from interface: `NumberRangePrefixTree.UnitNRShape`
Gets an ancestor at the specified level. It shares state, so you may want to clone() it.

Specified by:
  `getShapeAtLevel` in interface `NumberRangePrefixTree.UnitNRShape`

### roundToLevel

public NumberRangePrefixTree.UnitNRShape roundToLevel(int targetLevel)
Description copied from interface: `NumberRangePrefixTree.NRShape`
Returns this shape rounded to the target level. If we are already more course than the level then the shape is simply returned. The result may refer to internal state of the argument so you may want to clone it.

Specified by:
  `roundToLevel` in interface `NumberRangePrefixTree.NRShape`
Specified by:
  `roundToLevel` in interface `NumberRangePrefixTree.UnitNRShape`

### relate

public org.locationtech.spatial4j.shape.SpatialRelation relate(org.locationtech.spatial4j.shape.Shape shape)

Specified by:
  `relate` in interface `org.locationtech.spatial4j.shape.Shape`

### relate

public org.locationtech.spatial4j.shape.SpatialRelation relate(NumberRangePrefixTree.UnitNRShape lv)

### relate

public org.locationtech.spatial4j.shape.SpatialRelation relate(NumberRangePrefixTree.SpanUnitsNRShape spanShape)

### clone

public NumberRangePrefixTree.UnitNRShape clone()
Description copied from interface: `NumberRangePrefixTree.UnitNRShape`
Deep clone

Specified by:
  `clone` in interface `NumberRangePrefixTree.UnitNRShape`
Overrides:
  `clone` in class `Object`

### compareTo

public int compareTo(NumberRangePrefixTree.UnitNRShape o)

Specified by:
  `compareTo` in interface `Comparable<NumberRangePrefixTree.UnitNRShape>`

### getBoundingBox

public org.locationtech.spatial4j.shape.Rectangle getBoundingBox()

Specified by:
  `getBoundingBox` in interface `org.locationtech.spatial4j.shape.Shape`

### hasArea

public boolean hasArea()

Specified by:
  `hasArea` in interface `org.locationtech.spatial4j.shape.Shape`

### getArea

public double getArea(org.locationtech.spatial4j.context.SpatialContext ctx)

Specified by:
  `getArea` in interface `org.locationtech.spatial4j.shape.Shape`

### getCenter

public org.locationtech.spatial4j.shape.Point getCenter()

Specified by:
  `getCenter` in interface `org.locationtech.spatial4j.shape.Shape`

### getBuffered

public org.locationtech.spatial4j.shape.Shape getBuffered(double distance, org.locationtech.spatial4j.context.SpatialContext ctx)

Specified by:
  `getBuffered` in interface `org.locationtech.spatial4j.shape.Shape`

### isEmpty

public boolean isEmpty()

Specified by:
  `isEmpty` in interface `org.locationtech.spatial4j.shape.Shape`

### equals

public boolean equals(Object obj)

Specified by:
  `equals` in interface `org.locationtech.spatial4j.shape.Shape`
Overrides:
  `equals` in class `Object`

### getContext

public org.locationtech.spatial4j.context.SpatialContext getContext()

Specified by:
  `getContext` in interface `org.locationtech.spatial4j.shape.Shape`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### toString

public String toString()
Description copied from interface: `NumberRangePrefixTree.NRShape`
The result should be parseable by `NumberRangePrefixTree.parseShape(String)`.

Specified by:
  `toString` in interface `NumberRangePrefixTree.NRShape`
Overrides:
  `toString` in class `Object`

### toStringDebug

public String toStringDebug()
Configure your IDE to use this.