Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[COMMON] rewrite admin.Quota by java 17 record #1741

Merged
merged 1 commit into from
May 13, 2023
Merged
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
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();
}
}