mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-14 17:58:01 +00:00
Guava migration - Replace select usages of Iterables.transform
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package forge.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
@@ -59,33 +58,10 @@ public class Iterables {
|
||||
}
|
||||
|
||||
public static <F, T> Iterable<T> transform(final Iterable<F> iterable, final Function<? super F, T> function) {
|
||||
//TODO: Collection input variant. Some usages use Lists.newArrayList on output which could be made part of the stream.
|
||||
//Should probably also be ? extends T in the function type
|
||||
return () -> StreamSupport.stream(iterable.spliterator(), false).map(function).iterator();
|
||||
}
|
||||
|
||||
//TODO: Inline everything below.
|
||||
|
||||
|
||||
public static int size(Collection<?> collection) {
|
||||
return collection.size();
|
||||
}
|
||||
|
||||
public static boolean contains(Collection<?> collection, Object element) {
|
||||
return collection.contains(element);
|
||||
}
|
||||
|
||||
public static <T> T getFirst(List<? extends T> iterable, T defaultValue) {
|
||||
return iterable.isEmpty() ? defaultValue : iterable.get(0);
|
||||
}
|
||||
|
||||
public static <T> T getLast(List<T> iterable) {
|
||||
return iterable.get(iterable.size() - 1);
|
||||
}
|
||||
public static <T> T getLast(List<? extends T> iterable, T defaultValue) {
|
||||
return iterable.isEmpty() ? defaultValue : iterable.get(iterable.size() - 1);
|
||||
}
|
||||
|
||||
//TODO: Restore everything below
|
||||
public static <T> Iterable<T> unmodifiableIterable(final Iterable<? extends T> iterable) {
|
||||
return com.google.common.collect.Iterables.unmodifiableIterable(iterable);
|
||||
|
||||
@@ -35,6 +35,7 @@ import forge.util.storage.IStorage;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* This is a helper class for unlocking new sets during a format-limited
|
||||
@@ -136,14 +137,17 @@ public class QuestUtilUnlockSets {
|
||||
throw new RuntimeException("BUG? Could not find unlockable sets even though we should.");
|
||||
}
|
||||
List<CardEdition> options = new ArrayList<>();
|
||||
CardEdition.Collection editions = FModel.getMagicDb().getEditions();
|
||||
|
||||
// Sort current sets by date
|
||||
List<CardEdition> allowedSets = Lists.newArrayList(Iterables.transform(qData.getFormat().getAllowedSetCodes(), FModel.getMagicDb().getEditions()::get));
|
||||
Collections.sort(allowedSets);
|
||||
List<CardEdition> allowedSets = qData.getFormat().getAllowedSetCodes().stream()
|
||||
.map(editions::get)
|
||||
.sorted().collect(Collectors.toList());
|
||||
|
||||
// Sort unlockable sets by date
|
||||
List<CardEdition> excludedSets = Lists.newArrayList(Iterables.transform(qData.getFormat().getLockedSets(), FModel.getMagicDb().getEditions()::get));
|
||||
Collections.sort(excludedSets);
|
||||
List<CardEdition> excludedSets = qData.getFormat().getLockedSets().stream()
|
||||
.map(editions::get)
|
||||
.sorted().collect(Collectors.toList());
|
||||
|
||||
// get a number of sets between an excluded and any included set
|
||||
List<ImmutablePair<CardEdition, Long>> excludedWithDistances = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user