public static IntList toIntList(IntIterator iterator) { final IntList integers = new IntArrayList(); while (iterator.hasNext()) { integers.add(iterator.nextInt()); } return IntLists.unmodifiable(integers); }
static IntList asIntList(final int... values) { return IntLists.unmodifiable(new IntArrayList(values)); }
/** * Finds all indices of item in the specified list. * @param list The list. * @param item The item. * @return A list of indices. */ static <T> IntList indices(List<T> list, T item) { final IntList indices = new IntArrayList(); for (int i = 0; i < list.size(); i++) { if (list.get(i).equals(item)) { indices.add(i); } } return IntLists.unmodifiable(indices); }
/** * Removes all items from list and returns the indices of the removed items. * @param list The list to remove items from. * @param item The item to remove from the list. * @return The indices of the removed items, or an empty list if the item was * not found in list. */ static <T> IntList removeAll(List<T> list, T item) { final Iterator<T> it = list.iterator(); final IntArrayList indices = new IntArrayList(); int i = 0; while (it.hasNext()) { if (it.next().equals(item)) { it.remove(); indices.add(i); } i++; } return IntLists.unmodifiable(indices); }
@Override public IntList next() { if (!hasNext()) { throw new NoSuchElementException(); } if (index > 0) { for (int i = 0; i < insertionPositions.length; i++) { if (insertionPositions[i] == originalListSize) { insertionPositions[i - 1]++; for (int j = i; j < insertionPositions.length; j++) { insertionPositions[j] = insertionPositions[i - 1]; } break; } else if (i == insertionPositions.length - 1) { insertionPositions[i]++; } } } index++; return IntLists.unmodifiable(new IntArrayList(insertionPositions)); }
static IntList indices(GlobalStateObject state) { final IntList indices = new IntArrayList(); for (final VehicleStateObject vso : state.getVehicles()) { indices.add(vso.getDestination().isPresent() ? 1 : 0); } return IntLists.unmodifiable(indices); } }
public static IntList toIntList(IntIterator iterator) { final IntList integers = new IntArrayList(); while (iterator.hasNext()) { integers.add(iterator.nextInt()); } return IntLists.unmodifiable(integers); }
public static IntList toIntList(IntIterator iterator) { final IntList integers = new IntArrayList(); while (iterator.hasNext()) { integers.add(iterator.nextInt()); } return IntLists.unmodifiable(integers); }
static <C, T> Schedule<C, T> create(C context, ImmutableList<ImmutableList<T>> routes, IntList startIndices, RouteEvaluator<C, T> routeEvaluator) { final DoubleList costs = new DoubleArrayList(routes.size()); double sumCost = 0; for (int i = 0; i < routes.size(); i++) { final double cost = routeEvaluator.computeCost(context, i, routes.get(i)); costs.add(cost); sumCost += cost; } return new Schedule<C, T>( context, routes, IntLists.unmodifiable(new IntArrayList(startIndices)), DoubleLists.unmodifiable(costs), sumCost, routeEvaluator); }
static <C, T> Schedule<C, T> create(C context, ImmutableList<ImmutableList<T>> routes, IntList startIndices, DoubleList objectiveValues, double globalObjectiveValue, RouteEvaluator<C, T> routeEvaluator) { return new Schedule<C, T>( context, routes, IntLists.unmodifiable(new IntArrayList(startIndices)), DoubleLists.unmodifiable(new DoubleArrayList(objectiveValues)), globalObjectiveValue, routeEvaluator); }