public synchronized FilteredBlock applyAndUpdate(Block block){
  List<Transaction> txns=block.getTransactions();
  List<Sha256Hash> txHashes=new ArrayList<Sha256Hash>(txns.size());
  List<Transaction> matched=Lists.newArrayList();
  byte[] bits=new byte[(int)Math.ceil(txns.size() / 8.0)];
  for (int i=0; i < txns.size(); i++) {
    Transaction tx=txns.get(i);
    txHashes.add(tx.getHash());
    if (applyAndUpdate(tx)) {
      Utils.setBitLE(bits,i);
      matched.add(tx);
    }
  }
  PartialMerkleTree pmt=PartialMerkleTree.buildFromLeaves(block.getParams(),bits,txHashes);
  FilteredBlock filteredBlock=new FilteredBlock(block.getParams(),block.cloneAsHeader(),pmt);
  for (  Transaction transaction : matched)   filteredBlock.provideTransaction(transaction);
  return filteredBlock;
}

public synchronized FilteredBlock applyAndUpdate ( Block block ) { List < Transaction > txns = block . getTransactions ( ) ; List < Sha256Hash > txHashes = new ArrayList < Sha256Hash > ( txns . size ( ) ) ; List < Transaction > matched = Lists . newArrayList ( ) ; byte [ ] bits = new byte [ ( int ) Math . ceil ( txns . size ( ) / 8.0 ) ] ; for ( int i = 0 ; i < txns . size ( ) ; i ++ ) { Transaction tx = txns . get ( i ) ; txHashes . add ( tx . getHash ( ) ) ; if ( applyAndUpdate ( tx ) ) { Utils . setBitLE ( bits , i ) ; matched . add ( tx ) ; } } PartialMerkleTree pmt = PartialMerkleTree . buildFromLeaves ( block . getParams ( ) , bits , txHashes ) ; FilteredBlock filteredBlock = new FilteredBlock ( block . getParams ( ) , block . cloneAsHeader ( ) , pmt ) ; for ( Transaction transaction : matched ) filteredBlock . provideTransaction ( transaction ) ; return filteredBlock ; }
creates a new filteredblock from the given block , using this filter to select transactions . matches can cause the filter to be updated with the matched element , this ensures that when a filter is applied to a block , spends of matched transactions are also matched . however it means this filter can be mutated by the operation . the returned filtered block already has the matched transactions associated with it .
