
com.speedment.common.tuple.internal.nullable.mapper.Tuple2OfNullablesMapperImpl Maven / Gradle / Ivy
Show all versions of tuple Show documentation
/**
*
* Copyright (c) 2006-2018, 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.Tuple2;
import com.speedment.common.tuple.TupleMapper;
import com.speedment.common.tuple.TuplesOfNullables;
import com.speedment.common.tuple.nullable.Tuple2OfNullables;
import java.util.function.Function;
import static java.util.Objects.requireNonNull;
/**
* An implementation class of a {@link TupleMapper } of degree 2
*
* Generated by com.speedment.sources.pattern.tuple.TupleMapperImplPattern
*
* @param Type of the original object for the mapper to use when creating a
* {@code Tuple }
* @param type of element 0
* @param type of element 1
*
* @author Per Minborg
*/
public final class Tuple2OfNullablesMapperImpl implements TupleMapper> {
private final Function m0;
private final Function m1;
/**
* Constructs a {@link TupleMapper } that can create {@link Tuple2 }.
*
* @param m0 mapper to apply for element 0
* @param m1 mapper to apply for element 1
*/
public Tuple2OfNullablesMapperImpl(Function m0, Function m1) {
this.m0 = requireNonNull(m0);
this.m1 = requireNonNull(m1);
}
@Override
public Tuple2OfNullables apply(T t) {
return TuplesOfNullables.ofNullables(
m0.apply(t),
m1.apply(t)
);
}
@Override
public int degree() {
return 2;
}
@Override
public Function get(int index) {
switch(index){
case 0 : return get0();
case 1 : return get1();
default : throw new IndexOutOfBoundsException();
}
}
public Function get0() {
return m0;
}
public Function get1() {
return m1;
}
}