From e13bf66bd94ac9bf4aa2b85c8c21fd1b5c143e4f Mon Sep 17 00:00:00 2001 From: jk KPADEY Date: Fri, 26 Feb 2021 23:15:54 +0100 Subject: [PATCH] Fixed the ArrayOutOfBoundException happening for the north direction Signed-off-by: jk KPADEY --- .../src/main/java/io/github/mivek/utils/Converter.java | 2 +- .../test/java/io/github/mivek/utils/DegreesToDirectionTest.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/metarParser-commons/src/main/java/io/github/mivek/utils/Converter.java b/metarParser-commons/src/main/java/io/github/mivek/utils/Converter.java index 3ba26e53..f5d81999 100644 --- a/metarParser-commons/src/main/java/io/github/mivek/utils/Converter.java +++ b/metarParser-commons/src/main/java/io/github/mivek/utils/Converter.java @@ -36,7 +36,7 @@ public static String degreesToDirection(final String degreesStr) { return Messages.getInstance().getString("Converter.VRB"); } - return Messages.getInstance().getString("Converter." + DIRECTIONS[(int) ((degrees + 11.5) / 22.5)]); + return Messages.getInstance().getString("Converter." + DIRECTIONS[(int) ((degrees + 11.5) / 22.5) % DIRECTIONS.length]); } /** diff --git a/metarParser-commons/src/test/java/io/github/mivek/utils/DegreesToDirectionTest.java b/metarParser-commons/src/test/java/io/github/mivek/utils/DegreesToDirectionTest.java index 38ab928a..d9721115 100644 --- a/metarParser-commons/src/test/java/io/github/mivek/utils/DegreesToDirectionTest.java +++ b/metarParser-commons/src/test/java/io/github/mivek/utils/DegreesToDirectionTest.java @@ -34,6 +34,7 @@ public static Collection data() { { "Converter.SW", "230" }, { "Converter.N", "2" }, { "Converter.NNW", "345" }, + { "Converter.N", "350" }, {"Converter.VRB","anyString"} }); }