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

org.wildfly.clustering.marshalling.protostream.reflect.TernaryMemberMarshaller Maven / Gradle / Ivy

/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package org.wildfly.clustering.marshalling.protostream.reflect;

import java.lang.reflect.Member;
import java.util.function.BiFunction;

/**
 * Generic marshaller based on three non-public members.
 * @param  the target type of this marshaller
 * @param  the reflection member type
 * @param  the first component member type
 * @param  the second component member type
 * @param  the third component member type
 * @author Paul Ferraro
 */
public class TernaryMemberMarshaller extends AbstractMemberMarshaller {

	private final Class member1Type;
	private final Class member2Type;
	private final Class member3Type;
	private final TriFunction factory;

	public TernaryMemberMarshaller(Class type, BiFunction accessor, BiFunction, Class, M> memberLocator, Class member1Type, Class member2Type, Class member3Type, TriFunction factory) {
		super(type, accessor, memberLocator, member1Type, member2Type, member3Type);
		this.member1Type = member1Type;
		this.member2Type = member2Type;
		this.member3Type = member3Type;
		this.factory = factory;
	}

	@Override
	public T apply(Object[] parameters) {
		return this.factory.apply(this.member1Type.cast(parameters[0]), this.member2Type.cast(parameters[1]), this.member3Type.cast(parameters[2]));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy