Transforms an Iterable<T> to a Map<T, Integer> where each item is mapped to its position in the
Iterable's sequence, where the first position is given index {@code startFrom}. If an item
occurs twice, an IllegalArgumentException will be thrown.
760087
public static <T> ImmutableMap<T, Integer> itemToIndexMapStartingFrom(final Iterable<T> sequence,
      int startFrom) {
    final ImmutableMap.Builder<T, Integer> ret = ImmutableMap.builder();

    int idx = startFrom;
    for (final T item : sequence) {
      ret.put(item, idx);
      ++idx;
    }

    return ret.build();
  }
205598
public static <T> Maker<T> cycle(T first, T... rest) {
        ImmutableList<T> values = ImmutableList.<T>builder().add(first).add(rest).build();
        return new RangeValuesMaker<T>(Iterables.cycle(values).iterator());
    }
819800
@Override
    public Object mapSequence(Object sequence) {
        List<List<Integer>> seq = (List<List<Integer>>) sequence;
        List<Integer> ret = new ArrayList<>();
        for (List<Integer> step : seq)
            ret.add((Integer) map(step));
        return ret;
    }
481647
public static <T> Map<T, Integer> countMap(Iterable<T> iter) {
		return countMap(null == iter ? null : iter.iterator());
	}
665765
public static <K, V> Func1<Iterable<Map.Entry<K, V>>, SolidMap<K, V>> toSolidMap() {
        return new Func1<Iterable<Map.Entry<K, V>>, SolidMap<K, V>>() {
            @Override
            public SolidMap<K, V> call(Iterable<Map.Entry<K, V>> iterable) {
                return new SolidMap<>(stream(iterable).map(new Func1<Map.Entry<K, V>, Pair<K, V>>() {
                    @Override
                    public Pair<K, V> call(Map.Entry<K, V> value) {
                        return new Pair<>(value.getKey(), value.getValue());
                    }
                }));
            }
        };
    }
699222
public static <T, E extends Exception> IntList mapToInt(final T[] a, final int fromIndex, final int toIndex, final Try.ToIntFunction<? super T, E> func)
            throws E {
        checkFromToIndex(fromIndex, toIndex, len(a));
        N.checkArgNotNull(func);

        if (N.isNullOrEmpty(a)) {
            return new IntList();
        }

        final IntList result = new IntList(toIndex - fromIndex);

        for (int i = fromIndex; i < toIndex; i++) {
            result.add(func.applyAsInt(a[i]));
        }

        return result;
    }
546240
public static <E> E at(long index, Iterable<E> iterable) {
        dbc.precondition(iterable != null, "cannot call at with a null iterable");
        final Iterator<E> filtered = new FilteringIterator<E>(iterable.iterator(), new AtIndex<E>(index));
        return new FirstElement<E>().apply(filtered);
    }
1168701
function Sequence(iterable) {
    this.sequence = null;
    this._size = 0;
    this.nodeMap = new rMap();
    if (iterable) {
      if (typeof iterable.length === 'number') {
        for (var i = 0; i < iterable.length; i++) {
          this.add.apply(this, iterable[i]);
        }
      } else if (typeof iterable.entries === 'function') {
        var it = iterable.entries();
        while (!it.done) {
          var tmp = it.next();
          this.add.apply(this, tmp);//it.next());
        }
      }
    }
  }
248433
public static <T, R, E extends Exception> List<R> map(final Collection<? extends T> c, final int fromIndex, final int toIndex,
            final Try.Function<? super T, ? extends R, E> func) throws E {
        checkFromToIndex(fromIndex, toIndex, size(c));
        N.checkArgNotNull(func);

        if (N.isNullOrEmpty(c) && fromIndex == 0 && toIndex == 0) {
            return new ArrayList<>();
        }

        final List<R> result = new ArrayList<>(toIndex - fromIndex);

        if (c instanceof List && c instanceof RandomAccess) {
            final List<T> list = (List<T>) c;

            for (int i = fromIndex; i < toIndex; i++) {
                result.add(func.apply(list.get(i)));
            }
        } else {
            int idx = 0;

            for (T e : c) {
                if (idx++ < fromIndex) {
                    continue;
                }

                result.add(func.apply(e));

                if (idx >= toIndex) {
                    break;
                }
            }
        }

        return result;
    }
207520
public <A extends Appendable> A appendTo(A appendable, Map<?, ? extends Collection<?>> map) throws IOException {
		return appendTo(appendable, map.entrySet());
	}
824110
public static <T> Iterable<T> notNull(Iterable<T> iterable) {
        return iterable == null ? Collections.EMPTY_LIST : iterable;
    }
512661
@Override
    public Iterator<T> iterator() {
        Iterator<T> transformed = Iterators.transform(rows.iterator(), row -> {
            T value = mapper.map(row);
            mapper.mappingComplete();
            return value;
        });
        mapper.mappingComplete();
        return transformed;
    }
469689
static final Map<String, Object> previousAndCurrentToDelta(List<Map<String, Object>> data) {
        if (data.size() == 2) {
            Map<String, Object> previous = data.get(0);
            Map<String, Object> current = data.get(1);
            return previousAndCurrentToDelta(previous, current);
        } else {
            throw new IllegalArgumentException("Must be list of 2 items");
        }

    }
283435
private static <T> Iterator<Iterator<? extends T>> iterators(
      Iterable<? extends Iterable<? extends T>> iterables) {
    return new TransformedIterator<Iterable<? extends T>, Iterator<? extends T>>(
        iterables.iterator()) {
      @Override
      Iterator<? extends T> transform(Iterable<? extends T> from) {
        return from.iterator();
      }
    };
  }
573060
public static <K, V> MutableList<V> toSortedList(
            Map<K, V> map,
            Comparator<? super V> comparator)
    {
        return Iterate.toSortedList(map.values(), comparator);
    }
749517
public static <T, R, E extends Exception> List<R> map(final T[] a, final int fromIndex, final int toIndex,
            final Try.Function<? super T, ? extends R, E> func) throws E {
        checkFromToIndex(fromIndex, toIndex, len(a));
        N.checkArgNotNull(func);

        if (N.isNullOrEmpty(a)) {
            return new ArrayList<>();
        }

        final List<R> result = new ArrayList<>(toIndex - fromIndex);

        for (int i = fromIndex; i < toIndex; i++) {
            result.add(func.apply(a[i]));
        }

        return result;
    }
934735
private void processItemIdIndexMapping(final Map<String, List<Integer>> map, final List<Integer> rowIndex,
			final TreeItemModel treeModel, final Set<String> expandedRows) {

		// Add current item
		String id = treeModel.getItemId(rowIndex);
		if (id == null) {
			return;
		}
		map.put(id, rowIndex);

		// Check row is expandable
		if (!treeModel.isExpandable(rowIndex)) {
			return;
		}

		// Check has children
		if (!treeModel.hasChildren(rowIndex)) {
			return;
		}

		// Add children if expanded ROWS null or contains ID
		boolean addChildren = expandedRows == null || expandedRows.contains(id);
		if (!addChildren) {
			return;
		}

		// Get actual child count
		int children = treeModel.getChildCount(rowIndex);
		if (children == 0) {
			// Could be there are no children even though hasChildren returned true
			return;
		}

		// Add children by processing each child row
		for (int i = 0; i < children; i++) {
			// Add next level
			List<Integer> nextRow = new ArrayList<>(rowIndex);
			nextRow.add(i);
			processItemIdIndexMapping(map, nextRow, treeModel, expandedRows);
		}
	}