# Class BagMocBuilder

java.lang.Object
uk.ac.starlink.ttools.moc.BagMocBuilder

All Implemented Interfaces:
  `MocBuilder`

public class BagMocBuilder extends Object implements MocBuilder
MocBuilder implementation based on IndexBags.

Since:
  28 Jan 2025
Author:
  Mark Taylor

## Constructor Summary

Constructors
Constructor
Description
`BagMocBuilder(int maxOrder)`
Constructor with default IndexBag creation policy.
`BagMocBuilder(int maxOrder, LongFunction<IndexBag> bagFactory)`
Constructor with custom IndexBag creation policy.

## Method Summary

Modifier and Type
Method
Description
`void`
`addTile(int order, long ipix)`
Add a numbered tile at a given order.
`void`
`consolidate()`
Following a call to this method, the MOC is in normal form; no sets of 4 tiles in the same quad, no part of the sphere represented by more than one tile at different orders.
`PrimitiveIterator.OfLong`
`createOrderedUniqIterator()`
Returns an iterator over the UNIQ values represented by this MOC in sequence.
`void`
`endTiles()`
Signal that no further tiles will be added.
`long[]`
`getOrderCounts()`
Returns an array of the number of tiles present at each order of the normalised MOC.
`static long`
`uniq(int order, long lindex)`
Encodes an order and a tile index to a UNIQ value.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### BagMocBuilder

public BagMocBuilder(int maxOrder)
Constructor with default IndexBag creation policy.

Parameters:
  `maxOrder` - maximum order stored by this MOC

### BagMocBuilder

public BagMocBuilder(int maxOrder, LongFunction<IndexBag> bagFactory)
Constructor with custom IndexBag creation policy.

Parameters:
  `maxOrder` - maximum order stored by this MOC
  `bagFactory` - creates an IndexBag capable of storing non-negative integers less than the supplied long value

## Method Details

### addTile

public void addTile(int order, long ipix)
Description copied from interface: `MocBuilder`
Add a numbered tile at a given order. Adding a tile that has already been added has no effect.

Specified by:
  `addTile` in interface `MocBuilder`
Parameters:
  `order` - HEALPix order, in the range 0..29
  `ipix` - tile index within the given order, in the range 0..12*4^order

### endTiles

public void endTiles()
Description copied from interface: `MocBuilder`
Signal that no further tiles will be added.

Specified by:
  `endTiles` in interface `MocBuilder`

### createOrderedUniqIterator

public PrimitiveIterator.OfLong createOrderedUniqIterator()
Description copied from interface: `MocBuilder`
Returns an iterator over the UNIQ values represented by this MOC in sequence. That means that the lower-order ones come first.

Should only be called after `MocBuilder.endTiles()` has been called.

Specified by:
  `createOrderedUniqIterator` in interface `MocBuilder`

### getOrderCounts

public long[] getOrderCounts()
Description copied from interface: `MocBuilder`
Returns an array of the number of tiles present at each order of the normalised MOC. The length of the array gives the number of orders present (the last element may not be zero, unless only one element is returned). The sum of the elements of this array gives the number of values that will be returned by `MocBuilder.createOrderedUniqIterator()`.

Should only be called after `MocBuilder.endTiles()` has been called.

Specified by:
  `getOrderCounts` in interface `MocBuilder`

### consolidate

public void consolidate()
Following a call to this method, the MOC is in normal form; no sets of 4 tiles in the same quad, no part of the sphere represented by more than one tile at different orders. There is no change in the semantic content.

Calling this method during a run of tile additions may result in a smaller memory footprint or better performance. Or it may not.

### uniq

public static long uniq(int order, long lindex)
Encodes an order and a tile index to a UNIQ value. Input values are assumed to be legal.

Parameters:
  `order` - order
  `lindex` - tile index within order
Returns:
  uniq value