@@ -340,18 +340,18 @@ private static boolean isLegalCharacter(char input) {
340340 /**
341341 * A sample is uniquely identified by its name, labelNames and labelValues
342342 */
343- static class SampleKey {
344- String name ;
345- List <String > labelNames ;
346- List <String > labelValues ;
343+ private static class SampleKey {
344+ private final String name ;
345+ private final List <String > labelNames ;
346+ private final List <String > labelValues ;
347347
348- SampleKey (String name , List <String > labelNames , List <String > labelValues ) {
348+ private SampleKey (String name , List <String > labelNames , List <String > labelValues ) {
349349 this .name = name ;
350350 this .labelNames = labelNames ;
351351 this .labelValues = labelValues ;
352352 }
353353
354- static SampleKey of (MetricFamilySamples .Sample sample ) {
354+ private static SampleKey of (MetricFamilySamples .Sample sample ) {
355355 return new SampleKey (sample .name , sample .labelNames , sample .labelValues );
356356 }
357357
@@ -363,8 +363,8 @@ public boolean equals(Object o) {
363363 SampleKey sampleKey = (SampleKey ) o ;
364364
365365 if (name != null ? !name .equals (sampleKey .name ) : sampleKey .name != null ) return false ;
366- if (labelNames != null ? !labelNames .equals (sampleKey .labelNames ) : sampleKey .labelNames != null ) return false ;
367- return labelValues != null ? labelValues .equals (sampleKey .labelValues ) : sampleKey .labelValues == null ;
366+ if (labelValues != null ? !labelValues .equals (sampleKey .labelValues ) : sampleKey .labelValues != null ) return false ;
367+ return labelNames != null ? labelNames .equals (sampleKey .labelNames ) : sampleKey .labelNames == null ;
368368 }
369369
370370 @ Override
@@ -380,7 +380,7 @@ public int hashCode() {
380380 static class Receiver implements JmxScraper .MBeanReceiver {
381381 Map <String , MetricFamilySamples > metricFamilySamplesMap =
382382 new HashMap <String , MetricFamilySamples >();
383- Set <SampleKey > uniqueSampleKeys = new HashSet <SampleKey >();
383+ Set <SampleKey > sampleKeys = new HashSet <SampleKey >();
384384
385385 Config config ;
386386 MatchedRulesCache .StalenessTracker stalenessTracker ;
@@ -406,7 +406,7 @@ void addSample(MetricFamilySamples.Sample sample, Type type, String help) {
406406 metricFamilySamplesMap .put (sample .name , mfs );
407407 }
408408 SampleKey sampleKey = SampleKey .of (sample );
409- boolean exists = uniqueSampleKeys .contains (sampleKey );
409+ boolean exists = sampleKeys .contains (sampleKey );
410410 if (exists ) {
411411 if (LOGGER .isLoggable (Level .FINE )) {
412412 String labels = "{" ;
@@ -418,17 +418,8 @@ void addSample(MetricFamilySamples.Sample sample, Type type, String help) {
418418 }
419419 } else {
420420 mfs .samples .add (sample );
421- uniqueSampleKeys .add (sampleKey );
422- }
423- }
424-
425- private MetricFamilySamples .Sample findExisting (MetricFamilySamples .Sample sample , MetricFamilySamples mfs ) {
426- for (MetricFamilySamples .Sample existing : mfs .samples ) {
427- if (existing .name .equals (sample .name ) && existing .labelValues .equals (sample .labelValues ) && existing .labelNames .equals (sample .labelNames )) {
428- return existing ;
429- }
421+ sampleKeys .add (sampleKey );
430422 }
431- return null ;
432423 }
433424
434425 // Add the matched rule to the cached rules and tag it as not stale
0 commit comments