001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.io; 003 004import java.net.URL; 005import java.util.regex.Matcher; 006import java.util.regex.Pattern; 007 008/** 009 * Download URL pattern. 010 * @since 15784 011 */ 012public interface UrlPattern { 013 /** 014 * Returns the URL pattern. 015 * @return the URL pattern 016 */ 017 String pattern(); 018 019 /** 020 * Creates a matcher that will match the given input against this pattern. 021 * @param input The character sequence to be matched 022 * @return A new matcher for this pattern 023 */ 024 default Matcher matcher(String input) { 025 return Pattern.compile(pattern()).matcher(input); 026 } 027 028 /** 029 * Attempts to match the given input against the pattern. 030 * @param input The character sequence to be matched 031 * @return {@code true} if the given input matches this pattern 032 */ 033 default boolean matches(String input) { 034 return input != null && matcher(input).matches(); 035 } 036 037 /** 038 * Attempts to match the given URL external form against the pattern. 039 * @param url URL to be matched 040 * @return {@code true} if the given URL matches this pattern 041 */ 042 default boolean matches(URL url) { 043 return url != null && matches(url.toExternalForm()); 044 } 045}