All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.activej.common.tuple.TupleConstructors Maven / Gradle / Ivy

There is a newer version: 4.3-r8
Show newest version
/*
 * Copyright (C) 2020 ActiveJ LLC.
 *
 * 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 io.activej.common.tuple;

import java.util.function.Consumer;
import java.util.function.Supplier;

public final class TupleConstructors {

	public static  TupleConstructor1 toPojo(Supplier pojoSupplier, Consumer setter1) {
		return value1 -> {
			R pojo = pojoSupplier.get();
			setter1.accept(value1);
			return pojo;
		};
	}

	public static  TupleConstructor2 toPojo(Supplier pojoSupplier,
			Consumer setter1,
			Consumer setter2) {
		return (value1, value2) -> {
			R pojo = pojoSupplier.get();
			setter1.accept(value1);
			setter2.accept(value2);
			return pojo;
		};
	}

	public static  TupleConstructor3 toPojo(Supplier pojoSupplier,
			Consumer setter1,
			Consumer setter2,
			Consumer setter3) {
		return (value1, value2, value3) -> {
			R pojo = pojoSupplier.get();
			setter1.accept(value1);
			setter2.accept(value2);
			setter3.accept(value3);
			return pojo;
		};
	}

	public static  TupleConstructor4 toPojo(Supplier pojoSupplier,
			Consumer setter1,
			Consumer setter2,
			Consumer setter3,
			Consumer setter4) {
		return (value1, value2, value3, value4) -> {
			R pojo = pojoSupplier.get();
			setter1.accept(value1);
			setter2.accept(value2);
			setter3.accept(value3);
			setter4.accept(value4);
			return pojo;
		};
	}

	public static  TupleConstructor5 toPojo(Supplier pojoSupplier,
			Consumer setter1,
			Consumer setter2,
			Consumer setter3,
			Consumer setter4,
			Consumer setter5) {
		return (value1, value2, value3, value4, value5) -> {
			R pojo = pojoSupplier.get();
			setter1.accept(value1);
			setter2.accept(value2);
			setter3.accept(value3);
			setter4.accept(value4);
			setter5.accept(value5);
			return pojo;
		};
	}

	public static  TupleConstructor6 toPojo(Supplier pojoSupplier,
			Consumer setter1,
			Consumer setter2,
			Consumer setter3,
			Consumer setter4,
			Consumer setter5,
			Consumer setter6) {
		return (value1, value2, value3, value4, value5, value6) -> {
			R pojo = pojoSupplier.get();
			setter1.accept(value1);
			setter2.accept(value2);
			setter3.accept(value3);
			setter4.accept(value4);
			setter5.accept(value5);
			setter6.accept(value6);
			return pojo;
		};
	}

	public static  TupleConstructor1 toPojo(R pojo, Consumer setter1) {
		return value1 -> {
			setter1.accept(value1);
			return pojo;
		};
	}

	public static  TupleConstructor2 toPojo(R pojo,
			Consumer setter1,
			Consumer setter2) {
		return (value1, value2) -> {
			setter1.accept(value1);
			setter2.accept(value2);
			return pojo;
		};
	}

	public static  TupleConstructor3 toPojo(R pojo,
			Consumer setter1,
			Consumer setter2,
			Consumer setter3) {
		return (value1, value2, value3) -> {
			setter1.accept(value1);
			setter2.accept(value2);
			setter3.accept(value3);
			return pojo;
		};
	}

	public static  TupleConstructor4 toPojo(R pojo,
			Consumer setter1,
			Consumer setter2,
			Consumer setter3,
			Consumer setter4) {
		return (value1, value2, value3, value4) -> {
			setter1.accept(value1);
			setter2.accept(value2);
			setter3.accept(value3);
			setter4.accept(value4);
			return pojo;
		};
	}

	public static  TupleConstructor5 toPojo(R pojo,
			Consumer setter1,
			Consumer setter2,
			Consumer setter3,
			Consumer setter4,
			Consumer setter5) {
		return (value1, value2, value3, value4, value5) -> {
			setter1.accept(value1);
			setter2.accept(value2);
			setter3.accept(value3);
			setter4.accept(value4);
			setter5.accept(value5);
			return pojo;
		};
	}

	public static  TupleConstructor6 toPojo(R pojo,
			Consumer setter1,
			Consumer setter2,
			Consumer setter3,
			Consumer setter4,
			Consumer setter5,
			Consumer setter6) {
		return (value1, value2, value3, value4, value5, value6) -> {
			setter1.accept(value1);
			setter2.accept(value2);
			setter3.accept(value3);
			setter4.accept(value4);
			setter5.accept(value5);
			setter6.accept(value6);
			return pojo;
		};
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy