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

org.khasanof.executors.matcher.SimpleVideoNoteMatcher Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
package org.khasanof.executors.matcher;

import org.khasanof.annotation.methods.HandleVideoNote;
import org.khasanof.config.ApplicationConstants;
import org.khasanof.enums.scopes.VideoNoteScope;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.meta.api.objects.VideoNote;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

/**
 * @author Nurislom
 * @see org.khasanof.executors.matcher
 * @since 09.07.2023 16:47
 */
@Component
public class SimpleVideoNoteMatcher extends GenericMatcher {

    private final Map> biFunctionMap = new HashMap<>();

    {
        setBiFunctionMap();
    }

    public SimpleVideoNoteMatcher() {
        super(ApplicationConstants.MATCHER_MAP);
    }

    @Override
    public boolean matcher(HandleVideoNote annotation, VideoNote value) {
        Object apply = biFunctionMap.get(annotation.scope()).apply(value);
        return matchFunctions.get(Map.entry(annotation.match(), getScopeType(apply, annotation.match())))
                .apply(annotation.value(), apply);
    }

    @Override
    public Class getType() {
        return HandleVideoNote.class;
    }

    void setBiFunctionMap() {
        biFunctionMap.put(VideoNoteScope.DURATION, VideoNote::getDuration);
        biFunctionMap.put(VideoNoteScope.FILE_SIZE, VideoNote::getFileSize);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy