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.Config by java 17 record #1739

Merged
merged 1 commit into from
May 13, 2023
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
2 changes: 1 addition & 1 deletion common/src/main/java/org/astraea/common/ByteUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public String name() {

@Override
public Config config() {
return Config.of(protoTopic.getConfigMap());
return new Config(protoTopic.getConfigMap());
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/org/astraea/common/admin/Broker.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static Broker of(
Map<String, String> configs,
Map<String, DescribeLogDirsResponse.LogDirInfo> dirs,
Collection<org.apache.kafka.clients.admin.TopicDescription> topics) {
var config = Config.of(configs);
var config = new Config(configs);
var partitionsFromTopicDesc =
topics.stream()
.flatMap(
Expand Down
24 changes: 5 additions & 19 deletions common/src/main/java/org/astraea/common/admin/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,14 @@
import java.util.Optional;

/** this interface used to represent the resource (topic or broker) configuration. */
public interface Config {
public record Config(Map<String, String> raw) {

Config EMPTY = Config.of(Map.of());

static Config of(Map<String, String> configs) {
return new Config() {
@Override
public Map<String, String> raw() {
return configs;
}

@Override
public Optional<String> value(String key) {
return Optional.ofNullable(configs.get(key));
}
};
}

Map<String, String> raw();
public static final Config EMPTY = new Config(Map.of());
/**
* @param key config key
* @return the value associated to input key. otherwise, empty
*/
Optional<String> value(String key);
public Optional<String> value(String key) {
return Optional.ofNullable(raw.get(key));
}
}
2 changes: 1 addition & 1 deletion common/src/main/java/org/astraea/common/admin/Topic.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static Topic of(
org.apache.kafka.clients.admin.TopicDescription topicDescription,
Map<String, String> kafkaConfig) {

var config = Config.of(kafkaConfig);
var config = new Config(kafkaConfig);
var topicPartitions =
topicDescription.partitions().stream()
.map(p -> TopicPartition.of(name, p.partition()))
Expand Down