
com.newrelic.agent.util.FixedSizeSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of newrelic-agent Show documentation
Show all versions of newrelic-agent Show documentation
Jar required to run with a java application to monitor performance.
The newest version!
/*
*
* * Copyright 2020 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.util;
import java.util.TreeSet;
public class FixedSizeSet extends TreeSet {
private static final long serialVersionUID = 1474558437021809591L;
private int size;
public FixedSizeSet(int size) {
super();
this.size = size;
}
public int getFixedSize() {
return size;
}
@Override
public boolean add(E o) {
if (size() >= size) {
E first = first();
int comparison = o instanceof Comparable ? ((Comparable) o).compareTo(first) : comparator().compare(o,
first);
if (comparison < 0) {
return false;
} else {
super.remove(first);
}
}
return super.add(o);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy