keycloakjar.com.github.benmanes.caffeine.cache.Weigher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of camunda-platform-7-keycloak-all Show documentation
Show all versions of camunda-platform-7-keycloak-all Show documentation
Camunda 7 Keycloak Identity Provider Plugin including all transitive dependencies
/*
* Copyright 2014 Ben Manes. All Rights Reserved.
*
* 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 com.github.benmanes.caffeine.cache;
import static com.github.benmanes.caffeine.cache.Caffeine.requireArgument;
import static java.util.Objects.requireNonNull;
import java.io.Serializable;
import org.checkerframework.checker.index.qual.NonNegative;
/**
* Calculates the weights of cache entries. The total weight threshold is used to determine when an
* eviction is required.
*
* @param the type of keys
* @param the type of values
* @author [email protected] (Ben Manes)
*/
@FunctionalInterface
public interface Weigher {
/**
* Returns the weight of a cache entry. There is no unit for entry weights; rather they are simply
* relative to each other.
*
* @param key the key to weigh
* @param value the value to weigh
* @return the weight of the entry; must be non-negative
*/
@NonNegative
int weigh(K key, V value);
/**
* Returns a weigher where an entry has a weight of {@code 1}.
*
* @param the type of keys
* @param the type of values
* @return a weigher where an entry has a weight of {@code 1}
*/
static Weigher singletonWeigher() {
@SuppressWarnings("unchecked")
Weigher instance = (Weigher) SingletonWeigher.INSTANCE;
return instance;
}
/**
* Returns a weigher that enforces that the weight is non-negative.
*
* @param delegate the weigher to weighs the entry
* @param the type of keys
* @param the type of values
* @return a weigher that enforces that the weight is non-negative
*/
static Weigher boundedWeigher(Weigher delegate) {
return new BoundedWeigher<>(delegate);
}
}
enum SingletonWeigher implements Weigher