mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-08 21:52:48 +07:00
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
30 lines
1.2 KiB
HTML
30 lines
1.2 KiB
HTML
<html>
|
|
<body>
|
|
Reports calls to <code>containsAll()</code> on <code>java.util.List</code>.
|
|
<p>
|
|
The time complexity of this method call is O(n·m), where n is the number of elements in the list on which
|
|
the method is called, and m is the number of elements in the collection passed to the method as a parameter.
|
|
When the list is large, this can be an expensive operation.
|
|
</p>
|
|
<p>
|
|
The quick-fix wraps the list in <code>new java.util.HashSet<>()</code> since the time required to create
|
|
<code>java.util.HashSet</code> from <code>java.util.List</code> and execute <code>containsAll()</code> on
|
|
<code>java.util.HashSet</code> is O(n+m).
|
|
</p>
|
|
<p><b>Example:</b></p>
|
|
<pre><code> public boolean check(List<String> list, Collection<String> collection) {
|
|
// O(n·m) complexity
|
|
return list.containsAll(collection);
|
|
}
|
|
</code></pre>
|
|
<p>After the quick-fix is applied:</p>
|
|
<pre><code> public boolean check(List<String> list, Collection<String> collection) {
|
|
// O(n+m) complexity
|
|
return new HashSet<>(list).containsAll(collection);
|
|
}
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
<p><small>New in 2022.1</small></p>
|
|
</body>
|
|
</html>
|