Skip to content

Commit

Permalink
added utilitly fns to CacheStatsResponse
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Alfonsi <[email protected]>
  • Loading branch information
Peter Alfonsi committed Feb 27, 2024
1 parent c8dc1b3 commit 4abd602
Showing 1 changed file with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@

package org.opensearch.common.cache.stats;

import java.util.Objects;

/**
* A class containing the 5 metrics tracked by a CacheStats object.
*/
public class CacheStatsResponse { // TODO: Make this extend ToXContent.
public final long hits;
public final long misses;
public final long evictions;
public final long memorySize;
public final long entries;
public long hits;
public long misses;
public long evictions;
public long memorySize;
public long entries;

public CacheStatsResponse(long hits, long misses, long evictions, long memorySize, long entries) {
this.hits = hits;
Expand All @@ -25,4 +27,44 @@ public CacheStatsResponse(long hits, long misses, long evictions, long memorySiz
this.memorySize = memorySize;
this.entries = entries;
}

public CacheStatsResponse() {
this.hits = 0;
this.misses = 0;
this.evictions = 0;
this.memorySize = 0;
this.entries = 0;
}

public void add(CacheStatsResponse other) {
if (other == null) {
return;
}
this.hits += other.hits;
this.misses += other.misses;
this.evictions += other.evictions;
this.memorySize += other.memorySize;
this.entries += other.entries;
}

@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (o.getClass() != CacheStatsResponse.class) {
return false;
}
CacheStatsResponse other = (CacheStatsResponse) o;
return (hits == other.hits)
&& (misses == other.misses)
&& (evictions == other.evictions)
&& (memorySize == other.memorySize)
&& (entries == other.entries);
}

@Override
public int hashCode() {
return Objects.hash(hits, misses, evictions, memorySize, entries);
}
}

0 comments on commit 4abd602

Please sign in to comment.