Skip to content

Commit f56dc72

Browse files
author
Ľudovít Lučenič
committed
second parameter (pad length) of dec2hex function made optional, added compensation for zero value of this parameter (ignored, used default value of one instead)
Signed-off-by: Ľudovít Lučenič <[email protected]>
1 parent f6101f6 commit f56dc72

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<groupId>sk.digitalorchestra.graylog.plugins</groupId>
1111
<artifactId>graylog-plugin-hexdec-functions</artifactId>
12-
<version>1.1.0</version>
12+
<version>1.1.1</version>
1313
<packaging>jar</packaging>
1414

1515
<name>${project.artifactId}</name>
@@ -216,4 +216,8 @@
216216
</plugin>
217217
</plugins>
218218
</build>
219+
<organization>
220+
<name>Digital Orchestra, s.r.o.</name>
221+
<url>www.digital-orchestra.sk</url>
222+
</organization>
219223
</project>

src/main/java/sk/digitalorchestra/graylog/plugins/hexdec/Dec2HexFunction.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public class Dec2HexFunction extends AbstractFunction<String> {
2525

2626
private final ParameterDescriptor<Long, Long> lenParam = ParameterDescriptor
2727
.integer(PARAM_LEN)
28-
.description("Result string length. Result will be padded with leading zeroes to have at least len length. The sign of the parameter value is ignored. Defaults to 1.")
28+
.optional()
29+
.description("Result string length. Result will be padded with leading zeroes to have at least len length. " +
30+
"The sign of the parameter value is ignored. Defaults to 1, even if parameter is 0.")
2931
.build();
3032

3133
@Override
@@ -34,8 +36,10 @@ public String evaluate(FunctionArgs functionArgs, EvaluationContext evaluationCo
3436
Optional<Long> numLength = lenParam.optional(functionArgs, evaluationContext);
3537

3638
if (number == null) return null;
37-
38-
return String.format("%0" + String.valueOf(Math.abs(numLength.orElse(1L))) + "x", number);
39+
40+
String length = String.valueOf(Math.abs(numLength.orElse(1L)));
41+
42+
return String.format("%0" + (length == "0" ? "1" : length) + "x", number);
3943
}
4044

4145
@Override

src/main/java/sk/digitalorchestra/graylog/plugins/hexdec/HexDecFunctionsMetaData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public URI getURL() {
3737
@Override
3838
public Version getVersion() {
3939
return Version.fromPluginProperties(getClass(), PLUGIN_PROPERTIES, "version",
40-
Version.from(1, 1, 0));
40+
Version.from(1, 0, 0, "SNAPSHOT"));
4141
}
4242

4343
@Override

0 commit comments

Comments
 (0)