/**
*
* Copyright (c) 2006-2017, Speedment, Inc. 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:
*
* 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 com.speedment.common.tuple.internal.nullable.mapper;
import com.speedment.common.tuple.Tuple4;
import com.speedment.common.tuple.TupleMapper;
import com.speedment.common.tuple.TuplesOfNullables;
import com.speedment.common.tuple.nullable.Tuple4OfNullables;
import java.util.function.Function;
import static java.util.Objects.requireNonNull;
/**
* An implementation class of a {@link TupleMapper } of degree 4
*
* @param <T> Type of the original object for the mapper to use when creating a
* {@code Tuple }
* @param <T0> type of element 0
* @param <T1> type of element 1
* @param <T2> type of element 2
* @param <T3> type of element 3
*
* @author Per Minborg
*/
public final class Tuple4OfNullablesMapperImpl<T, T0, T1, T2, T3> implements TupleMapper<T, Tuple4OfNullables<T0, T1, T2, T3>> {
private final Function<T, T0> m0;
private final Function<T, T1> m1;
private final Function<T, T2> m2;
private final Function<T, T3> m3;
/**
* Constructs a {@link TupleMapper } that can create {@link Tuple4 }.
*
* @param m0 mapper to apply for element 0
* @param m1 mapper to apply for element 1
* @param m2 mapper to apply for element 2
* @param m3 mapper to apply for element 3
*/
public Tuple4OfNullablesMapperImpl(
Function<T, T0> m0,
Function<T, T1> m1,
Function<T, T2> m2,
Function<T, T3> m3) {
this.m0 = requireNonNull(m0);
this.m1 = requireNonNull(m1);
this.m2 = requireNonNull(m2);
this.m3 = requireNonNull(m3);
}
@Override
public Tuple4OfNullables<T0, T1, T2, T3> apply(T t) {
return TuplesOfNullables.ofNullables(
m0.apply(t),
m1.apply(t),
m2.apply(t),
m3.apply(t)
);
}
@Override
public int degree() {
return 4;
}
@Override
public Function<T, ?> get(int index) {
switch(index){
case 0 : return get0();
case 1 : return get1();
case 2 : return get2();
case 3 : return get3();
default : throw new IndexOutOfBoundsException();
}
}
public Function<T, T0> get0() {
return m0;
}
public Function<T, T1> get1() {
return m1;
}
public Function<T, T2> get2() {
return m2;
}
public Function<T, T3> get3() {
return m3;
}
}