/** * Return a List that is transformed from elements of the input type to elements of the output type by a transformer function. * * @param <T> the input type * @param <R> the out type * @param iterator to iterate over the contents * @param transformer the function that performs the transformation * @return an unmodifiable List of the transformed type */ public static <T, R> List<R> transform(@Nonnull final Iterator<? extends T> iterator, @Nonnull final Function<T, R> transformer) { return toList(transformIterator(iterator, transformer)); }
/** * Returns an iterator for this map * @return an iterator */ public Iterator<Entry> iterator() { return CollectionUtil.transformIterator(map.entrySet().iterator(), new Function<Map.Entry<Long, List<Long>>, Entry>() { public Entry get(final java.util.Map.Entry<Long, List<Long>> entry) { return new Entry(entry.getKey(), entry.getValue()); } }); }
/** * Return a {@link Set} that is transformed from elements of the input type * to elements of the output type by a transformer function. * <p> * Note, this performs a copy and applies the transform to all elements. * * @param <T> the input type * @param <R> the output type * @param iterable the contents * @param transformer the function that performs the transformation * @return an unmodifiable Set of the transformed type */ public static <T, R> Set<R> transformSet(@Nonnull final Iterable<T> iterable, @Nonnull final Function<T, R> transformer) { return toSet(transformIterator(iterable.iterator(), transformer)); }
/** * Use to get the percentage of a particular row. * <br/> * If the percentage calculated is not a whole number it is rounded down. An exception is the last row * for which the percentage is calculated as a remainder to 100 (percent). * * @param row row to get the width percentage for * @return percentage for the given row */ public int getPercentage(PercentageGraphRow row) { final RowPercentageCalculator calculator = new RowPercentageCalculator(getTotal()); // if last element if (lastRow.equals(row)) { return calculator.getLastPercentage(CollectionUtil.transformIterator(rows.iterator(), new Function<PercentageGraphRow, Long>() { public Long get(final PercentageGraphRow input) { return input.getNumber(); } })); } else { return calculator.getPercentage(row.getNumber()); } }