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

org.datavec.api.transform.ops.ByteWritableOp Maven / Gradle / Ivy

There is a newer version: 1.0.0-M2.1
Show newest version
package org.datavec.api.transform.ops;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.datavec.api.writable.Writable;

/**
 * This class converts an {@link IAggregableReduceOp} operating on a Byte to one operating
 * on {@link Writable} instances. It's expected this will only work if that {@link Writable}
 * supports a conversion to Byte.
 *
 * Created by huitseeker on 5/14/17.
 */
@AllArgsConstructor
public class ByteWritableOp implements IAggregableReduceOp {

    @Getter
    private IAggregableReduceOp operation;

    @Override
    public > void combine(W accu) {
        if (accu instanceof ByteWritableOp)
            operation.combine(((ByteWritableOp) accu).getOperation());
        else
            throw new UnsupportedOperationException("Tried to combine() incompatible " + accu.getClass().getName()
                            + " operator where " + this.getClass().getName() + " expected");
    }

    @Override
    public void accept(Writable writable) {
        int val = writable.toInt();
        operation.accept((byte) val);
    }

    @Override
    public T get() {
        return operation.get();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy