From d71fdfebd6f838133ef9869bc0e939c3cc176698 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Sun, 25 Oct 2020 11:00:09 +0100 Subject: [PATCH 1/4] add short date formatter. fixes #6579 --- CHANGELOG.md | 1 + .../org/jabref/logic/layout/LayoutEntry.java | 3 +++ .../layout/format/ShortMonthFormatter.java | 20 ++++++++++++++++ .../format/ShortMonthFormatterTest.java | 24 +++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java create mode 100644 src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 55d21265e7d..97c4788b3c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve to the page field for cases where the page numbers are missing. [#7019](https://github.com/JabRef/jabref/issues/7019) - We added a new fetcher to enable users to search jstor.org [#6627](https://github.com/JabRef/jabref/issues/6627) - We added an error message in the New Entry dialog that is shown in case the fetcher did not find anything . [#7000](https://github.com/JabRef/jabref/issues/7000) +- We added a new formatter to output shorthand month format. [#6579](https://github.com/JabRef/jabref/issues/6579) ### Changed diff --git a/src/main/java/org/jabref/logic/layout/LayoutEntry.java b/src/main/java/org/jabref/logic/layout/LayoutEntry.java index 8a1f6e7349f..658232eb72d 100644 --- a/src/main/java/org/jabref/logic/layout/LayoutEntry.java +++ b/src/main/java/org/jabref/logic/layout/LayoutEntry.java @@ -74,6 +74,7 @@ import org.jabref.logic.layout.format.RisAuthors; import org.jabref.logic.layout.format.RisKeywords; import org.jabref.logic.layout.format.RisMonth; +import org.jabref.logic.layout.format.ShortMonthFormatter; import org.jabref.logic.layout.format.ToLowerCase; import org.jabref.logic.layout.format.ToUpperCase; import org.jabref.logic.layout.format.WrapContent; @@ -542,6 +543,8 @@ private LayoutFormatter getLayoutFormatterByName(String name) { return new MarkdownFormatter(); case "CSLType": return new CSLType(); + case "ShortMonth": + return new ShortMonthFormatter(); default: return null; } diff --git a/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java b/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java new file mode 100644 index 00000000000..56322cdead3 --- /dev/null +++ b/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java @@ -0,0 +1,20 @@ +package org.jabref.logic.layout.format; + +import java.util.Optional; + +import org.jabref.logic.layout.ParamLayoutFormatter; +import org.jabref.model.entry.Month; + +public class ShortMonthFormatter implements ParamLayoutFormatter { + + @Override + public void setArgument(String arg) { + // no effect + } + + @Override + public String format(String fieldText) { + Optional month = Month.parse(fieldText); + return month.map(Month::getShortName).orElse(""); + } +} diff --git a/src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java b/src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java new file mode 100644 index 00000000000..a1966e2b4d4 --- /dev/null +++ b/src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java @@ -0,0 +1,24 @@ +package org.jabref.logic.layout.format; + +import org.jabref.logic.layout.ParamLayoutFormatter; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ShortMonthFormatterTest { + + private ParamLayoutFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new ShortMonthFormatter(); + } + + @Test + public void testFormat() { + assertEquals("jan", formatter.format("01")); + assertEquals("jan", formatter.format("Januar")); + } +} From 5224281360297d90aeb91361a18c3db8c8c885d4 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 28 Oct 2020 10:55:48 +0100 Subject: [PATCH 2/4] Update src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java Co-authored-by: Christoph --- .../org/jabref/logic/layout/format/ShortMonthFormatter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java b/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java index 56322cdead3..f05b56d65d7 100644 --- a/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java +++ b/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java @@ -5,7 +5,7 @@ import org.jabref.logic.layout.ParamLayoutFormatter; import org.jabref.model.entry.Month; -public class ShortMonthFormatter implements ParamLayoutFormatter { +public class ShortMonthFormatter implements LayoutFormatter { @Override public void setArgument(String arg) { From 1930ed91acc04299f736f5a2acc2ff95dc0bda3f Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 28 Oct 2020 11:01:26 +0100 Subject: [PATCH 3/4] remove setArgument --- src/main/java/org/jabref/logic/layout/LayoutEntry.java | 3 +++ .../org/jabref/logic/layout/format/ShortMonthFormatter.java | 5 ----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/logic/layout/LayoutEntry.java b/src/main/java/org/jabref/logic/layout/LayoutEntry.java index 658232eb72d..05d96248699 100644 --- a/src/main/java/org/jabref/logic/layout/LayoutEntry.java +++ b/src/main/java/org/jabref/logic/layout/LayoutEntry.java @@ -543,8 +543,11 @@ private LayoutFormatter getLayoutFormatterByName(String name) { return new MarkdownFormatter(); case "CSLType": return new CSLType(); +<<<<<<< HEAD case "ShortMonth": return new ShortMonthFormatter(); +======= +>>>>>>> a1107ed890bb562ca6f5b64f26ae7aecceb6f92d default: return null; } diff --git a/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java b/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java index f05b56d65d7..0fea391e03c 100644 --- a/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java +++ b/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java @@ -7,11 +7,6 @@ public class ShortMonthFormatter implements LayoutFormatter { - @Override - public void setArgument(String arg) { - // no effect - } - @Override public String format(String fieldText) { Optional month = Month.parse(fieldText); From 7fea856a8eae9d1cb474fbd2a176254a58d79da4 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 28 Oct 2020 11:28:04 +0100 Subject: [PATCH 4/4] fixing imports --- src/main/java/org/jabref/logic/layout/LayoutEntry.java | 3 --- .../org/jabref/logic/layout/format/ShortMonthFormatter.java | 2 +- .../jabref/logic/layout/format/ShortMonthFormatterTest.java | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/logic/layout/LayoutEntry.java b/src/main/java/org/jabref/logic/layout/LayoutEntry.java index 05d96248699..658232eb72d 100644 --- a/src/main/java/org/jabref/logic/layout/LayoutEntry.java +++ b/src/main/java/org/jabref/logic/layout/LayoutEntry.java @@ -543,11 +543,8 @@ private LayoutFormatter getLayoutFormatterByName(String name) { return new MarkdownFormatter(); case "CSLType": return new CSLType(); -<<<<<<< HEAD case "ShortMonth": return new ShortMonthFormatter(); -======= ->>>>>>> a1107ed890bb562ca6f5b64f26ae7aecceb6f92d default: return null; } diff --git a/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java b/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java index 0fea391e03c..63bef135801 100644 --- a/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java +++ b/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java @@ -2,7 +2,7 @@ import java.util.Optional; -import org.jabref.logic.layout.ParamLayoutFormatter; +import org.jabref.logic.layout.LayoutFormatter; import org.jabref.model.entry.Month; public class ShortMonthFormatter implements LayoutFormatter { diff --git a/src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java b/src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java index a1966e2b4d4..bcd17b9e518 100644 --- a/src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java +++ b/src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java @@ -1,6 +1,6 @@ package org.jabref.logic.layout.format; -import org.jabref.logic.layout.ParamLayoutFormatter; +import org.jabref.logic.layout.LayoutFormatter; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -9,7 +9,7 @@ public class ShortMonthFormatterTest { - private ParamLayoutFormatter formatter; + private LayoutFormatter formatter; @BeforeEach public void setUp() {