package aalg.algebra;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;

/**
 * Additive group over given field.
 * @author Ing. Petr Ležák
 *
 * @param <T> type of element
 */
public class AdditiveFieldGroup<T extends IElement> extends GroupImpl<T> {

	private final IField<T> field;   // Underlying field
	
	
	/**
	 * Creates additive group over given field.
	 * @param field field
	 */
	public AdditiveFieldGroup(final IField<T> field) {
		this.field = field;
	}
	
	@Override
	public T operation(final T a, final T b) {
		return field.add(a, b);
	}

	@Override
	public T getIdentity() {
		return field.getAdditiveIdentity();
	}
	
	@Override
	public T getInverse(final T x) {
		return field.additiveInverse(x);
	}

	@Override
	public T readElement(final InputStream stream) throws IOException {
		return field.readElement(stream);
	}

	@Override
	public void writeElement(final T element, final OutputStream stream) throws IOException {
		field.writeElement(element, stream);
	}

	@Override
	public boolean containsElement (final T element) {
		return field.containsElement(element);
	}

	@Override
	public Iterable<T> getElements() {
		return field.getElements();
	}

	@Override
	public BigInteger getOrder() {
		return field.getOrder();
	}
	
	@Override
	public T elementFromString(final String string) {
		return field.elementFromString(string);
	}

	@Override
	public BigInteger getElementIndex(final T element) {
		return field.getElementIndex(element);
	}
}
