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

[METRICS] rewrite BeanObject by java 17 record #1707

Merged
merged 1 commit into from
May 8, 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
50 changes: 5 additions & 45 deletions common/src/main/java/org/astraea/common/metrics/BeanObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import java.util.stream.Collectors;

/** Snapshot of remote MBean value */
public class BeanObject {
private final String domainName;
private final Map<String, String> properties;
private final Map<String, Object> attributes;
private final long createdTimestamp;
public record BeanObject(
String domainName,
Map<String, String> properties,
Map<String, Object> attributes,
long createdTimestamp) {

/**
* construct a {@link BeanObject}
Expand Down Expand Up @@ -63,44 +63,4 @@ public BeanObject(
.collect(Collectors.toUnmodifiableMap(Entry::getKey, Entry::getValue));
this.createdTimestamp = createdTimestamp;
}

public String domainName() {
return domainName;
}

public Map<String, String> properties() {
return properties;
}

public Map<String, Object> attributes() {
return attributes;
}

public long createdTimestamp() {
return createdTimestamp;
}

@Override
public String toString() {
String propertyList =
properties.entrySet().stream()
.map((entry -> entry.getKey() + "=" + entry.getValue()))
.collect(Collectors.joining(","));
return "[" + domainName + ":" + propertyList + "]\n" + attributes;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BeanObject that = (BeanObject) o;
return domainName.equals(that.domainName)
&& properties.equals(that.properties)
&& attributes.equals(that.attributes);
}

@Override
public int hashCode() {
return Objects.hash(domainName, properties, attributes);
}
}