io.permazen.encoding.Concat4Encoding Maven / Gradle / Ivy
Show all versions of permazen-encoding Show documentation
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package io.permazen.encoding;
import com.google.common.base.Converter;
import com.google.common.base.Preconditions;
import io.permazen.tuple.Tuple4;
import java.util.function.Function;
/**
* Support superclass for non-null {@link Encoding}s of values that can be decomposed into four component values.
*
*
* Null values are not supported by this class and there is no default value.
*
* @param this encoding's value type
* @param first tuple value type
* @param second tuple value type
* @param third tuple value type
* @param fourth tuple value type
*/
public abstract class Concat4Encoding extends ConvertedEncoding> {
private static final long serialVersionUID = -7395218884659436175L;
/**
* Constructor.
*
* @param type Java type for this encoding's values
* @param encoding1 first value encoding
* @param encoding2 second value encoding
* @param encoding3 third value encoding
* @param encoding4 fourth value encoding
* @param splitter1 first value splitter
* @param splitter2 second value splitter
* @param splitter3 third value splitter
* @param splitter4 fourth value splitter
* @param joiner value joiner from tuple
* @throws IllegalArgumentException if any parameter is null
*/
protected Concat4Encoding(Class type,
Encoding encoding1,
Encoding encoding2,
Encoding encoding3,
Encoding encoding4,
Function super T, ? extends V1> splitter1,
Function super T, ? extends V2> splitter2,
Function super T, ? extends V3> splitter3,
Function super T, ? extends V4> splitter4,
Function super Tuple4, ? extends T> joiner) {
super(null, type, new Tuple4Encoding<>(encoding1, encoding2, encoding3, encoding4),
Converter.from(
value -> new Tuple4<>(splitter1.apply(value), splitter2.apply(value), splitter3.apply(value), splitter4.apply(value)),
joiner::apply));
Preconditions.checkArgument(splitter1 != null, "null splitter1");
Preconditions.checkArgument(splitter2 != null, "null splitter2");
Preconditions.checkArgument(splitter3 != null, "null splitter3");
Preconditions.checkArgument(splitter4 != null, "null splitter4");
Preconditions.checkArgument(joiner != null, "null joiner");
}
@SuppressWarnings("unchecked")
public Tuple4Encoding getTuple4Encoding() {
return (Tuple4Encoding)this.delegate;
}
}