|
| 1 | +/** |
| 2 | + * This file is part of Graylog Pipeline Processor. |
| 3 | + * |
| 4 | + * Graylog Pipeline Processor is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * Graylog Pipeline Processor is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with Graylog Pipeline Processor. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | +package org.graylog.plugins.pipelineprocessor.functions.strings; |
| 18 | + |
| 19 | +import com.google.common.base.Strings; |
| 20 | +import org.graylog.plugins.pipelineprocessor.EvaluationContext; |
| 21 | +import org.graylog.plugins.pipelineprocessor.ast.functions.AbstractFunction; |
| 22 | +import org.graylog.plugins.pipelineprocessor.ast.functions.FunctionArgs; |
| 23 | +import org.graylog.plugins.pipelineprocessor.ast.functions.FunctionDescriptor; |
| 24 | +import org.graylog.plugins.pipelineprocessor.ast.functions.ParameterDescriptor; |
| 25 | + |
| 26 | +import static com.google.common.collect.ImmutableList.of; |
| 27 | + |
| 28 | +public class Concat extends AbstractFunction<String> { |
| 29 | + public static final String NAME = "concat"; |
| 30 | + private final ParameterDescriptor<String, String> firstParam; |
| 31 | + private final ParameterDescriptor<String, String> secondParam; |
| 32 | + |
| 33 | + public Concat() { |
| 34 | + firstParam = ParameterDescriptor.string("first").build(); |
| 35 | + secondParam = ParameterDescriptor.string("second").build(); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public String evaluate(FunctionArgs args, EvaluationContext context) { |
| 40 | + final String first = Strings.nullToEmpty(firstParam.required(args, context)); |
| 41 | + final String second = Strings.nullToEmpty(secondParam.required(args, context)); |
| 42 | + |
| 43 | + return first.concat(second); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public FunctionDescriptor<String> descriptor() { |
| 48 | + return FunctionDescriptor.<String>builder() |
| 49 | + .name(NAME) |
| 50 | + .returnType(String.class) |
| 51 | + .params(of(firstParam, secondParam)) |
| 52 | + .build(); |
| 53 | + } |
| 54 | +} |
0 commit comments