<commit_before>/*
 * This file is part of memoization.java. It is subject to the license terms in the LICENSE file found in the top-level
 * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of memoization.java,
 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
 * in the LICENSE file.
 */
package de.xn__ho_hia.memoization.caffeine;

import java.util.Objects;
import java.util.function.Function;

import com.github.benmanes.caffeine.cache.Cache;

import de.xn__ho_hia.quality.suppression.CompilerWarnings;

abstract class AbstractCaffeineBasedMemoizer<KEY, VALUE> {

    private final Cache<KEY, VALUE> cache;

    @SuppressWarnings(CompilerWarnings.NLS)
    AbstractCaffeineBasedMemoizer(final Cache<KEY, VALUE> cache) {
        this.cache = Objects.requireNonNull(cache, "Cannot use a NULL cache - provide an actual cache to fix this.");
    }

    protected final VALUE get(final KEY key, final Function<KEY, VALUE> mappingFunction) {
        return cache.get(key, mappingFunction);<commit_msg>explicitly check for null-pointer dereference<commit_after>/*
 * This file is part of memoization.java. It is subject to the license terms in the LICENSE file found in the top-level
 * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of memoization.java,
 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
 * in the LICENSE file.
 */
package de.xn__ho_hia.memoization.caffeine;

import java.util.Objects;
import java.util.function.Function;

import com.github.benmanes.caffeine.cache.Cache;

import de.xn__ho_hia.quality.suppression.CompilerWarnings;

@SuppressWarnings(CompilerWarnings.NLS)
abstract class AbstractCaffeineBasedMemoizer<KEY, VALUE> {

    private final Cache<KEY, VALUE> cache;

    AbstractCaffeineBasedMemoizer(final Cache<KEY, VALUE> cache) {
        this.cache = Objects.requireNonNull(cache, "Cannot use a NULL cache - provide an actual cache to fix this.");
    }

    protected final VALUE get(final KEY key, final Function<KEY, VALUE> mappingFunction) {
        final VALUE value = cache.get(key, mappingFunction);
        if (value == null) {
            throw new NullPointerException("The calculated value is NULL");
        }
        return value;
{'fraction_non_alphanumeric': 0.085, 'fraction_numerical': 0.0016666666666666668, 'mean_word_length': 4.24235807860262, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6208287', 'n_tokens_mistral': 682, 'n_tokens_neox': 681, 'n_words': 227}