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

org.datavec.api.transform.ops.LongWritableOp 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 Long to one operating
 * on {@link Writable} instances. It's expected this will only work if that {@link Writable}
 * supports a conversion to Long.
 *
 * Created by huitseeker on 5/14/17.
 */
@AllArgsConstructor
public class LongWritableOp implements IAggregableReduceOp {

    @Getter
    private IAggregableReduceOp operation;

    @Override
    public > void combine(W accu) {
        if (accu instanceof LongWritableOp)
            operation.combine(((LongWritableOp) 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) {
        operation.accept(writable.toLong());
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy