package pl.mkaczara.bch.encoder.worker;
import java.util.concurrent.Callable;
import pl.mkaczara.bch.math.BinMonomial;
import pl.mkaczara.bch.math.BinPolynomial;
import pl.mkaczara.bch.code.CyclicCode;
/**
* Klasa obiektow, reprezentujacych workery kodera kodu BCH
*
* @author Kuba
*/
public class BCHEncoderWorker implements Callable<BinPolynomial>{
/**
* Wielomian wejsciowy
*/
private BinPolynomial input;
/**
* Kod
*/
private CyclicCode code;
/**
* Tworzy obiekt kodera BCH
*
* @param code kod
*/
public BCHEncoderWorker(CyclicCode code) {
this.code = code;
}
/**
* Koduje informacje
*
* @param input wielomian informacji
* @return wielomian slowa kodowego
*/
public BinPolynomial encode(BinPolynomial input){
input = input.multiplyByMonomial(new BinMonomial(code.getN() - code.getK()));
BinPolynomial rx = input.modulo(code.getGenerator());
input = input.add(rx);
return input;
}
@Override
public BinPolynomial call() throws Exception {
if(null == input){
throw new IllegalStateException("No input data given!");
}
return encode(input);
}
public BinPolynomial getInput() {
return input;
}
public void setInput(BinPolynomial input) {
this.input = input;
}
} // end BCHEncoderWorker