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

com.github.sadstool.redissonaspectlock.attributes.key.LockKeyProvider Maven / Gradle / Ivy

The newest version!
package com.github.sadstool.redissonaspectlock.attributes.key;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class LockKeyProvider {
    private SpelLockKeyProvider spelLockKeyProvider;
    private LockKeyComponentsProvider lockKeyComponentsProvider;

    public LockKeyProvider(SpelLockKeyProvider spelLockKeyProvider, LockKeyComponentsProvider lockKeyComponentsProvider) {
        this.spelLockKeyProvider = spelLockKeyProvider;
        this.lockKeyComponentsProvider = lockKeyComponentsProvider;
    }

    public List get(String keyDefinition, Method method, Object[] parameterValues) {
        String key = spelLockKeyProvider.get(keyDefinition, method, parameterValues);
        List components = lockKeyComponentsProvider.get(method.getParameters(), parameterValues);

        return Stream.of(Collections.singleton(key), components)
                .flatMap(Collection::stream)
                .filter(Objects::nonNull)
                .filter(string -> !string.isEmpty())
                .collect(Collectors.toList());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy