
org.cloudfoundry.util.tuple.TupleUtils Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2013-2021 the original author or authors.
*
* 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
*
* http://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 org.cloudfoundry.util.tuple;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuple3;
import reactor.util.function.Tuple4;
import reactor.util.function.Tuple5;
import reactor.util.function.Tuple6;
import reactor.util.function.Tuple7;
import reactor.util.function.Tuple8;
public final class TupleUtils {
private TupleUtils() {}
/**
* Returns a {@link Consumer} of {@link Tuple2} that wraps a consumer of the component values of the tuple
*
* @param consumer the component value consumer
* @param the type of the first value
* @param the type of the second value
* @return the wrapper consumer
*/
public static Consumer> consumer(Consumer2 consumer) {
return tuple -> consumer.accept(tuple.getT1(), tuple.getT2());
}
/**
* Returns a {@link Consumer} of {@link Tuple3} that wraps a consumer of the component values of the tuple
*
* @param consumer the component value consumer
* @param the type of the first value
* @param the type of the second value
* @param the type of the third value
* @return the wrapper consumer
*/
public static Consumer> consumer(
Consumer3 consumer) {
return tuple -> consumer.accept(tuple.getT1(), tuple.getT2(), tuple.getT3());
}
/**
* Returns a {@link Consumer} of {@link Tuple4} that wraps a consumer of the component values of the tuple
*
* @param consumer the component value consumer
* @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 wrapper consumer
*/
public static Consumer> consumer(
Consumer4 consumer) {
return tuple -> consumer.accept(tuple.getT1(), tuple.getT2(), tuple.getT3(), tuple.getT4());
}
/**
* Returns a {@link Consumer} of {@link Tuple5} that wraps a consumer of the component values of the tuple
*
* @param consumer the component value consumer
* @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 wrapper consumer
*/
public static Consumer> consumer(
Consumer5 consumer) {
return tuple ->
consumer.accept(
tuple.getT1(), tuple.getT2(), tuple.getT3(), tuple.getT4(), tuple.getT5());
}
/**
* Returns a {@link Consumer} of {@link Tuple6} that wraps a consumer of the component values of the tuple
*
* @param consumer the component value consumer
* @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 wrapper consumer
*/
public static Consumer> consumer(
Consumer6 consumer) {
return tuple ->
consumer.accept(
tuple.getT1(),
tuple.getT2(),
tuple.getT3(),
tuple.getT4(),
tuple.getT5(),
tuple.getT6());
}
/**
* Returns a {@link Consumer} of {@link Tuple7} that wraps a consumer of the component values of the tuple
*
* @param consumer the component value consumer
* @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 wrapper consumer
*/
public static
Consumer> consumer(
Consumer7 consumer) {
return tuple ->
consumer.accept(
tuple.getT1(),
tuple.getT2(),
tuple.getT3(),
tuple.getT4(),
tuple.getT5(),
tuple.getT6(),
tuple.getT7());
}
/**
* Returns a {@link Consumer} of {@link Tuple8} that wraps a consumer of the component values of the tuple
*
* @param consumer the component value consumer
* @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 wrapper consumer
*/
public static
Consumer> consumer(
Consumer8 consumer) {
return tuple ->
consumer.accept(
tuple.getT1(),
tuple.getT2(),
tuple.getT3(),
tuple.getT4(),
tuple.getT5(),
tuple.getT6(),
tuple.getT7(),
tuple.getT8());
}
/**
* Returns a {@link Function} of {@link Tuple2} that wraps a function of the component values of the tuple
*
* @param function the component value function
* @param the type of the first value
* @param the type of the second value
* @param the type of the result of the function
* @return the wrapper function
*/
public static Function, R> function(Function2 function) {
return tuple -> function.apply(tuple.getT1(), tuple.getT2());
}
/**
* Returns a {@link Function} of {@link Tuple3} that wraps a function of the component values of the tuple
*
* @param function the component value function
* @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 result of the function
* @return the wrapper function
*/
public static Function, R> function(
Function3 function) {
return tuple -> function.apply(tuple.getT1(), tuple.getT2(), tuple.getT3());
}
/**
* Returns a {@link Function} of {@link Tuple4} that wraps a function of the component values of the tuple
*
* @param function the component value function
* @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 result of the function
* @return the wrapper function
*/
public static Function, R> function(
Function4 function) {
return tuple -> function.apply(tuple.getT1(), tuple.getT2(), tuple.getT3(), tuple.getT4());
}
/**
* Returns a {@link Function} of {@link Tuple5} that wraps a function of the component values of the tuple
*
* @param function the component value function
* @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 result of the function
* @return the wrapper function
*/
public static Function, R> function(
Function5 function) {
return tuple ->
function.apply(
tuple.getT1(), tuple.getT2(), tuple.getT3(), tuple.getT4(), tuple.getT5());
}
/**
* Returns a {@link Function} of {@link Tuple6} that wraps a function of the component values of the tuple
*
* @param function the component value function
* @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 result of the function
* @return the wrapper function
*/
public static Function, R> function(
Function6 function) {
return tuple ->
function.apply(
tuple.getT1(),
tuple.getT2(),
tuple.getT3(),
tuple.getT4(),
tuple.getT5(),
tuple.getT6());
}
/**
* Returns a {@link Function} of {@link Tuple7} that wraps a function of the component values of the tuple
*
* @param function the component value function
* @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 result of the function
* @return the wrapper function
*/
public static
Function, R> function(
Function7 function) {
return tuple ->
function.apply(
tuple.getT1(),
tuple.getT2(),
tuple.getT3(),
tuple.getT4(),
tuple.getT5(),
tuple.getT6(),
tuple.getT7());
}
/**
* Returns a {@link Function} of {@link Tuple8} that wraps a function of the component values of the tuple
*
* @param function the component value function
* @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
* @param the type of the result of the function
* @return the wrapper function
*/
public static
Function, R> function(
Function8 function) {
return tuple ->
function.apply(
tuple.getT1(),
tuple.getT2(),
tuple.getT3(),
tuple.getT4(),
tuple.getT5(),
tuple.getT6(),
tuple.getT7(),
tuple.getT8());
}
/**
* Returns a {@link Predicate} of {@link Tuple2} that wraps a predicate of the component values of the tuple
*
* @param predicate the component value predicate
* @param the type of the first value
* @param the type of the second value
* @return the wrapper predicate
*/
public static Predicate> predicate(Predicate2 predicate) {
return tuple -> predicate.test(tuple.getT1(), tuple.getT2());
}
/**
* Returns a {@link Predicate} of {@link Tuple3} that wraps a predicate of the component values of the tuple
*
* @param predicate the component value predicate
* @param the type of the first value
* @param the type of the second value
* @param the type of the third value
* @return the wrapper predicate
*/
public static Predicate> predicate(
Predicate3 predicate) {
return tuple -> predicate.test(tuple.getT1(), tuple.getT2(), tuple.getT3());
}
/**
* Returns a {@link Predicate} of {@link Tuple4} that wraps a predicate of the component values of the tuple
*
* @param predicate the component value predicate
* @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 wrapper predicate
*/
public static Predicate> predicate(
Predicate4 predicate) {
return tuple -> predicate.test(tuple.getT1(), tuple.getT2(), tuple.getT3(), tuple.getT4());
}
/**
* Returns a {@link Predicate} of {@link Tuple5} that wraps a predicate of the component values of the tuple
*
* @param predicate the component value predicate
* @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 wrapper predicate
*/
public static Predicate> predicate(
Predicate5 predicate) {
return tuple ->
predicate.test(
tuple.getT1(), tuple.getT2(), tuple.getT3(), tuple.getT4(), tuple.getT5());
}
/**
* Returns a {@link Predicate} of {@link Tuple6} that wraps a predicate of the component values of the tuple
*
* @param predicate the component value predicate
* @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 wrapper predicate
*/
public static Predicate> predicate(
Predicate6 predicate) {
return tuple ->
predicate.test(
tuple.getT1(),
tuple.getT2(),
tuple.getT3(),
tuple.getT4(),
tuple.getT5(),
tuple.getT6());
}
/**
* Returns a {@link Predicate} of {@link Tuple7} that wraps a predicate of the component values of the tuple
*
* @param predicate the component value predicate
* @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 wrapper predicate
*/
public static
Predicate> predicate(
Predicate7 predicate) {
return tuple ->
predicate.test(
tuple.getT1(),
tuple.getT2(),
tuple.getT3(),
tuple.getT4(),
tuple.getT5(),
tuple.getT6(),
tuple.getT7());
}
/**
* Returns a {@link Predicate} of {@link Tuple8} that wraps a predicate of the component values of the tuple
*
* @param predicate the component value predicate
* @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 wrapper predicate
*/
public static
Predicate> predicate(
Predicate8 predicate) {
return tuple ->
predicate.test(
tuple.getT1(),
tuple.getT2(),
tuple.getT3(),
tuple.getT4(),
tuple.getT5(),
tuple.getT6(),
tuple.getT7(),
tuple.getT8());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy