org.datavec.api.transform.ops.IntWritableOp Maven / Gradle / Ivy
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 Integer to one operating
* on {@link Writable} instances. It's expected this will only work if that {@link Writable}
* supports a conversion to Integer.
*
* Created by huitseeker on 5/14/17.
*/
@AllArgsConstructor
public class IntWritableOp implements IAggregableReduceOp {
@Getter
private IAggregableReduceOp operation;
@Override
public > void combine(W accu) {
if (accu instanceof IntWritableOp)
operation.combine(((IntWritableOp) 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.toInt());
}
@Override
public T get() {
return operation.get();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy