All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wildfly.clustering.infinispan.client.near.SimpleKeyWeigher Maven / Gradle / Ivy

/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package org.wildfly.clustering.infinispan.client.near;

import java.util.function.Predicate;

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

/**
 * Weigher that only considers keys passing a given predicate.
 * @author Paul Ferraro
 */
public class SimpleKeyWeigher implements Weigher {
    private final Predicate evictable;

    public SimpleKeyWeigher(Predicate evictable) {
        this.evictable = evictable;
    }

    @Override
    public int weigh(Object key, Object value) {
        return this.evictable.test(key) ? 1 : 0;
    }
}