@Test public void testDecoding() { final List<LZ77Codeword> encoded = new LinkedList<>(); encoded.add(new LZ77Codeword(0, 0, 'a')); encoded.add(new LZ77Codeword(0, 0, 'b')); encoded.add(new LZ77Codeword(2, 1, 'a')); encoded.add(new LZ77Codeword(3, 1, 'b')); encoded.add(new LZ77Codeword(6, 4, 'c')); encoded.add(new LZ77Codeword(3, 4, 'b')); encoded.add(new LZ77Codeword(1, 1, (char) 0)); final String expected = "abaabbabaacaacabb"; final String actual = new String(LZ77.decode(encoded)); assertEquals(expected, actual); }
public static char[] decode(final List<LZ77Codeword> input) { final StringBuilder buffer = new StringBuilder(); for (final LZ77Codeword word : input) { final int numCharsToGoBack = word.getI(); final int numCharsToCopy = word.getJ(); final char characterToAppend = word.getX(); if (numCharsToCopy > 0) { final int firstCopyIndex = buffer.length() - numCharsToGoBack; log.debug("Copying {} char(s) from index {}.", numCharsToCopy, firstCopyIndex); for (int i = 0; i < numCharsToCopy; i++) { final char charToCopy = buffer.charAt(firstCopyIndex + i); log.debug("Copying: `{}`", charToCopy); buffer.append(charToCopy); } } if (characterToAppend != 0) { log.debug("Appending: `{}`", characterToAppend); buffer.append(characterToAppend); } } return buffer.toString().toCharArray(); }
LZ77 { public static char[] decode(final List<LZ77Codeword> input) { final StringBuilder buffer = new StringBuilder(); for (final LZ77Codeword word : input) { final int numCharsToGoBack = word.getI(); final int numCharsToCopy = word.getJ(); final char characterToAppend = word.getX(); if (numCharsToCopy > 0) { final int firstCopyIndex = buffer.length() - numCharsToGoBack; log.debug("Copying {} char(s) from index {}.", numCharsToCopy, firstCopyIndex); for (int i = 0; i < numCharsToCopy; i++) { final char charToCopy = buffer.charAt(firstCopyIndex + i); log.debug("Copying: `{}`", charToCopy); buffer.append(charToCopy); } } if (characterToAppend != 0) { log.debug("Appending: `{}`", characterToAppend); buffer.append(characterToAppend); } } return buffer.toString().toCharArray(); } }
LZ77 { public static char[] decode(final List<LZ77Codeword> input) { final StringBuilder buffer = new StringBuilder(); for (final LZ77Codeword word : input) { final int numCharsToGoBack = word.getI(); final int numCharsToCopy = word.getJ(); final char characterToAppend = word.getX(); if (numCharsToCopy > 0) { final int firstCopyIndex = buffer.length() - numCharsToGoBack; log.debug("Copying {} char(s) from index {}.", numCharsToCopy, firstCopyIndex); for (int i = 0; i < numCharsToCopy; i++) { final char charToCopy = buffer.charAt(firstCopyIndex + i); log.debug("Copying: `{}`", charToCopy); buffer.append(charToCopy); } } if (characterToAppend != 0) { log.debug("Appending: `{}`", characterToAppend); buffer.append(characterToAppend); } } return buffer.toString().toCharArray(); } private  LZ77(); }
LZ77 { public static char[] decode(final List<LZ77Codeword> input) { final StringBuilder buffer = new StringBuilder(); for (final LZ77Codeword word : input) { final int numCharsToGoBack = word.getI(); final int numCharsToCopy = word.getJ(); final char characterToAppend = word.getX(); if (numCharsToCopy > 0) { final int firstCopyIndex = buffer.length() - numCharsToGoBack; log.debug("Copying {} char(s) from index {}.", numCharsToCopy, firstCopyIndex); for (int i = 0; i < numCharsToCopy; i++) { final char charToCopy = buffer.charAt(firstCopyIndex + i); log.debug("Copying: `{}`", charToCopy); buffer.append(charToCopy); } } if (characterToAppend != 0) { log.debug("Appending: `{}`", characterToAppend); buffer.append(characterToAppend); } } return buffer.toString().toCharArray(); } private  LZ77(); static List<LZ77Codeword> encode(final char[] input, final int backBufferSize, final int frontBufferSize); static char[] decode(final List<LZ77Codeword> input); }
LZ77 { public static char[] decode(final List<LZ77Codeword> input) { final StringBuilder buffer = new StringBuilder(); for (final LZ77Codeword word : input) { final int numCharsToGoBack = word.getI(); final int numCharsToCopy = word.getJ(); final char characterToAppend = word.getX(); if (numCharsToCopy > 0) { final int firstCopyIndex = buffer.length() - numCharsToGoBack; log.debug("Copying {} char(s) from index {}.", numCharsToCopy, firstCopyIndex); for (int i = 0; i < numCharsToCopy; i++) { final char charToCopy = buffer.charAt(firstCopyIndex + i); log.debug("Copying: `{}`", charToCopy); buffer.append(charToCopy); } } if (characterToAppend != 0) { log.debug("Appending: `{}`", characterToAppend); buffer.append(characterToAppend); } } return buffer.toString().toCharArray(); } private  LZ77(); static List<LZ77Codeword> encode(final char[] input, final int backBufferSize, final int frontBufferSize); static char[] decode(final List<LZ77Codeword> input);  }