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

org.graylog2.grok.GrokPatterns Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
/**
 * This file is part of Graylog.
 *
 * Graylog is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Graylog 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
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Graylog.  If not, see .
 */
package org.graylog2.grok;

import com.google.common.base.Strings;
import com.google.common.collect.Sets;
import org.bson.types.ObjectId;
import org.graylog2.rest.models.system.responses.GrokPatternSummary;

import java.util.Collection;
import java.util.Set;

public class GrokPatterns {
    public static GrokPatternSummary toSummary(GrokPattern grokPattern) {
        final GrokPatternSummary summary = new GrokPatternSummary();

        summary.id = grokPattern.id.toHexString();
        summary.name = grokPattern.name;
        summary.pattern = grokPattern.pattern;

        return summary;
    }

    public static Set toSummarySet(Set patternSet) {
        final Set result = Sets.newHashSetWithExpectedSize(patternSet.size());

        for (GrokPattern grokPattern : patternSet) {
            result.add(toSummary(grokPattern));
        }

        return result;
    }

    public static GrokPattern fromSummary(GrokPatternSummary grokPatternSummary) {
        final GrokPattern result = new GrokPattern();
        if (!Strings.isNullOrEmpty(grokPatternSummary.id))
            result.id = new ObjectId(grokPatternSummary.id);
        result.name = grokPatternSummary.name;
        result.pattern = grokPatternSummary.pattern;

        return result;
    }

    public static Set fromSummarySet(Collection grokPatternSummaries) {
        final Set result = Sets.newHashSetWithExpectedSize(grokPatternSummaries.size());
        for (GrokPatternSummary summary : grokPatternSummaries) {
            result.add(fromSummary(summary));
        }

        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy