org.apache.tinkerpop.gremlin.algorithm.generator

## Class SizableIterable<T>

- java.lang.Object
- - org.apache.tinkerpop.gremlin.algorithm.generator.SizableIterable<T>

- All Implemented Interfaces:
    Iterable<T>

      public class SizableIterable<T>
      extends Object
      implements Iterable<T>

  Utility class to make size determinations for `Iterable` for efficient.

  If the number of elements in an Iterable is known, then the Iterable can be wrapped in this class to make determining the size a constant time operation rather than an iteration over the whole Iterable.

  Some generators need to know the number of vertices prior to generation. Using this class can speed up the generator.
  Author:
    Matthias Broecheler (me@matthiasb.com)

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SizableIterable(Iterable<T> iterable, int size)` Wraps the given Iterable with the given size.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Iterator<T>` | `iterator()`
    `int` | `size()` Returns the size of the Iterable
    `static <T> int` | `sizeOf(Iterable<T> iterable)` Utility method to determine the number of elements in an Iterable.

    - ### Methods inherited from class java.lang.Object

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

    - ### Methods inherited from interface java.lang.Iterable

      `forEach, spliterator`

- - ### Constructor Detail

    - #### SizableIterable

          public SizableIterable(Iterable<T> iterable,
                                 int size)

      Wraps the given Iterable with the given size.

      NOTE: the size MUST be the size of the Iterable. This is not verified.

  - ### Method Detail

    - #### size

          public int size()

      Returns the size of the Iterable
      Returns:
        Size of the Iterable

    - #### iterator

          public Iterator<T> iterator()

      Specified by:
        `iterator` in interface `Iterable<T>`

    - #### sizeOf

          public static <T> int sizeOf(Iterable<T> iterable)

      Utility method to determine the number of elements in an Iterable.

      Checks if the given Iterable is an instance of a Collection or SizableIterable before iterating to improve performance.
      Returns:
        The size of the given Iterable.

Copyright © 2013–2018 Apache Software Foundation. All rights reserved.