public List<Block> chunk(String resourceId, List<Statement> statements) {
    List<Statement> filtered = new ArrayList<>();
    int i = 0;
    while (i < statements.size()) {
      Statement first = statements.get(i);
      int j = i + 1;
      while (j < statements.size() && statements.get(j).getValue().equals(first.getValue())) {
        j++;
      }
      filtered.add(statements.get(i));
      if (i < j - 1) {
        filtered.add(statements.get(j - 1));
      }
      i = j;
    }
    statements = filtered;

    if (statements.size() < blockSize) {
      return Collections.emptyList();
    }
    Statement[] statementsArr = statements.toArray(new Statement[statements.size()]);
    List<Block> blocks = new ArrayList<>(statementsArr.length - blockSize + 1);
    long hash = 0;
    int first = 0;
    int last = 0;
    for (; last < blockSize - 1; last++) {
      hash = hash * PRIME_BASE + statementsArr[last].getValue().hashCode();
    }
    Block.Builder blockBuilder = Block.builder().setResourceId(resourceId);
    for (; last < statementsArr.length; last++, first++) {
      Statement firstStatement = statementsArr[first];
      Statement lastStatement = statementsArr[last];
      // add last statement to hash
      hash = hash * PRIME_BASE + lastStatement.getValue().hashCode();
      // create block
      Block block = blockBuilder.setBlockHash(new ByteArray(hash))
          .setIndexInFile(first)
          .setLines(firstStatement.getStartLine(), lastStatement.getEndLine())
          .build();
      blocks.add(block);
      // remove first statement from hash
      hash -= power * firstStatement.getValue().hashCode();
    }
    return blocks;
  }
@Test
  public void shouldCalculateHashes() {
    List<Statement> statements = createStatementsFromStrings("aaaaaa", "bbbbbb", "cccccc", "dddddd", "eeeeee");
    BlockChunker blockChunker = createChunkerWithBlockSize(3);
    List<Block> blocks = blockChunker.chunk("resource", statements);
    assertThat(blocks.get(0).getBlockHash(), equalTo(hash("aaaaaa", "bbbbbb", "cccccc")));
    assertThat(blocks.get(1).getBlockHash(), equalTo(hash("bbbbbb", "cccccc", "dddddd")));
    assertThat(blocks.get(2).getBlockHash(), equalTo(hash("cccccc", "dddddd", "eeeeee")));
    assertThat(blocks.get(0).getBlockHash().toString(), is("fffffeb6ae1af4c0"));
    assertThat(blocks.get(1).getBlockHash().toString(), is("fffffebd8512d120"));
    assertThat(blocks.get(2).getBlockHash().toString(), is("fffffec45c0aad80"));
  }