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

io.permazen.encoding.Tuple2Encoding Maven / Gradle / Ivy

The newest version!

/*
 * Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
 */

package io.permazen.encoding;

import com.google.common.reflect.TypeParameter;
import com.google.common.reflect.TypeToken;

import io.permazen.tuple.Tuple2;

/**
 * Non-null {@link Encoding} for a {@link Tuple2} created by concatenating the component {@link Encoding}s.
 *
 * 

* Null values are not supported by this class and there is no default value. */ public class Tuple2Encoding extends TupleEncoding> { private static final long serialVersionUID = 8336238765491523439L; /** * Constructor. * * @param value1Encoding component value encoding * @param value2Encoding component value encoding * @throws IllegalArgumentException if any component value encoding is null */ @SuppressWarnings("serial") public Tuple2Encoding(Encoding value1Encoding, Encoding value2Encoding) { super(new TypeToken>() { } .where(new TypeParameter() { }, value1Encoding.getTypeToken().wrap()) .where(new TypeParameter() { }, value2Encoding.getTypeToken().wrap()), value1Encoding, value2Encoding); } @SuppressWarnings("unchecked") public Encoding getEncoding1() { return (Encoding)this.encodings.get(0); } @SuppressWarnings("unchecked") public Encoding getEncoding2() { return (Encoding)this.encodings.get(1); } @Override @SuppressWarnings("unchecked") protected Tuple2 createTuple(Object[] values) { assert values.length == 2; return new Tuple2<>((V1)values[0], (V2)values[1]); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy