<commit_before>/*
 * Copyright Terracotta, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.ehcache;

/**
 * Basic interface to a cache, defines all operational methods to crete, access,
 * update or delete mappings of key to value
 *
 * @param <K> the type of the keys used to access data within this cache
 * @param <V> the type of the values held within this cache
 */
public interface Cache<K, V> extends Iterable<Cache.Entry<K,V>> {

  /**
   * Retrieve the value currently mapped to the provided key
   *
   * @param key the key to query the value for
   * @return the value mapped to the key, null if none
   *
   * @throws java.lang.NullPointerException if the provided key is null
   */
  V get(K key);

  /**
   * Associates the provided value to the given key
   *
   * @param key the key, may not be null
   * @param value the value, may not be null
   *
   * @throws java.lang.NullPointerException if either key or value is null
   */
  void put(K key, V value);

  /**
   * Checks whether a mapping for the given key is present, without retrieving the associated value
   *
   * @param key the key
   * @return true if a mapping is present, false otherwise
   *
   * @throws java.lang.NullPointerException if the provided key is null
   */
  boolean containsKey(K key);

  /**
   * Removes the value, if any, associated with the provided key
   *
   * @param key the key to remove the value for
   *
   * @throws java.lang.NullPointerException if the provided key is null
   */
  void remove(K key);

  /**
   * Removes all mapping currently present in the Cache. This is not an atomic operation and can be very costly operation as well...
   */
  void clear();

  /**
   * If the provided key is not associated with a value, then associate it with the provided value.
   * 
   * @param key the key to be associated with
   * @param value the value to associate
   * @return the value that was associated with the key, or {@code null} if none
   * 
   * @throws NullPointerException if either key or value is null
   */
  V putIfAbsent(K key, V value);

  /**
   * If the provided key is associated with the provided value then remove the entry.
   * 
   * @param key the key to remove
   * @param value the value to check against
   * @return {@code true} if the entry was removed
   * 
   * @throws NullPointerException if either key or value is null
   */
  boolean remove(K key, V value);

  /**
   * If the provided key is associated with a value, then replace that value with the provided value.
   * 
   * @param key the key to be associated with
   * @param value the value to associate
   * @return the value that was associated with the key, or {@code null} if none
   * 
   * @throws NullPointerException if either key or value is null
   */
  V replace(K key, V value) throws NullPointerException;
  
  /**
   * If the provided key is associated with {@code oldValue}, then replace that value with {@code newValue}.
   * 
   * @param key the key to be associated with
   * @param oldValue the value to check against
   * @param newValue the value to associate
   * @return {@code true} if the value was replaced
   * 
   * @throws NullPointerException if any of the values, or the key is null<commit_msg>#24 standardize on not declaring throws NPE [PR feedback]<commit_after>/*
 * Copyright Terracotta, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.ehcache;

/**
 * Basic interface to a cache, defines all operational methods to crete, access,
 * update or delete mappings of key to value
 *
 * @param <K> the type of the keys used to access data within this cache
 * @param <V> the type of the values held within this cache
 */
public interface Cache<K, V> extends Iterable<Cache.Entry<K,V>> {

  /**
   * Retrieve the value currently mapped to the provided key
   *
   * @param key the key to query the value for
   * @return the value mapped to the key, null if none
   *
   * @throws java.lang.NullPointerException if the provided key is null
   */
  V get(K key);

  /**
   * Associates the provided value to the given key
   *
   * @param key the key, may not be null
   * @param value the value, may not be null
   *
   * @throws java.lang.NullPointerException if either key or value is null
   */
  void put(K key, V value);

  /**
   * Checks whether a mapping for the given key is present, without retrieving the associated value
   *
   * @param key the key
   * @return true if a mapping is present, false otherwise
   *
   * @throws java.lang.NullPointerException if the provided key is null
   */
  boolean containsKey(K key);

  /**
   * Removes the value, if any, associated with the provided key
   *
   * @param key the key to remove the value for
   *
   * @throws java.lang.NullPointerException if the provided key is null
   */
  void remove(K key);

  /**
   * Removes all mapping currently present in the Cache. This is not an atomic operation and can be very costly operation as well...
   */
  void clear();

  /**
   * If the provided key is not associated with a value, then associate it with the provided value.
   * 
   * @param key the key to be associated with
   * @param value the value to associate
   * @return the value that was associated with the key, or {@code null} if none
   * 
   * @throws NullPointerException if either key or value is null
   */
  V putIfAbsent(K key, V value);

  /**
   * If the provided key is associated with the provided value then remove the entry.
   * 
   * @param key the key to remove
   * @param value the value to check against
   * @return {@code true} if the entry was removed
   * 
   * @throws NullPointerException if either key or value is null
   */
  boolean remove(K key, V value);

  /**
   * If the provided key is associated with a value, then replace that value with the provided value.
   * 
   * @param key the key to be associated with
   * @param value the value to associate
   * @return the value that was associated with the key, or {@code null} if none
   * 
   * @throws NullPointerException if either key or value is null
   */
  V replace(K key, V value);
  
  /**
   * If the provided key is associated with {@code oldValue}, then replace that value with {@code newValue}.
   * 
   * @param key the key to be associated with
   * @param oldValue the value to check against
   * @param newValue the value to associate
   * @return {@code true} if the value was replaced
   * 
   * @throws NullPointerException if any of the values, or the key is null
{'fraction_non_alphanumeric': 0.07364649681528662, 'fraction_numerical': 0.001326963906581741, 'mean_word_length': 3.015450186467768, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4215487', 'n_tokens_mistral': 2060, 'n_tokens_neox': 2015, 'n_words': 1067}