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

org.graylog.plugins.threatintel.functions.GenericLookupResult Maven / Gradle / Ivy

There is a newer version: 6.1.4
Show newest version
/*
 * Copyright (C) 2020 Graylog, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the Server Side Public License, version 1,
 * as published by MongoDB, Inc.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * Server Side Public License for more details.
 *
 * You should have received a copy of the Server Side Public License
 * along with this program. If not, see
 * .
 */
package org.graylog.plugins.threatintel.functions;

import com.google.common.collect.ForwardingMap;
import com.google.common.collect.ImmutableMap;

import java.util.Map;

public class GenericLookupResult extends ForwardingMap {

    public static final String RESULTS_KEY = "threat_indicated";

    private final ImmutableMap results;

    public static final GenericLookupResult FALSE = new FalseGenericLookupResult();
    public static final GenericLookupResult TRUE = new TrueGenericLookupResult();

    private GenericLookupResult(ImmutableMap fields) {
        this.results = fields;
    }

    public Map getResults() {
        return results;
    }

    public boolean isMatch() {
        return ((boolean) getResults().get(RESULTS_KEY));
    }

    @Override
    protected Map delegate() {
        return getResults();
    }

    private static class FalseGenericLookupResult extends GenericLookupResult {
        private static final ImmutableMap FALSE = ImmutableMap.builder()
                .put(RESULTS_KEY, false)
                .build();

        private FalseGenericLookupResult() {
            super(FALSE);
        }
    }

    private static class TrueGenericLookupResult extends GenericLookupResult {
        private static final ImmutableMap TRUE = ImmutableMap.builder()
                .put(RESULTS_KEY, true)
                .build();

        private TrueGenericLookupResult() {
            super(TRUE);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy