Loading app/src/main/java/it/niedermann/owncloud/notes/util/NoteLinksUtils.java +55 −5 Original line number Original line Diff line number Diff line package it.niedermann.owncloud.notes.util; package it.niedermann.owncloud.notes.util; import android.text.TextUtils; import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting; import java.util.HashSet; import java.util.HashSet; Loading @@ -20,7 +18,7 @@ public class NoteLinksUtils { /** /** * Replaces all links to other notes of the form `[<link-text>](<note-file-id>)` * Replaces all links to other notes of the form `[<link-text>](<note-file-id>)` * in the markdown string with links to a dummy url. * in the markdown string with links to a dummy url. * * <p> * Why is this needed? * Why is this needed? * See discussion in issue #623 * See discussion in issue #623 * * Loading @@ -38,7 +36,8 @@ public class NoteLinksUtils { } } } } String noteRemoteIdsCondition = TextUtils.join("|", noteRemoteIdsToReplace); String noteRemoteIdsCondition = join("|", noteRemoteIdsToReplace); Pattern replacePattern = Pattern.compile(String.format(replaceNoteRemoteIdsRegEx, noteRemoteIdsCondition)); Pattern replacePattern = Pattern.compile(String.format(replaceNoteRemoteIdsRegEx, noteRemoteIdsCondition)); Matcher replaceMatcher = replacePattern.matcher(markdown); Matcher replaceMatcher = replacePattern.matcher(markdown); return replaceMatcher.replaceAll(String.format("[$1](%s$2)", RELATIVE_LINK_WORKAROUND_PREFIX)); return replaceMatcher.replaceAll(String.format("[$1](%s$2)", RELATIVE_LINK_WORKAROUND_PREFIX)); Loading @@ -63,4 +62,55 @@ public class NoteLinksUtils { public static long extractNoteRemoteId(String link) { public static long extractNoteRemoteId(String link) { return Long.parseLong(link.replace(RELATIVE_LINK_WORKAROUND_PREFIX, "")); return Long.parseLong(link.replace(RELATIVE_LINK_WORKAROUND_PREFIX, "")); } } /** * Returns a new {@code String} composed of copies of the * {@code CharSequence elements} joined together with a copy of the * specified {@code delimiter}. * * <blockquote>For example, * <pre>{@code * List<String> strings = new LinkedList<>(); * strings.add("Java");strings.add("is"); * strings.add("cool"); * String message = String.join(" ", strings); * //message returned is: "Java is cool" * * Set<String> strings = new LinkedHashSet<>(); * strings.add("Java"); strings.add("is"); * strings.add("very"); strings.add("cool"); * String message = String.join("-", strings); * //message returned is: "Java-is-very-cool" * }</pre></blockquote> * <p> * Note that if an individual element is {@code null}, then {@code "null"} is added. * * @param delimiter a sequence of characters that is used to separate each * of the {@code elements} in the resulting {@code String} * @param elements an {@code Iterable} that will have its {@code elements} * joined together. * @return a new {@code String} that is composed from the {@code elements} * argument * @throws NullPointerException If {@code delimiter} or {@code elements} * is {@code null} * @see String#join(CharSequence, Iterable) */ private static String join(CharSequence delimiter, Iterable<String> elements) { if (delimiter == null) { throw new NullPointerException("Parameter delimiter must not be null"); } if (elements == null) { throw new NullPointerException("Parameter elements must not be bull"); } StringBuilder builder = new StringBuilder(); for (String item : elements) { builder.append(item); builder.append(delimiter); } if (builder.length() > 0) { builder.deleteCharAt(builder.length() - 1); } return builder.toString(); } } } app/src/androidTest/java/it/niedermann/owncloud/notes/model/NoteTest.java→app/src/test/java/it/niedermann/owncloud/notes/model/NoteTest.java +0 −0 File moved. View file app/src/androidTest/java/it/niedermann/owncloud/notes/util/MarkDownUtilTest.java→app/src/test/java/it/niedermann/owncloud/notes/util/MarkDownUtilTest.java +0 −0 File moved. View file app/src/androidTest/java/it/niedermann/owncloud/notes/util/NoteLinksUtilsTest.java→app/src/test/java/it/niedermann/owncloud/notes/util/NoteLinksUtilsTest.java +0 −2 Original line number Original line Diff line number Diff line package it.niedermann.owncloud.notes.util; package it.niedermann.owncloud.notes.util; import androidx.test.filters.SmallTest; import org.junit.Assert; import org.junit.Assert; import org.junit.Test; import org.junit.Test; Loading @@ -12,7 +11,6 @@ import java.util.Set; import static it.niedermann.owncloud.notes.util.NoteLinksUtils.RELATIVE_LINK_WORKAROUND_PREFIX; import static it.niedermann.owncloud.notes.util.NoteLinksUtils.RELATIVE_LINK_WORKAROUND_PREFIX; @SmallTest public class NoteLinksUtilsTest { public class NoteLinksUtilsTest { @Test @Test Loading app/src/androidTest/java/it/niedermann/owncloud/notes/util/NoteUtilTest.java→app/src/test/java/it/niedermann/owncloud/notes/util/NoteUtilTest.java +0 −0 File moved. View file Loading
app/src/main/java/it/niedermann/owncloud/notes/util/NoteLinksUtils.java +55 −5 Original line number Original line Diff line number Diff line package it.niedermann.owncloud.notes.util; package it.niedermann.owncloud.notes.util; import android.text.TextUtils; import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting; import java.util.HashSet; import java.util.HashSet; Loading @@ -20,7 +18,7 @@ public class NoteLinksUtils { /** /** * Replaces all links to other notes of the form `[<link-text>](<note-file-id>)` * Replaces all links to other notes of the form `[<link-text>](<note-file-id>)` * in the markdown string with links to a dummy url. * in the markdown string with links to a dummy url. * * <p> * Why is this needed? * Why is this needed? * See discussion in issue #623 * See discussion in issue #623 * * Loading @@ -38,7 +36,8 @@ public class NoteLinksUtils { } } } } String noteRemoteIdsCondition = TextUtils.join("|", noteRemoteIdsToReplace); String noteRemoteIdsCondition = join("|", noteRemoteIdsToReplace); Pattern replacePattern = Pattern.compile(String.format(replaceNoteRemoteIdsRegEx, noteRemoteIdsCondition)); Pattern replacePattern = Pattern.compile(String.format(replaceNoteRemoteIdsRegEx, noteRemoteIdsCondition)); Matcher replaceMatcher = replacePattern.matcher(markdown); Matcher replaceMatcher = replacePattern.matcher(markdown); return replaceMatcher.replaceAll(String.format("[$1](%s$2)", RELATIVE_LINK_WORKAROUND_PREFIX)); return replaceMatcher.replaceAll(String.format("[$1](%s$2)", RELATIVE_LINK_WORKAROUND_PREFIX)); Loading @@ -63,4 +62,55 @@ public class NoteLinksUtils { public static long extractNoteRemoteId(String link) { public static long extractNoteRemoteId(String link) { return Long.parseLong(link.replace(RELATIVE_LINK_WORKAROUND_PREFIX, "")); return Long.parseLong(link.replace(RELATIVE_LINK_WORKAROUND_PREFIX, "")); } } /** * Returns a new {@code String} composed of copies of the * {@code CharSequence elements} joined together with a copy of the * specified {@code delimiter}. * * <blockquote>For example, * <pre>{@code * List<String> strings = new LinkedList<>(); * strings.add("Java");strings.add("is"); * strings.add("cool"); * String message = String.join(" ", strings); * //message returned is: "Java is cool" * * Set<String> strings = new LinkedHashSet<>(); * strings.add("Java"); strings.add("is"); * strings.add("very"); strings.add("cool"); * String message = String.join("-", strings); * //message returned is: "Java-is-very-cool" * }</pre></blockquote> * <p> * Note that if an individual element is {@code null}, then {@code "null"} is added. * * @param delimiter a sequence of characters that is used to separate each * of the {@code elements} in the resulting {@code String} * @param elements an {@code Iterable} that will have its {@code elements} * joined together. * @return a new {@code String} that is composed from the {@code elements} * argument * @throws NullPointerException If {@code delimiter} or {@code elements} * is {@code null} * @see String#join(CharSequence, Iterable) */ private static String join(CharSequence delimiter, Iterable<String> elements) { if (delimiter == null) { throw new NullPointerException("Parameter delimiter must not be null"); } if (elements == null) { throw new NullPointerException("Parameter elements must not be bull"); } StringBuilder builder = new StringBuilder(); for (String item : elements) { builder.append(item); builder.append(delimiter); } if (builder.length() > 0) { builder.deleteCharAt(builder.length() - 1); } return builder.toString(); } } }
app/src/androidTest/java/it/niedermann/owncloud/notes/model/NoteTest.java→app/src/test/java/it/niedermann/owncloud/notes/model/NoteTest.java +0 −0 File moved. View file
app/src/androidTest/java/it/niedermann/owncloud/notes/util/MarkDownUtilTest.java→app/src/test/java/it/niedermann/owncloud/notes/util/MarkDownUtilTest.java +0 −0 File moved. View file
app/src/androidTest/java/it/niedermann/owncloud/notes/util/NoteLinksUtilsTest.java→app/src/test/java/it/niedermann/owncloud/notes/util/NoteLinksUtilsTest.java +0 −2 Original line number Original line Diff line number Diff line package it.niedermann.owncloud.notes.util; package it.niedermann.owncloud.notes.util; import androidx.test.filters.SmallTest; import org.junit.Assert; import org.junit.Assert; import org.junit.Test; import org.junit.Test; Loading @@ -12,7 +11,6 @@ import java.util.Set; import static it.niedermann.owncloud.notes.util.NoteLinksUtils.RELATIVE_LINK_WORKAROUND_PREFIX; import static it.niedermann.owncloud.notes.util.NoteLinksUtils.RELATIVE_LINK_WORKAROUND_PREFIX; @SmallTest public class NoteLinksUtilsTest { public class NoteLinksUtilsTest { @Test @Test Loading
app/src/androidTest/java/it/niedermann/owncloud/notes/util/NoteUtilTest.java→app/src/test/java/it/niedermann/owncloud/notes/util/NoteUtilTest.java +0 −0 File moved. View file