class JmxMBeanPropertyCache {
    private static final Pattern PROPERTY_PATTERN =
            Pattern.compile(
                    "([^,=:\\*\\?]+)"
                            + // Name - non-empty, anything but comma, equals, colon, star, or
                            // question mark
                            "="
                            + // Equals
                            "("
                            + // Either
                            "\""
                            + // Quoted
                            "(?:"
                            + // A possibly empty sequence of
                            "[^\\\\\"]*"
                            + // Greedily match anything but backslash or quote
                            "(?:\\\\.)?"
                            + // Greedily see if we can match an escaped sequence
                            ")*"
                            + "\""
                            + "|"
                            + // Or
                            "[^,=:\"]*"
                            + // Unquoted - can be empty, anything but comma, equals, colon, or
                            // quote
                            ")");

    // Implement a version of ObjectName.getKeyPropertyList that returns the
    // properties in the ordered they were added (the ObjectName stores them
    // in the order they were added).
    private final Map<ObjectName, LinkedHashMap<String, String>> keyPropertiesPerBean;

    public JmxMBeanPropertyCache() {
        this.keyPropertiesPerBean = new ConcurrentHashMap<>();
    }

    Map<ObjectName, LinkedHashMap<String, String>> getKeyPropertiesPerBean() {
        return keyPropertiesPerBean;
    }

    public LinkedHashMap<String, String> getKeyPropertyList(ObjectName mbeanName) {
        LinkedHashMap<String, String> keyProperties = keyPropertiesPerBean.get(mbeanName);
        if (keyProperties == null) {
            keyProperties = new LinkedHashMap<>();
            String properties = mbeanName.getKeyPropertyListString();
            Matcher match = PROPERTY_PATTERN.matcher(properties);
            while (match.lookingAt()) {
                keyProperties.put(match.group(1), match.group(2));
                properties = properties.substring(match.end());
                if (properties.startsWith(",")) {
                    properties = properties.substring(1);
                }
                match.reset(properties);
            }
            keyPropertiesPerBean.put(mbeanName, keyProperties);
        }
        return keyProperties;
    }

    public void onlyKeepMBeans(Set<ObjectName> latestBeans) {<FILL_FUNCTION_BODY>}
}

        for (ObjectName prevName : keyPropertiesPerBean.keySet()) {
            if (!latestBeans.contains(prevName)) {
                keyPropertiesPerBean.remove(prevName);
            }
        }
    
<no_super_class>