reactor.util.function.Tuples Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redisson-all Show documentation
Show all versions of redisson-all Show documentation
Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava3/Reactive API. Client side caching. Over 50 Redis based Java objects and services: JCache API, Apache Tomcat, Hibernate, Spring, Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Scheduler, RPC
/*
* Copyright (c) 2016-2021 VMware Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package reactor.util.function;
import java.util.Collection;
import java.util.function.Function;
/**
* A {@literal Tuples} is an immutable {@link Collection} of objects, each of which can be of an arbitrary type.
*
* @author Jon Brisbin
* @author Stephane Maldini
*/
@SuppressWarnings({"rawtypes"})
public abstract class Tuples implements Function {
/**
* Create a {@link Tuple2} with the given array if it is small
* enough to fit inside a {@link Tuple2} to {@link Tuple8}.
*
* @param list the content of the Tuple (size 1 to 8)
* @return The new {@link Tuple2}.
* @throws IllegalArgumentException if the array is not of length 1-8
*/
public static Tuple2 fromArray(Object[] list) {
//noinspection ConstantConditions
if (list == null || list.length < 2) {
throw new IllegalArgumentException("null or too small array, need between 2 and 8 values");
}
switch (list.length){
case 2:
return of(list[0], list[1]);
case 3:
return of(list[0], list[1], list[2]);
case 4:
return of(list[0], list[1], list[2], list[3]);
case 5:
return of(list[0], list[1], list[2], list[3], list[4]);
case 6:
return of(list[0], list[1], list[2], list[3], list[4], list[5]);
case 7:
return of(list[0], list[1], list[2], list[3], list[4], list[5], list[6]);
case 8:
return of(list[0], list[1], list[2], list[3], list[4], list[5], list[6], list[7]);
}
throw new IllegalArgumentException("too many arguments ("+ list.length + "), need between 2 and 8 values");
}
/**
* Create a {@link Tuple2} with the given objects.
*
* @param t1 The first value in the tuple. Not null.
* @param t2 The second value in the tuple. Not null.
* @param The type of the first value.
* @param The type of the second value.
* @return The new {@link Tuple2}.
*/
public static Tuple2 of(T1 t1, T2 t2) {
return new Tuple2<>(t1, t2);
}
/**
* Create a {@link Tuple3} with the given objects.
*
* @param t1 The first value in the tuple. Not null.
* @param t2 The second value in the tuple. Not null.
* @param t3 The third value in the tuple. Not null.
* @param The type of the first value.
* @param The type of the second value.
* @param The type of the third value.
* @return The new {@link Tuple3}.
*/
public static Tuple3 of(T1 t1, T2 t2, T3 t3) {
return new Tuple3<>(t1, t2, t3);
}
/**
* Create a {@link Tuple4} with the given objects.
*
* @param t1 The first value in the tuple. Not null.
* @param t2 The second value in the tuple. Not null.
* @param t3 The third value in the tuple. Not null.
* @param t4 The fourth value in the tuple. Not null.
* @param The type of the first value.
* @param The type of the second value.
* @param The type of the third value.
* @param The type of the fourth value.
* @return The new {@link Tuple4}.
*/
public static Tuple4 of(T1 t1, T2 t2, T3 t3, T4 t4) {
return new Tuple4<>(t1, t2, t3, t4);
}
/**
* Create a {@link Tuple5} with the given objects.
*
* @param t1 The first value in the tuple. Not null.
* @param t2 The second value in the tuple. Not null.
* @param t3 The third value in the tuple. Not null.
* @param t4 The fourth value in the tuple. Not null.
* @param t5 The fifth value in the tuple. Not null.
* @param The type of the first value.
* @param The type of the second value.
* @param The type of the third value.
* @param The type of the fourth value.
* @param The type of the fifth value.
* @return The new {@link Tuple5}.
*/
public static Tuple5 of(
T1 t1,
T2 t2,
T3 t3,
T4 t4,
T5 t5) {
return new Tuple5<>(t1, t2, t3, t4, t5);
}
/**
* Create a {@link Tuple6} with the given objects.
*
* @param t1 The first value in the tuple. Not null.
* @param t2 The second value in the tuple. Not null.
* @param t3 The third value in the tuple. Not null.
* @param t4 The fourth value in the tuple. Not null.
* @param t5 The fifth value in the tuple. Not null.
* @param t6 The sixth value in the tuple. Not null.
* @param The type of the first value.
* @param The type of the second value.
* @param The type of the third value.
* @param The type of the fourth value.
* @param The type of the fifth value.
* @param The type of the sixth value.
* @return The new {@link Tuple6}.
*/
public static Tuple6 of(
T1 t1,
T2 t2,
T3 t3,
T4 t4,
T5 t5,
T6 t6) {
return new Tuple6<>(t1, t2, t3, t4, t5, t6);
}
/**
* Create a {@link Tuple7} with the given objects.
*
* @param t1 The first value in the tuple. Not null.
* @param t2 The second value in the tuple. Not null.
* @param t3 The third value in the tuple. Not null.
* @param t4 The fourth value in the tuple. Not null.
* @param t5 The fifth value in the tuple. Not null.
* @param t6 The sixth value in the tuple. Not null.
* @param t7 The seventh value in the tuple. Not null.
* @param The type of the first value.
* @param The type of the second value.
* @param The type of the third value.
* @param The type of the fourth value.
* @param The type of the fifth value.
* @param The type of the sixth value.
* @param The type of the seventh value.
* @return The new {@link Tuple7}.
*/
public static Tuple7 of(
T1 t1,
T2 t2,
T3 t3,
T4 t4,
T5 t5,
T6 t6,
T7 t7) {
return new Tuple7<>(t1, t2, t3, t4, t5, t6, t7);
}
/**
* Create a {@link Tuple8} with the given objects.
*
* @param t1 The first value in the tuple. Not Null.
* @param t2 The second value in the tuple.Not Null.
* @param t3 The third value in the tuple. Not Null.
* @param t4 The fourth value in the tuple. Not Null.
* @param t5 The fifth value in the tuple. Not Null.
* @param t6 The sixth value in the tuple. Not Null.
* @param t7 The seventh value in the tuple. Not Null.
* @param t8 The eighth value in the tuple. Not Null.
* @param The type of the first value.
* @param The type of the second value.
* @param The type of the third value.
* @param The type of the fourth value.
* @param The type of the fifth value.
* @param The type of the sixth value.
* @param The type of the seventh value.
* @param The type of the eighth value.
* @return The new {@link Tuple8}.
*/
public static Tuple8 of(
T1 t1,
T2 t2,
T3 t3,
T4 t4,
T5 t5,
T6 t6,
T7 t7,
T8 t8) {
return new Tuple8<>(t1, t2, t3, t4, t5, t6, t7, t8);
}
/**
* A converting function from Object array to {@link Tuples}
*
* @return The unchecked conversion function to {@link Tuples}.
*/
@SuppressWarnings("unchecked")
public static Function
© 2015 - 2024 Weber Informatics LLC | Privacy Policy