/** * Creates a new tuple without any values. * * @param <F> the type for the first value * @param <S> the type for the second value * @return the newly created tuple */ @Nonnull public static <F extends Comparable<F>, S> ComparableTuple<F, S> createTuple() { return new ComparableTuple<>(null, null); }
/** * Adds the given entity with the default priority. * * @param entity the entity added to the collector. * @see #DEFAULT_PRIORITY */ public void addDefault(T entity) { data.add(new ComparableTuple<Integer, T>(DEFAULT_PRIORITY, entity)); }
/** * Adds the given entity with the given priority. * * @param priority the priority to use for this element. * @param entity the entity added to the collector. */ public void add(int priority, T entity) { data.add(new ComparableTuple<Integer, T>(priority, entity)); }
/** * Creates a new tuple by only specifying the first value of the tuple. * <p> * The second value will remain <tt>null</tt>. * * @param first defines the first value of the tuple * @param <F> the type for the first value * @param <S> the type for the second value * @return the newly created tuple */ @Nonnull public static <F extends Comparable<F>, S> ComparableTuple<F, S> create(@Nullable F first) { return new ComparableTuple<>(first, null); }
/** * Creates a new tuple with the given values. * * @param first defines the first value of the tuple * @param second defines the second value of the tuple * @param <F> the type for the first value * @param <S> the type for the second value * @return the newly created tuple */ @Nonnull public static <F extends Comparable<F>, S> ComparableTuple<F, S> create(@Nullable F first, @Nullable S second) { return new ComparableTuple<>(first, second); }
/** * Converts a map into a list of tuples. * * @param map the map to be converted * @param <K> the key type of the map and therefore the type of the first component of the tuples * @param <V> the value type of the map and therefore the type of the second component of the tuples * @return a list of tuples, containing one tuple per map entry where the first component is the key, * and the second component is the value of the map entry. */ public static <K extends Comparable<K>, V> List<ComparableTuple<K, V>> fromComparableMap(@Nonnull Map<K, V> map) { List<ComparableTuple<K, V>> result = new ArrayList<>(map.size()); for (Map.Entry<K, V> e : map.entrySet()) { result.add(new ComparableTuple<K, V>(e.getKey(), e.getValue())); } return result; }