source: josm/trunk/src/org/openstreetmap/josm/io/UrlPattern.java

Last change on this file was 15784, checked in by Don-vip, 4 years ago

see #18613 - rework download tasks / URL patterns

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import java.net.URL;
5import java.util.regex.Matcher;
6import java.util.regex.Pattern;
7
8/**
9 * Download URL pattern.
10 * @since 15784
11 */
12public interface UrlPattern {
13 /**
14 * Returns the URL pattern.
15 * @return the URL pattern
16 */
17 String pattern();
18
19 /**
20 * Creates a matcher that will match the given input against this pattern.
21 * @param input The character sequence to be matched
22 * @return A new matcher for this pattern
23 */
24 default Matcher matcher(String input) {
25 return Pattern.compile(pattern()).matcher(input);
26 }
27
28 /**
29 * Attempts to match the given input against the pattern.
30 * @param input The character sequence to be matched
31 * @return {@code true} if the given input matches this pattern
32 */
33 default boolean matches(String input) {
34 return input != null && matcher(input).matches();
35 }
36
37 /**
38 * Attempts to match the given URL external form against the pattern.
39 * @param url URL to be matched
40 * @return {@code true} if the given URL matches this pattern
41 */
42 default boolean matches(URL url) {
43 return url != null && matches(url.toExternalForm());
44 }
45}
Note: See TracBrowser for help on using the repository browser.