/** * @param input collection to partition * @return a stream of elements for a triangular matrix of size {@code l.size()}, where l is the * list corresponding to the input collection. For input of length 3, the values are * (l.get(1),l.get(2)), (l.get(1),l.get(3)), (l.get(2),l.get(3)) */ public static <T> Stream<Pair<T>> pairs(Collection<T> input) { List<T> l; if (input instanceof List) { l = (List<T>) input; } else { l = new ArrayList<>(input); } int size = l.size(); List<Pair<T>> values = new ArrayList<>((size * size - size) / 2); for (int i = 0; i < size - 1; i++) { for (int j = i + 1; j < size; j++) { values.add(pair(l.get(i), l.get(j))); } } return values.stream(); }
/** * @param input collection to partition * @return a stream of elements for a triangular matrix of size {@code l.size()}, where l is the * list corresponding to the input collection. For input of length 3, the values are * (l.get(1),l.get(2)), (l.get(1),l.get(3)), (l.get(2),l.get(3)) */ public static <T> Stream<Pair<T>> pairs(Collection<T> input) { List<T> l; if (input instanceof List) { l = (List<T>) input; } else { l = new ArrayList<>(input); } int size = l.size(); List<Pair<T>> values = new ArrayList<>((size * size - size) / 2); for (int i = 0; i < size - 1; i++) { for (int j = i + 1; j < size; j++) { values.add(pair(l.get(i), l.get(j))); } } return values.stream(); }
/** * @param input collection to partition * @return a stream of coordinates for a symmetric matrix of size {@code l.size()}, where l is * the list corresponding to the input collection, excluding main diagonal. For input 3, * the values are (l.get(1),l.get(2)), (l.get(1),l.get(3)), (l.get(2),l.get(3)), * (l.get(2),l.get(1)),(l.get(3),l.get(1)), (l.get(3),l.get(2)) */ public static <T> Stream<Pair<T>> allPairs(Collection<T> input) { List<T> l; if (input instanceof List) { l = (List<T>) input; } else { l = new ArrayList<>(input); } int size = l.size(); List<Pair<T>> values = new ArrayList<>(size * size - size); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (i != j) { values.add(pair(l.get(i), l.get(j))); } } } return values.stream(); }
/** * @param input collection to partition * @return a stream of elements for a triangular matrix of size {@code l.size()}, where l is the * list corresponding to the input collection. For input of length 3, the values are * (l.get(1),l.get(2)), (l.get(1),l.get(3)), (l.get(2),l.get(3)) */ public static <T> Stream<Pair<T>> pairs(Collection<T> input) { List<T> l; if (input instanceof List) { l = (List<T>) input; } else { l = new ArrayList<>(input); } int size = l.size(); List<Pair<T>> values = new ArrayList<>((size * size - size) / 2); for (int i = 0; i < size - 1; i++) { for (int j = i + 1; j < size; j++) { values.add(pair(l.get(i), l.get(j))); } } return values.stream(); }
/** * @param input collection to partition * @return a stream of coordinates for a symmetric matrix of size {@code l.size()}, where l is * the list corresponding to the input collection, excluding main diagonal. For input 3, * the values are (l.get(1),l.get(2)), (l.get(1),l.get(3)), (l.get(2),l.get(3)), * (l.get(2),l.get(1)),(l.get(3),l.get(1)), (l.get(3),l.get(2)) */ public static <T> Stream<Pair<T>> allPairs(Collection<T> input) { List<T> l; if (input instanceof List) { l = (List<T>) input; } else { l = new ArrayList<>(input); } int size = l.size(); List<Pair<T>> values = new ArrayList<>(size * size - size); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (i != j) { values.add(pair(l.get(i), l.get(j))); } } } return values.stream(); }
/** * @param input collection to partition * @return a stream of coordinates for a symmetric matrix of size {@code l.size()}, where l is * the list corresponding to the input collection, excluding main diagonal. For input 3, * the values are (l.get(1),l.get(2)), (l.get(1),l.get(3)), (l.get(2),l.get(3)), * (l.get(2),l.get(1)),(l.get(3),l.get(1)), (l.get(3),l.get(2)) */ public static <T> Stream<Pair<T>> allPairs(Collection<T> input) { List<T> l; if (input instanceof List) { l = (List<T>) input; } else { l = new ArrayList<>(input); } int size = l.size(); List<Pair<T>> values = new ArrayList<>(size * size - size); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (i != j) { values.add(pair(l.get(i), l.get(j))); } } } return values.stream(); }