package com.nickww.finitefield;

import static com.nickww.finitefield.FiniteByteField.*;

import java.util.List;

final class XorChecksumVector extends ChecksumVector
{
	@Override
	public byte[] withChecksums(byte[] data)
	{
		if(data.length < 1)
			throw new IllegalArgumentException("Data array must have at least one element");
		
		byte[] checksummed = new byte[data.length + 1];
		System.arraycopy(data, 0, checksummed, 0, data.length);
		checksummed[checksummed.length - 1] = add(data);
		return checksummed;
	}
	
	@Override
	public byte[] solveMissingValues(Byte[] dataWithChecksums)
	{
		if(dataWithChecksums.length < 2)
			throw new IllegalArgumentException("Array too small to include both data and checksums.");
		
		byte[] data = super.copy(dataWithChecksums, dataWithChecksums.length - 1);
		List<Integer> nullIndices = super.missingIndices(dataWithChecksums);
		if(!nullIndices.isEmpty() && nullIndices.get(0) != data.length)
		{
			if(nullIndices.size() > 1)
				throw new IllegalArgumentException("Too many missing values - can only handle 1");
			else
				data[nullIndices.get(0)] = add(dataWithChecksums[dataWithChecksums.length - 1], add(data));
		}
		return data;
	}
}

@@ -823,16 +823,20 @@
  - 1);%0D%0A
+%09%09%0D%0A
 %09%09List%3CI
@@ -903,81 +903,8 @@
 );%0D%0A
-%09%09if(!nullIndices.isEmpty() && nullIndices.get(0) != data.length)%0D%0A%09%09%7B%0D%0A%09
 %09%09if
@@ -929,17 +929,16 @@
 ) %3E 1)%0D%0A
-%09
 %09%09%09throw
@@ -1022,16 +1022,77 @@
 %0D%0A%09%09
-%09else
+%0D%0A%09%09if(!nullIndices.isEmpty() && nullIndices.get(0) != data.length)
 %0D%0A
-%09
 %09%09%09d
@@ -1187,13 +1187,8 @@
 );%0D%0A
-%09%09%7D%0D%0A
 %09%09re

Refactor to flatten if statements