Skip to content

Commit

Permalink
[COMMON] rewrite admin.Quota by java 17 record (#1741)
Browse files Browse the repository at this point in the history
  • Loading branch information
chia7712 authored May 13, 2023
1 parent a9ee445 commit 9d0f993
Showing 1 changed file with 3 additions and 67 deletions.
70 changes: 3 additions & 67 deletions common/src/main/java/org/astraea/common/admin/Quota.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Quota> of(Map<ClientQuotaEntity, Map<String, Double>> data) {
public static List<Quota> of(Map<ClientQuotaEntity, Map<String, Double>> data) {
return data.entrySet().stream()
.flatMap(
clientQuotaEntityMapEntry ->
Expand All @@ -39,68 +37,6 @@ static List<Quota> of(Map<ClientQuotaEntity, Map<String, Double>> 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();
}
}

0 comments on commit 9d0f993

Please sign in to comment.