# Class IntegerBag

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

All Implemented Interfaces:
  `IndexBag`

public class IntegerBag extends Object implements IndexBag
IndexBag implementation that stores values individually. It can hold any int value.

Since:
  28 Jan 2025
Author:
  Mark Taylor

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`DFLT_SETMAX`
Default set size threshold.

## Constructor Summary

Constructors
Constructor
Description
`IntegerBag()`
Constructs an IntegerBag with a default set size threshold.
`IntegerBag(int setmax)`
Constructs an IntegerBag with a supplied set size threshold.

## Method Summary

Modifier and Type
Method
Description
`void`
`addIndex(long lval)`
Adds an index to this bag.
`long`
`getCount()`
Returns the number of distinct indices in this bag.
`boolean`
`hasIndex(long lval)`
Indicates whether the given index has previously been added to this bag.
`PrimitiveIterator.OfLong`
`sortedLongIterator()`
Returns an iterator over all the integers added to this bag, supplied in ascending order.

### Methods inherited from class Object

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

## Field Details

### DFLT_SETMAX

public static final int DFLT_SETMAX
Default set size threshold.

See Also:
  - Constant Field Values

## Constructor Details

### IntegerBag

public IntegerBag()
Constructs an IntegerBag with a default set size threshold.

### IntegerBag

public IntegerBag(int setmax)
Constructs an IntegerBag with a supplied set size threshold.

Parameters:
  `setmax` - maximum HashSet size

## Method Details

### hasIndex

public boolean hasIndex(long lval)
Description copied from interface: `IndexBag`
Indicates whether the given index has previously been added to this bag.

If the index is outside of the range permitted by this bag, behaviour is undefined.

Specified by:
  `hasIndex` in interface `IndexBag`
Parameters:
  `lval` - integer to check
Returns:
  true iff the given index has previously been added

### addIndex

public void addIndex(long lval)
Description copied from interface: `IndexBag`
Adds an index to this bag. If the index is already present, there is no effect.

If the index is outside of the range permitted by this bag, behaviour is undefined.

Specified by:
  `addIndex` in interface `IndexBag`
Parameters:
  `lval` - integer to add

### getCount

public long getCount()
Description copied from interface: `IndexBag`
Returns the number of distinct indices in this bag.

Specified by:
  `getCount` in interface `IndexBag`
Returns:
  count of added integers

### sortedLongIterator

public PrimitiveIterator.OfLong sortedLongIterator()
Description copied from interface: `IndexBag`
Returns an iterator over all the integers added to this bag, supplied in ascending order.

Specified by:
  `sortedLongIterator` in interface `IndexBag`
Returns:
  sorted iterator over indices