@SuppressWarnings("unchecked")
    public <T> SortedMap<String, T> getAll(Pattern regex) {
        if (regex == null) {
            throw new IllegalArgumentException("null regex");
        } 
        SortedMap<String, T> subMap = new TreeMap<>();
        for (String key : entries.keySet()) {
            if (regex.matcher(key).matches()) {
                subMap.put(key, (T) entries.get(key).currentValue);
            }
        }
        return subMap;
    }