SeriesHelper { static Double getLast( final List<Series> series, final Tag... tags ) { Double result = null; for ( Series s : series ) { boolean match = true; for ( int i = 0; i < tags.length && match; i++ ) { String k = s.getTags().get( tags[i].getName() ); if ( k == null || !k.equalsIgnoreCase( tags[i].getValue() ) ) { match = false; } } if ( match ) { result = s.getValues().get( s.getValues().size() - 1 )[1]; break; } } return result; } private  SeriesHelper(); static double getAvg( final List<Series> series, final Tag... tags ); static Set<String> getTagValues( final List<Series> series, String tag );  }
@Test public void testGetLast() { final List<Series> cpuSeries = rhMetrics.getSeriesByType( SeriesBatch.SeriesType.CPU ); assertEquals( 0.7833333333333333, SeriesHelper.getLast( cpuSeries, new Tag( "type", "system" ) ), 0.0000001 ); assertEquals( 1.9333333333333333, SeriesHelper.getLast( cpuSeries, new Tag( "type", "user" ) ), 0.0000001 ); final List<Series> netSeries = rhMetrics.getSeriesByType( SeriesBatch.SeriesType.NET ); assertEquals( 36114.6, SeriesHelper.getLast( netSeries, new Tag( "iface", "eth0" ), new Tag( "type", "in" ) ), 0.0000001 ); final List<Series> diskSeries = rhMetrics.getSeriesByType( SeriesBatch.SeriesType.DISK ); Double available = SeriesHelper.getLast( diskSeries, new Tag( "mount", "/" ), new Tag( "type", "available" ) ); assertEquals( 3.00056576e+08, available, 0.0000001 ); Double used = SeriesHelper.getLast( diskSeries, new Tag( "mount", "/" ), new Tag( "type", "used" ) ); assertEquals( 6.52783616e+08, used, 0.0000001 ); Double total = SeriesHelper.getLast( diskSeries, new Tag( "mount", "/" ), new Tag( "type", "total" ) ); assertEquals( 1.02330368e+09, total, 0.0000001 ); available = SeriesHelper.getLast( diskSeries, new Tag( "mount", "/mnt" ), new Tag( "type", "available" ) ); assertEquals( 1.01273182208e+11, available, 0.0000001 ); used = SeriesHelper.getLast( diskSeries, new Tag( "mount", "/mnt" ), new Tag( "type", "used" ) ); assertEquals( 5.54901504e+09, used, 0.0000001 ); total = SeriesHelper.getLast( diskSeries, new Tag( "mount", "/mnt" ), new Tag( "type", "total" ) ); assertEquals( 1.073741824e+11, total, 0.0000001 ); assertNull( SeriesHelper .getLast( new ArrayList<Series>(), new Tag( "mount", "/mnt" ), new Tag( "type", "available" ) ) ); }