Skip to content

Commit

Permalink
[METRICS] rewrite BeanObject by java 17 record (#1707)
Browse files Browse the repository at this point in the history
  • Loading branch information
chia7712 authored May 8, 2023
1 parent ec91b20 commit f7d50da
Showing 1 changed file with 5 additions and 45 deletions.
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);
}
}

0 comments on commit f7d50da

Please sign in to comment.