Package org.web3j.utils
Class Bloom
java.lang.Object
org.web3j.utils.Bloom
Ethereum Bloom filter. can be used to create a filter or test an item (topic) for a given filter.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(byte[] topic) add a byte array (topic) to filter.voidadd a byte array (topic) to filter.booleanbyte[]getBytes()inthashCode()booleantest(byte[] topic) test presents of a topic.static booleantest(byte[] bloomBytes, byte[]... topics) test topics against a bloom filter.booleantest presents of a topic.static booleantest topics against a bloom filter.toString()
-
Constructor Details
-
Bloom
public Bloom()creates empty filter (all bits set to zero). -
Bloom
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
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
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
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
-
getBytesHexString
- Returns:
- Bloom filter bytes as hex string
-
getBytes
public byte[] getBytes()- Returns:
- Bloom filter bytes (returns a copy)
-
equals
-
hashCode
public int hashCode()
-