From e484183c582bfa805a4f5eabae8e3c97cacde97e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 26 Jun 2016 09:44:50 +0200 Subject: [PATCH] Switch the order of the arguments --- .../net/pterodactylus/sone/template/ParserFilter.java | 4 ++-- src/main/java/net/pterodactylus/sone/text/Parser.java | 6 +++--- .../java/net/pterodactylus/sone/text/ParserContext.java | 2 +- .../java/net/pterodactylus/sone/text/SoneTextParser.java | 2 +- .../java/net/pterodactylus/sone/web/WebInterface.java | 2 +- .../net/pterodactylus/sone/text/SoneTextParserTest.java | 16 ++++++++-------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java index ac092d8..96d2f72 100644 --- a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java @@ -101,7 +101,7 @@ public class ParserFilter implements Filter { FreenetRequest request = (FreenetRequest) templateContext.get("request"); SoneTextParserContext context = new SoneTextParserContext(request, (Sone) sone); StringWriter parsedTextWriter = new StringWriter(); - Iterable parts = soneTextParser.parse(context, text); + Iterable parts = soneTextParser.parse(text, context); if (length > -1) { int allPartsLength = 0; List shortenedParts = new ArrayList(); @@ -248,7 +248,7 @@ public class ParserFilter implements Filter { private void render(Writer writer, PostPart postPart) { SoneTextParser parser = new SoneTextParser(core, core); SoneTextParserContext parserContext = new SoneTextParserContext(null, postPart.getPost().getSone()); - Iterable parts = parser.parse(parserContext, postPart.getPost().getText()); + Iterable parts = parser.parse(postPart.getPost().getText(), parserContext); StringBuilder excerpt = new StringBuilder(); for (Part part : parts) { excerpt.append(part.getText()); diff --git a/src/main/java/net/pterodactylus/sone/text/Parser.java b/src/main/java/net/pterodactylus/sone/text/Parser.java index ca26a79..67c0632 100644 --- a/src/main/java/net/pterodactylus/sone/text/Parser.java +++ b/src/main/java/net/pterodactylus/sone/text/Parser.java @@ -35,13 +35,13 @@ public interface Parser { /** * Create one or more {@link Part}s from the given text source. * - * @param context - * The parser context (may be {@code null}) * @param source * The text source + * @param context + * The parser context (may be {@code null}) * @return The parsed parts */ @Nonnull - Iterable parse(@Nullable C context, @Nonnull String source); + Iterable parse(@Nonnull String source, @Nullable C context); } diff --git a/src/main/java/net/pterodactylus/sone/text/ParserContext.java b/src/main/java/net/pterodactylus/sone/text/ParserContext.java index da60a72..92ff32a 100644 --- a/src/main/java/net/pterodactylus/sone/text/ParserContext.java +++ b/src/main/java/net/pterodactylus/sone/text/ParserContext.java @@ -20,7 +20,7 @@ package net.pterodactylus.sone.text; /** * Context for the {@link Parser}. This interface needs to be implemented by * {@link Parser}s that need to provide more information than just the text to - * parse to {@link Parser#parse(ParserContext, String)}. + * parse to {@link Parser#parse(String, ParserContext)}. * * @author David ‘Bombe’ Roden */ diff --git a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java index ae299e1..4a6fd0b 100644 --- a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java +++ b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java @@ -122,7 +122,7 @@ public class SoneTextParser implements Parser { */ @Nonnull @Override - public Iterable parse(@Nullable SoneTextParserContext context, @Nonnull String source) { + public Iterable parse(@Nonnull String source, @Nullable SoneTextParserContext context) { PartContainer parts = new PartContainer(); BufferedReader bufferedReader = new BufferedReader(new StringReader(source)); try { diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index cabc44e..5fe5efb 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -793,7 +793,7 @@ public class WebInterface { private Collection getMentionedSones(String text) { /* we need no context to find mentioned Sones. */ Set mentionedSones = new HashSet(); - for (Part part : soneTextParser.parse(null, text)) { + for (Part part : soneTextParser.parse(text, null)) { if (part instanceof SonePart) { mentionedSones.add(((SonePart) part).getSone()); } diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index b630ac5..3b6ac4a 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -53,17 +53,17 @@ public class SoneTextParserTest extends TestCase { Iterable parts; /* check basic operation. */ - parts = soneTextParser.parse(null, "Test."); + parts = soneTextParser.parse("Test.", null); assertNotNull("Parts", parts); assertEquals("Part Text", "Test.", convertText(parts, PlainTextPart.class)); /* check empty lines at start and end. */ - parts = soneTextParser.parse(null, "\nTest.\n\n"); + parts = soneTextParser.parse("\nTest.\n\n", null); assertNotNull("Parts", parts); assertEquals("Part Text", "Test.", convertText(parts, PlainTextPart.class)); /* check duplicate empty lines in the text. */ - parts = soneTextParser.parse(null, "\nTest.\n\n\nTest."); + parts = soneTextParser.parse("\nTest.\n\n\nTest.", null); assertNotNull("Parts", parts); assertEquals("Part Text", "Test.\n\nTest.", convertText(parts, PlainTextPart.class)); } @@ -80,17 +80,17 @@ public class SoneTextParserTest extends TestCase { Iterable parts; /* check basic links. */ - parts = soneTextParser.parse(null, "KSK@gpl.txt"); + parts = soneTextParser.parse("KSK@gpl.txt", null); assertNotNull("Parts", parts); assertEquals("Part Text", "[KSK@gpl.txt|gpl.txt|gpl.txt]", convertText(parts, FreenetLinkPart.class)); /* check embedded links. */ - parts = soneTextParser.parse(null, "Link is KSK@gpl.txt\u200b."); + parts = soneTextParser.parse("Link is KSK@gpl.txt\u200b.", null); assertNotNull("Parts", parts); assertEquals("Part Text", "Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\u200b.", convertText(parts, PlainTextPart.class, FreenetLinkPart.class)); /* check embedded links and line breaks. */ - parts = soneTextParser.parse(null, "Link is KSK@gpl.txt\nKSK@test.dat\n"); + parts = soneTextParser.parse("Link is KSK@gpl.txt\nKSK@test.dat\n", null); assertNotNull("Parts", parts); assertEquals("Part Text", "Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\n[KSK@test.dat|test.dat|test.dat]", convertText(parts, PlainTextPart.class, FreenetLinkPart.class)); } @@ -107,7 +107,7 @@ public class SoneTextParserTest extends TestCase { Iterable parts; /* check basic links. */ - parts = soneTextParser.parse(null, "Some text.\n\nLink to sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU and stuff."); + parts = soneTextParser.parse("Some text.\n\nLink to sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU and stuff.", null); assertNotNull("Parts", parts); assertEquals("Part Text", "Some text.\n\nLink to [Sone|DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU] and stuff.", convertText(parts, PlainTextPart.class, SonePart.class)); } @@ -125,7 +125,7 @@ public class SoneTextParserTest extends TestCase { Iterable parts; /* check empty http links. */ - parts = soneTextParser.parse(null, "Some text. Empty link: http:// – nice!"); + parts = soneTextParser.parse("Some text. Empty link: http:// – nice!", null); assertNotNull("Parts", parts); assertEquals("Part Text", "Some text. Empty link: http:// – nice!", convertText(parts, PlainTextPart.class)); } -- 2.7.4