Class Bloom

java.lang.Object
org.web3j.utils.Bloom

public class Bloom extends Object
Ethereum Bloom filter. can be used to create a filter or test an item (topic) for a given filter.
  • Constructor Summary

    Constructors
    Constructor
    Description
    creates empty filter (all bits set to zero).
    Bloom(byte[] bytes)
    create filter from bytes.
    Bloom(String bytes)
    create filter from hex string.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(byte[] topic)
    add a byte array (topic) to filter.
    void
    add(String topic)
    add a byte array (topic) to filter.
    boolean
     
    byte[]
     
     
    int
     
    boolean
    test(byte[] topic)
    test presents of a topic.
    static boolean
    test(byte[] bloomBytes, byte[]... topics)
    test topics against a bloom filter.
    boolean
    test(String topic)
    test presents of a topic.
    static boolean
    test(String bloomBytes, String... topics)
    test topics against a bloom filter.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Bloom

      public Bloom()
      creates empty filter (all bits set to zero).
    • Bloom

      public Bloom(String bytes)
      create filter from hex string.
      Parameters:
      bytes - the filter data. its length must be 256 bytes.
      Throws:
      IllegalArgumentException - if bytes length is not 256, or it is null.
    • Bloom

      public Bloom(byte[] bytes)
      create filter from bytes.
      Parameters:
      bytes - the filter data. its length must be 256 bytes.
      Throws:
      IllegalArgumentException - if bytes length is not 256, or it is null.
  • Method Details

    • test

      public static boolean test(byte[] bloomBytes, byte[]... topics)
      test topics against a bloom filter.
      Parameters:
      bloomBytes - the filter bytes.
      topics - topics to be tested
      Returns:
      true if all topics is present in filter, otherwise returns false
      Throws:
      IllegalArgumentException - if bloomBytes length is not 256, or it is null, or topics is null.
    • test

      public static boolean test(String bloomBytes, String... topics)
      test topics against a bloom filter.
      Parameters:
      bloomBytes - the filter bytes.
      topics - topics to be tested
      Returns:
      true if all topics is present in filter, otherwise returns false
      Throws:
      IllegalArgumentException - if bloomBytes length is not 256, or it is null, or topics is null.
    • add

      public void add(String topic)
      add a byte array (topic) to filter. after adding, test() will return true for this topic.
      Parameters:
      topic - the topic hex string.
      Throws:
      IllegalArgumentException - if topic is null.
    • add

      public void add(byte[] topic)
      add a byte array (topic) to filter. after adding, test() will return true for this topic.
      Parameters:
      topic - the topic hex string.
      Throws:
      IllegalArgumentException - if topic is null.
    • test

      public boolean test(String topic)
      test presents of a topic. for every topic added by add() this returns true.
      Parameters:
      topic - the topic hex string.
      Returns:
      true if topic is present (false-positive is possible), and false if topic is not present(false-negative is not possible).
      Throws:
      IllegalArgumentException - if topic is null.
    • test

      public boolean test(byte[] topic)
      test presents of a topic. for every topic added by add() this returns true.
      Parameters:
      topic - the topic bytes.
      Returns:
      true if topic is present (false-positive is possible), and false if topic is not present(false-negative is not possible).
      Throws:
      IllegalArgumentException - if topic is null.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getBytesHexString

      public String getBytesHexString()
      Returns:
      Bloom filter bytes as hex string
    • getBytes

      public byte[] getBytes()
      Returns:
      Bloom filter bytes (returns a copy)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object