Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/davidje13/multivaluecollections

Java collections for multiple object types in one collection
https://github.com/davidje13/multivaluecollections

java

Last synced: 27 days ago
JSON representation

Java collections for multiple object types in one collection

Awesome Lists containing this project

README

        

# Multivalue Collections

Java collection classes for situations where multiple types of object need to
live in one collection.

Collections are immutable. Populating collections with values is achieved via
builders.

## Path

Paths store a node-edge-node-edge-node pattern. They always start and finish on
a node.

The types of path supported are:

- `LinkedPath` (backed by a doubly-linked-list)
- `ArrayPath` (backed by an array)

The API for both is identical. The common interface is `ImmutablePath`.

### Example

```java
import com.davidje13.path.*;

ImmutablePath path = LinkedPath.builder("node 1")
.pushBack("edge 1", "node 2")
.pushBack("edge 2", "node 3")
.build();

List nodes = path.getNodesFromHead();
// nodes = ["node 1", "node 2", "node 3"]

List seen = new ArrayList();
path.visitFromHead(
(node) -> seen.add(node),
(edge) -> seen.add(edge)
);
// seen = ["node 1", "edge 1", "node 2", "edge 2", "node 3"]
```