You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "Jakob Homan (Jira)" <ji...@apache.org> on 2020/06/03 20:48:00 UTC
[jira] [Created] (KAFKA-10093) Replace iteration with call to
addAll in Utils
Jakob Homan created KAFKA-10093:
-----------------------------------
Summary: Replace iteration with call to addAll in Utils
Key: KAFKA-10093
URL: https://issues.apache.org/jira/browse/KAFKA-10093
Project: Kafka
Issue Type: Improvement
Components: clients
Reporter: Jakob Homan
Assignee: Can Cecen
n.b. This is a newbie ticket designed to be an introduction to contributing for the assignee.
In clients/src/main/java/org/apache/kafka/common/utils/Utils.java we're currently using iteration to add all the elements from one collection into another. We can replace this with a call to Arrays.asList() and Collections.addAll().
{code}/**
* Creates a set
* @param elems the elements
* @param <T> the type of element
* @return Set
*/
@SafeVarargs
public static <T> Set<T> mkSet(T... elems) {
Set<T> result = new HashSet<>((int) (elems.length / 0.75) + 1);
for (T elem : elems)
result.add(elem);
return result;
}
/**
* Creates a sorted set
* @param elems the elements
* @param <T> the type of element, must be comparable
* @return SortedSet
*/
@SafeVarargs
public static <T extends Comparable<T>> SortedSet<T> mkSortedSet(T... elems) {
SortedSet<T> result = new TreeSet<>();
for (T elem : elems)
result.add(elem);
return result;
}{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)