Giter Club home page Giter Club logo

streems's Introduction

Streems Build Status

Read me first

This project is licensed under the Apache Software License, version 2. See the LICENSE file at the root of the project for more details.

This project requires Java 8.

The current version is 0.2.0:

dependencies {
    compile(group: "com.github.javachat", name: "streems", version: "0.1.0");
}

Another package exists which provides a way to reuse a TreeTraverer from Guava (see below):

dependencies {
    compile(group: "com.github.javachat", name: "streems-guava", version: "0.1.0");
}

What this is

This library provides a Stream interface over n-ary trees.

The idea was inspired by Guava's TreeTraverser. Since Guava is aimed at Java 7 or less, its traversal methods return instances of Iterables, not Streams. This package provides such a functionality.

The different traversals of an n-ary tree

An example is provided by the javadoc of TreeTraverser; we will reproduce it here:

For example, the tree

          h
        / | \
       /  e  \
      d       g
     /|\      |
    / | \     f
   a  b  c       

can be iterated over in preorder (hdabcegf), postorder (abcdefgh), or
breadth-first order (hdegabcf).

Usage

You provide a class which gives access to its immediate children, in order, using either of:

  • a Stream,
  • an Iterator,
  • an Iterable,
  • or an array.

You can then use this API to traverse instances of the class as an n-ary tree in any order: preorder, postorder or breadth first.

For instance:

final Stream<MyNode> stream
    = Streems.traverse(myNode, MyNode::children, Traversal.PREORDER);

Notes about the returned Streams...

The underlying Spliterator will always have the same characteristics: ORDERED and NONNULL:

  • ORDERED is obvious... After all, you choose the traversal order and you expect nodes to be returned in that order;
  • NONNULL because it is a requirement (you cannot attempt to get any children from a null node).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.