package com.stackoverflow.scanner;
import javax.annotation.Nonnull;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.regex.Pattern;
import static java.lang.String.format;
public class ScannerExample
{
private static final Set EXIT_COMMANDS;
private static final Set HELP_COMMANDS;
private static final Pattern DATE_PATTERN;
private static final String HELP_MESSAGE;
static {
final SortedSet ecmds = new TreeSet(String.CASE_INSENSITIVE_ORDER);
ecmds.addAll(Arrays.asList("exit", "done", "quit", "end", "fino"));
EXIT_COMMANDS = Collections.unmodifiableSortedSet(ecmds);
final SortedSet hcmds = new TreeSet(String.CASE_INSENSITIVE_ORDER);
hcmds.addAll(Arrays.asList("help", "helpi", "?"));
HELP_COMMANDS = Collections.unmodifiableSet(hcmds);
DATE_PATTERN = Pattern.compile("\\d{4}([-\\/])\\d{2}\\1\\d{2}"); // http://regex101.com/r/xB8dR3/1 HELP_MESSAGE = format("Please enter some data or enter one of the following commands to
exit %s", EXIT_COMMANDS);
}
*Bajarish oqimini boshqarish uchun istisnolardan foydalanish har doim yomon.
* Shuning uchun bu usulda inkapsullangan, bu shunday qilingan
* har qanday tashqi kutubxonalarni kiritmaslik uchun maxsus usul
* shuning uchun bu to'liq o'ziga xos misol.
* @param ning mumkin bo'lgan URL manzili
* @return true, agar s haqiqiy urlni bildirsa, aks holda false
private static boolean isValidURL(@Nonnull final String s)
{
try { new URL(s); return true; }
catch (final MalformedURLException e) { return false; }
}