# Class Bundle

java.lang.Object
htsjdk.beta.io.bundle.Bundle

All Implemented Interfaces:
  `Serializable, Iterable<BundleResource>`

Direct Known Subclasses:
  `ReadsBundle, VariantsBundle`

public class Bundle extends Object implements Iterable<BundleResource>, Serializable
An immutable collection of related resources, including a (single, required) primary resource, such as "reads", "variants", "features", or "reference", plus zero or more related secondary resources ("index", "dictionary", "MD5", etc.).

Each resource in a `Bundle` is represented by a `BundleResource`, which in turn describes a binding mechanism for that resource (such as an `IOPath` in the case of a URI, Path or file name; or an input or output stream), and a "content type" string that is unique within that `Bundle`. Any string can be used as a content type. Predefined content type strings are defined in `BundleResourceType`.

A `Bundle` must have one resource that is designated as the "primary" resource, specified by a content type string. A resource with "primary content type" is guaranteed to be present in the `Bundle`.

Since each resource in a `Bundle` has a content type that is unique within that `Bundle`, a Bundle can not be used to represent a list of similar items where each item is equivalent to each other item (i.e., a list of shards, where each shard in the list is equivalent to each other shard). Rather `Bundle`s are used to represent related resources where each resource has a unique character or role relative to the other resources (i.e., a "reads" resource and a corresponding "index" resource).

Bundles that contain only serializable (`IOPathResource`) resources may be serialized to, and deserialized from JSON. Note that the order of resources in a bundle is not significant, and is not guaranteed to be preserved.

See Also:
  - Serialized Form

## Constructor Summary

Constructors
Constructor
Description
`Bundle(String primaryContentType, Collection<BundleResource> resources)`
Create a new bundle from an existing resource collection.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`equals(Object o)`
`static boolean`
`equalsIgnoreOrder(Bundle bundle1, Bundle bundle2)`
`Optional<BundleResource>`
`get(String targetContentType)`
Get the BundleResource for the provided targetContentType string.
`BundleResource`
`getOrThrow(String requiredContentType)`
Get the BundleResource for the provided targetContentType string, or throw if no such resource exists.
`String`
`getPrimaryContentType()`
Get the primary content type for this bundle.
`BundleResource`
`getPrimaryResource()`
Get the primary `BundleResource` for this bundle.
`Collection<BundleResource>`
`getResources()`
Get the collection of resources from this `Bundle`.
`int`
`hashCode()`
`Iterator<BundleResource>`
`iterator()`
Get an iterator of BundleResources for this bundle.
`String`
`toString()`

### Methods inherited from class Object

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

### Methods inherited from interface Iterable

`forEach, spliterator`

## Constructor Details

### Bundle

public Bundle(String primaryContentType, Collection<BundleResource> resources)
Create a new bundle from an existing resource collection.

Parameters:
  `primaryContentType` - the content type of the primary resource in this bundle. may not be null. a resource with this content type must be included in resources
  `resources` - resources to include in this bundle, may not be null or empty

## Method Details

### get

public Optional<BundleResource> get(String targetContentType)
Get the BundleResource for the provided targetContentType string.

Parameters:
  `targetContentType` - the content type to be retrieved from the bundle
Returns:
  an Optional<BundleResource> that contains the targetContent type

### getOrThrow

public BundleResource getOrThrow(String requiredContentType)
Get the BundleResource for the provided targetContentType string, or throw if no such resource exists.

Parameters:
  `requiredContentType` - the content type to be retrieved from the bundle
Returns:
  a BundleResource of type targetContentType
Throws:
  `IllegalArgumentException` - if the targetContentType resource isn't present in the bundle

### getPrimaryContentType

public String getPrimaryContentType()
Get the primary content type for this bundle.

Returns:
  the primary content type for this bundle

### getPrimaryResource

public BundleResource getPrimaryResource()
Get the primary `BundleResource` for this bundle.

Returns:
  the primary `BundleResource` for this bundle.

### getResources

public Collection<BundleResource> getResources()
Get the collection of resources from this `Bundle`.

### iterator

public Iterator<BundleResource> iterator()
Get an iterator of BundleResources for this bundle.

Specified by:
  `iterator` in interface `Iterable<BundleResource>`
Returns:
  iterator of BundleResources for this bundle.

### equals

public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### equalsIgnoreOrder

public static boolean equalsIgnoreOrder(Bundle bundle1, Bundle bundle2)