Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,22 @@ public synchronized void clear() {

@Override
public synchronized V put(K k, V v) {
Map<K, V> copy = new HashMap<K, V>(this.map);
Map<K, V> copy = new HashMap<>(this.map);
V prev = copy.put(k, v);
this.map = Collections.unmodifiableMap(copy);
return prev;
}

@Override
public synchronized void putAll(Map<? extends K, ? extends V> entries) {
Map<K, V> copy = new HashMap<K, V>(this.map);
Map<K, V> copy = new HashMap<>(this.map);
copy.putAll(entries);
this.map = Collections.unmodifiableMap(copy);
}

@Override
public synchronized V remove(Object key) {
Map<K, V> copy = new HashMap<K, V>(this.map);
Map<K, V> copy = new HashMap<>(this.map);
V prev = copy.remove(key);
this.map = Collections.unmodifiableMap(copy);
return prev;
Expand Down
27 changes: 7 additions & 20 deletions clients/src/main/java/org/apache/kafka/common/utils/Exit.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,15 @@ public interface ShutdownHookAdder {
void addShutdownHook(String name, Runnable runnable);
}

private static final Procedure DEFAULT_HALT_PROCEDURE = new Procedure() {
@Override
public void execute(int statusCode, String message) {
Runtime.getRuntime().halt(statusCode);
}
};
private static final Procedure DEFAULT_HALT_PROCEDURE = (statusCode, message) -> Runtime.getRuntime().halt(statusCode);

private static final Procedure DEFAULT_EXIT_PROCEDURE = new Procedure() {
@Override
public void execute(int statusCode, String message) {
System.exit(statusCode);
}
};
private static final Procedure DEFAULT_EXIT_PROCEDURE = (statusCode, message) -> System.exit(statusCode);

private static final ShutdownHookAdder DEFAULT_SHUTDOWN_HOOK_ADDER = new ShutdownHookAdder() {
@Override
public void addShutdownHook(String name, Runnable runnable) {
if (name != null)
Runtime.getRuntime().addShutdownHook(KafkaThread.nonDaemon(name, runnable));
else
Runtime.getRuntime().addShutdownHook(new Thread(runnable));
}
private static final ShutdownHookAdder DEFAULT_SHUTDOWN_HOOK_ADDER = (name, runnable) -> {
if (name != null)
Runtime.getRuntime().addShutdownHook(KafkaThread.nonDaemon(name, runnable));
else
Runtime.getRuntime().addShutdownHook(new Thread(runnable));
};

private volatile static Procedure exitProcedure = DEFAULT_EXIT_PROCEDURE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ final int slot(Element[] curElements, Object e) {
* @param key The element to match.
* @return The match index, or INVALID_INDEX if no match was found.
*/
final private int findIndexOfEqualElement(Object key) {
private int findIndexOfEqualElement(Object key) {
if (key == null || size == 0) {
return INVALID_INDEX;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int findElementToRemove(Object key) {
*/
final public List<E> findAll(E key) {
if (key == null || size() == 0) {
return Collections.<E>emptyList();
return Collections.emptyList();
}
ArrayList<E> results = new ArrayList<>();
int slot = slot(elements, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public MappedIterator(Iterator<? extends F> underlyingIterator, Function<F, T> m
}

@Override
public final boolean hasNext() {
public boolean hasNext() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class is final

return underlyingIterator.hasNext();
}

@Override
public final T next() {
public T next() {
return mapper.apply(underlyingIterator.next());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ public class Sanitizer {
* using URL-encoding.
*/
public static String sanitize(String name) {
String encoded = "";
try {
encoded = URLEncoder.encode(name, StandardCharsets.UTF_8.name());
String encoded = URLEncoder.encode(name, StandardCharsets.UTF_8.name());
StringBuilder builder = new StringBuilder();
for (int i = 0; i < encoded.length(); i++) {
char c = encoded.charAt(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import org.apache.kafka.common.acl.AclOperation;
import org.apache.kafka.common.acl.AclPermissionType;
import org.apache.kafka.common.config.SecurityConfig;
import org.apache.kafka.common.resource.PatternType;
import org.apache.kafka.common.resource.ResourcePattern;
import org.apache.kafka.common.resource.ResourceType;
import org.apache.kafka.common.security.auth.SecurityProviderCreator;
import org.apache.kafka.common.security.auth.KafkaPrincipal;
Expand Down Expand Up @@ -171,9 +169,4 @@ public static void authorizeByResourceTypeCheckArgs(AclOperation op,
"Unknown operation type");
}
}

public static boolean denyAll(ResourcePattern pattern) {
return pattern.patternType() == PatternType.LITERAL
&& pattern.name().equals(ResourcePattern.WILDCARD_RESOURCE);
}
}
27 changes: 0 additions & 27 deletions clients/src/main/java/org/apache/kafka/common/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1257,15 +1257,6 @@ public static <T> List<T> toList(Iterator<T> iterator, Predicate<T> predicate) {
return res;
}

public static <T> List<T> concatListsUnmodifiable(List<T> left, List<T> right) {
return concatLists(left, right, Collections::unmodifiableList);
}

public static <T> List<T> concatLists(List<T> left, List<T> right, Function<List<T>, List<T>> finisher) {
return Stream.concat(left.stream(), right.stream())
.collect(Collectors.collectingAndThen(Collectors.toList(), finisher));
}

public static int to32BitField(final Set<Byte> bytes) {
int value = 0;
for (final byte b : bytes)
Expand All @@ -1291,18 +1282,6 @@ public static Set<Byte> from32BitField(final int intValue) {
return result;
}

public static <K1, V1, K2, V2> Map<K2, V2> transformMap(
Map<? extends K1, ? extends V1> map,
Function<K1, K2> keyMapper,
Function<V1, V2> valueMapper) {
return map.entrySet().stream().collect(
Collectors.toMap(
entry -> keyMapper.apply(entry.getKey()),
entry -> valueMapper.apply(entry.getValue())
)
);
}

/**
* A Collector that offers two kinds of convenience:
* 1. You can specify the concrete type of the returned Map
Expand Down Expand Up @@ -1454,12 +1433,6 @@ public static boolean isBlank(String str) {
return str == null || str.trim().isEmpty();
}

public static <K, V> Map<K, V> initializeMap(Collection<K> keys, Supplier<V> valueSupplier) {
Map<K, V> res = new HashMap<>(keys.size());
keys.forEach(key -> res.put(key, valueSupplier.get()));
return res;
}

/**
* Get an array containing all of the {@link Object#toString string representations} of a given enumerable type.
* @param enumClass the enum class; may not be null
Expand Down