Coverage Summary for Class: BlocksBloom (co.rsk.logfilter)

Class Class, % Method, % Line, %
BlocksBloom 0% (0/1) 0% (0/9) 0% (0/31)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 5  * 6  * This program is free software: you can redistribute it and/or modify 7  * it under the terms of the GNU Lesser General Public License as published by 8  * the Free Software Foundation, either version 3 of the License, or 9  * (at your option) any later version. 10  * 11  * This program is distributed in the hope that it will be useful, 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14  * GNU Lesser General Public License for more details. 15  * 16  * You should have received a copy of the GNU Lesser General Public License 17  * along with this program. If not, see <http://www.gnu.org/licenses/>. 18  */ 19  20 package co.rsk.logfilter; 21  22 import org.ethereum.core.Bloom; 23  24 /** 25  * Created by ajlopez on 29/01/2019. 26  */ 27 public class BlocksBloom { 28  private final Bloom bloom; 29  private long fromBlock; 30  private long toBlock; 31  private boolean empty; 32  33  public BlocksBloom() { 34  this.bloom = new Bloom(); 35  this.fromBlock = 0; 36  this.toBlock = 0; 37  this.empty = true; 38  } 39  40  public BlocksBloom(long fromBlock, long toBlock, Bloom bloom) { 41  this.bloom = bloom; 42  this.fromBlock = fromBlock; 43  this.toBlock = toBlock; 44  this.empty = false; 45  } 46  47  public Bloom getBloom() { return this.bloom; } 48  49  public long fromBlock() { return this.fromBlock; } 50  51  public long toBlock() { return this.toBlock; } 52  53  public long size() { 54  if (this.empty) { 55  return 0; 56  } 57  58  return this.toBlock - this.fromBlock + 1; 59  } 60  61  public boolean hasBlockBloom(long blockNumber) { 62  if (this.empty) { 63  return false; 64  } 65  66  return this.fromBlock <= blockNumber && blockNumber <= this.toBlock; 67  } 68  69  public void addBlockBloom(long blockNumber, Bloom blockBloom) { 70  if (this.empty) { 71  this.fromBlock = blockNumber; 72  this.toBlock = blockNumber; 73  this.empty = false; 74  } 75  else if (blockNumber == toBlock + 1) { 76  this.toBlock = blockNumber; 77  } 78  else { 79  throw new UnsupportedOperationException("Block out of sequence"); 80  } 81  82  this.bloom.or(blockBloom); 83  } 84  85  public boolean matches(Bloom bloom) { 86  return this.bloom.matches(bloom); 87  } 88 }