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

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

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

import org.khasanof.annotation.methods.HandleDocument;
import org.khasanof.config.ApplicationConstants;
import org.khasanof.enums.scopes.DocumentScope;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.meta.api.objects.Document;

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

/**
 * @author Nurislom
 * @see org.khasanof.executors.matcher
 * @since 28.06.2023 10:27
 */
@Component
public class SimpleDocumentMatcher extends GenericMatcher {

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

    {
        setFunctionMap();
    }

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

    @Override
    public boolean matcher(HandleDocument annotation, Document 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 HandleDocument.class;
    }

    private void setFunctionMap() {
        biFunctionMap.put(DocumentScope.FILE_NAME, Document::getFileName);
        biFunctionMap.put(DocumentScope.MIME_TYPE, Document::getMimeType);
        biFunctionMap.put(DocumentScope.FILE_SIZE, Document::getFileSize);
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy