--- /dev/null 2016-02-08 00:02:26.507791838 +0300 +++ new/test/gc/g1/plab/lib/PlabInfo.java 2016-03-18 18:05:47.996086694 +0300 @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package gc.g1.plab.lib; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class PlabInfo { + + private final Map plabInfo; + + public PlabInfo() { + plabInfo = new HashMap<>(); + } + + private PlabInfo(Map map) { + plabInfo = new HashMap<>(map); + } + + /** + * Add key and value to underlying Map. + * @param key PLAB info field name + * @param value PLAB info value for field + */ + public void put(String key, long value) { + plabInfo.put(key, value); + } + + /** + * Get stream of Map.Entry representing underlying Map with PLAB information. + */ + public Stream> entryStream() { + return plabInfo.entrySet().stream(); + } + + /** + * Returns the PlabInfo narrowed for the given fields only + * @param fields + * @return PlabInfo + */ + public PlabInfo filter(List fields) { + return new PlabInfo(entryStream() + .filter(field -> fields.contains(field.getKey())) + .collect(Collectors.toMap( + item -> item.getKey(), + item -> item.getValue()) + ) + ); + } + + /** + * Checks if statistic contains expected fields. + * @param fields fields which should be in statistic + * @return true if all fields are in statistic, false otherwise + */ + public boolean checkFields(List fields) { + for (String key : fields) { + if (!plabInfo.containsKey(key)) { + return false; + } + } + return true; + } + + /** + * Return a collection of the values. + * @return collection of values + */ + public Collection values() { + return plabInfo.values(); + } + + /** + * Get value for specified field. + * @param field + * @return long value which is contained in specified field + */ + public long get(String field) { + return plabInfo.get(field); + } +}