Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what CollectionUtils.isEqualCollection cardinality is?

Tags:

java

apache

I wanted to test equality between 2 list and found CollectionUtils.isEqualCollection. It says on API: Returns true iff the given Collections contain exactly the same elements with exactly the same cardinalities.

what cardinalities exactly are? I couldn't find good explanation about it.

Thanks in advance!

like image 278
OferP Avatar asked Jan 11 '16 16:01

OferP


People also ask

What is CollectionUtils emptyIfNull?

Apache Commons CollectionUtils emptyIfNull(final Collection<T> collection) Returns an immutable empty collection if the argument is null, or the argument itself otherwise.

What is collection cardinality?

Based on CollectionUtils. cardinality() : Returns the number of occurrences of obj in coll . I'd say it returns true if and only if they have the same elements, the same number of times. Take a look here, around line 514.

Does CollectionUtils isNotEmpty check for NULL?

isNotEmpty() method of CollectionUtils can be used to check if a list is not empty without worrying about null list. So null check is not required to be placed everywhere before checking the size of the list.

What is Java CollectionUtils?

Simply put, the Apache CollectionUtils provides utility methods for common operations which cover a wide range of use cases and helps in avoiding writing boilerplate code. The library targets older JVM releases because currently, similar functionality is provided by the Java 8's Stream API.


1 Answers

Based on CollectionUtils.cardinality():

Returns the number of occurrences of obj in coll.

I'd say it returns true if and only if they have the same elements, the same number of times.

Take a look here, around line 514. It seems the order of the elements doesn't matter.

like image 65
Vlad Avatar answered Nov 13 '22 01:11

Vlad