org.graylog.plugins.pipelineprocessor.ast.functions.FunctionDescriptor Maven / Gradle / Ivy
/*
* 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.pipelineprocessor.ast.functions;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import javax.annotation.Nullable;
@AutoValue
@JsonAutoDetect
public abstract class FunctionDescriptor {
@JsonProperty
public abstract String name();
@JsonProperty
public abstract boolean pure();
@JsonProperty
public abstract Class returnType();
@JsonProperty
public abstract ImmutableList params();
@JsonIgnore
public abstract ImmutableMap paramMap();
@JsonIgnore
public ParameterDescriptor param(String name) {
return paramMap().get(name);
}
@JsonProperty
@Nullable
public abstract String description();
public static Builder builder() {
//noinspection unchecked
return new AutoValue_FunctionDescriptor.Builder().pure(false);
}
@AutoValue.Builder
public static abstract class Builder {
abstract FunctionDescriptor autoBuild();
public FunctionDescriptor build() {
return paramMap(Maps.uniqueIndex(params(), ParameterDescriptor::name))
.autoBuild();
}
public abstract Builder name(String name);
public abstract Builder pure(boolean pure);
public abstract Builder returnType(Class type);
public Builder params(ParameterDescriptor... params) {
return params(ImmutableList.builder().add(params).build());
}
public abstract Builder params(ImmutableList params);
public abstract Builder paramMap(ImmutableMap map);
public abstract ImmutableList params();
public abstract Builder description(@Nullable String description);
}
}