From 9d0f993891ea9f25f5d4a9b3813905d3fab5953c Mon Sep 17 00:00:00 2001 From: Chia-Ping Tsai Date: Sat, 13 May 2023 21:15:45 +0800 Subject: [PATCH] [COMMON] rewrite admin.Quota by java 17 record (#1741) --- .../java/org/astraea/common/admin/Quota.java | 70 +------------------ 1 file changed, 3 insertions(+), 67 deletions(-) diff --git a/common/src/main/java/org/astraea/common/admin/Quota.java b/common/src/main/java/org/astraea/common/admin/Quota.java index 7684427685..478eff6731 100644 --- a/common/src/main/java/org/astraea/common/admin/Quota.java +++ b/common/src/main/java/org/astraea/common/admin/Quota.java @@ -18,13 +18,11 @@ import java.util.List; import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; import org.apache.kafka.common.quota.ClientQuotaEntity; -public class Quota { +public record Quota(String targetKey, String targetValue, String limitKey, double limitValue) { - static List of(Map> data) { + public static List of(Map> data) { return data.entrySet().stream() .flatMap( clientQuotaEntityMapEntry -> @@ -39,68 +37,6 @@ static List of(Map> data) { stringStringEntry.getValue(), v.getKey(), v.getValue())))) - .collect(Collectors.toUnmodifiableList()); - } - - private final String targetKey; - - private final String targetValue; - private final String limitKey; - private final double limitValue; - - public Quota(String targetKey, String targetValue, String limitKey, double limitValue) { - this.targetKey = targetKey; - this.targetValue = targetValue; - this.limitKey = limitKey; - this.limitValue = limitValue; - } - - public String targetKey() { - return targetKey; - } - - public String targetValue() { - return targetValue; - } - - public String limitKey() { - return limitKey; - } - - public double limitValue() { - return limitValue; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Quota quota = (Quota) o; - return Double.compare(quota.limitValue, limitValue) == 0 - && Objects.equals(targetKey, quota.targetKey) - && Objects.equals(targetValue, quota.targetValue) - && Objects.equals(limitKey, quota.limitKey); - } - - @Override - public int hashCode() { - return Objects.hash(targetKey, targetValue, limitKey, limitValue); - } - - @Override - public String toString() { - return "Quota{" - + "targetKey='" - + targetKey - + '\'' - + ", targetValue='" - + targetValue - + '\'' - + ", limitKey='" - + limitKey - + '\'' - + ", limitValue=" - + limitValue - + '}'; + .toList(); } }