import java.util.regex.Pattern ;
public class Main {
private static void testar
( boolean resultado,
String teste
) { System .
out .
println ( Validador.
validarCaminho ( teste
) == resultado
? "Ok" : "ERRO" ) ; }
public static void main
( String [ ] args
) { testar( true , "C:/home/PauloNeto/NetBeansProjects/Expre/src/expre/texto.txt" ) ;
testar( true , "C:/home/Paulo Neto/Net Beans Projects/Expre/src/expre/texto.txt" ) ;
testar( true , "/home/PauloNeto/NetBeansProjects/Expre/src/expre/texto.txt" ) ;
testar( true , "/home/Paulo Neto/Net Beans Projects/Expre/src/expre/texto.txt" ) ;
testar( true , "home/PauloNeto/NetBeansProjects/Expre/src/expre/texto.txt" ) ;
testar( true , "home/Paulo Neto/Net Beans Projects/Expre/src/expre/texto.txt" ) ;
testar( true , "home/PauloNeto/NetBeansProjects/Expre/src/expre/texto" ) ;
testar( true , "home/Paulo Neto/Net Beans Projects/Expre/src/expre/texto" ) ;
testar( true , "home" ) ;
testar( true , "/home" ) ;
testar( true , "C:/home" ) ;
testar( true , "home.txt" ) ;
testar( true , "/home.txt" ) ;
testar( true , "C:/home.txt" ) ;
testar( true , "C:" ) ;
testar( true , "C:/" ) ;
testar( false , "a:" ) ;
testar( false , "a:/" ) ;
testar( false , " home" ) ;
testar( false , "home " ) ;
testar( false , "home/" ) ;
testar( false , "home." ) ;
testar( false , ".txt" ) ;
testar( false , "C:home" ) ;
testar( false , "C:home/texto" ) ;
testar( false , "home//texto.txt" ) ;
testar( false , "ho me/PauloNeto/NetBeansProjects/Expre/src/expre/texto.txt" ) ;
testar( false , "home/PauloNeto/NetBeansProjects/Expre/src/expre/texto." ) ;
testar( false , "home/PauloNeto/NetBeans#Projects/Expre/src/expre/texto.txt" ) ;
testar( false , "home/PauloNeto/NetBeans Projects/Expre/src/expre/texto.txt" ) ;
testar( false , "home/PauloNeto/NetBeansProjects/Expre/src/expre/texto..txt" ) ;
testar( false , "home/PauloNeto/NetBeansProjects/Expre/src/expre/texto.x.txt" ) ;
testar( false , "home/PauloNeto/NetBeansProjects/Expre/src/expre/texto." ) ;
testar( false , "home/PauloNeto/NetBeansProjects/Expre/src/expre/texto.txt." ) ;
testar( false , " E:/home/PauloNeto/NetBeansProjects/Expre/src/expre/texto.txt" ) ;
testar( false , "E :/home/PauloNeto/NetBeansProjects/Expre/src/expre/texto.txt" ) ;
testar( false , "E: /home/PauloNeto/NetBeansProjects/Expre/src/expre/texto.txt" ) ;
testar( false , "E:/ home/PauloNeto/NetBeansProjects/Expre/src/expre/texto.txt" ) ;
testar( false , "E:/home /PauloNeto/NetBeansProjects/Expre/src/expre/texto.txt" ) ;
testar( false , "home /PauloNeto/NetBeansProjects/Expre/src/expre/texto.txt" ) ;
testar( false , " home/PauloNeto/NetBeansProjects/Expre/src/expre/texto.txt" ) ;
testar( false , "home/ PauloNeto/NetBeansProjects/Expre/src/expre/texto.txt" ) ;
testar( false , "home/PauloNeto /NetBeansProjects/Expre/src/expre/texto.txt" ) ;
testar( false , "home/PauloNeto/NetBeansProjects/Expre/src/expre/texto. txt" ) ;
testar( false , "home/PauloNeto/NetBeansProjects/Expre/src/expre/texto.txt " ) ;
testar( false , "home/PauloNeto/NetBeansProjects/Expre/src/expre/texto.t xt" ) ;
testar( false , "E: " ) ;
testar( false , "E :" ) ;
testar( false , " E:" ) ;
testar( false , "E:/ " ) ;
testar( false , "E: /" ) ;
testar( false , "E :/" ) ;
testar( false , " E:/" ) ;
testar( false , "" ) ;
testar( false , " " ) ;
testar( false , "/" ) ;
testar( false , "." ) ;
testar( false , ":" ) ;
}
}
class Validador {
private static final Pattern p1 = Pattern.compile ( "^[A-Z0-9a-z]*$" ) ;
private static final Pattern p2 =
Pattern.compile ( "^(?:(?:[A-Z]\\ :)?\\ /)?(?:[a-zA-Z0-9]+(?: [a-zA-Z0-9]+)*)(?:\\ /(?:[a-zA-Z0-9]+(?: [a-zA-Z0-9]+)*))*(?:\\ .[a-zA-Z0-9]+)?|[A-Z]\\ :\\ /?$" ) ;
public static boolean validarPalavra
( String palavra
) { return p1.matcher ( palavra) .matches ( ) ;
}
public static boolean validarCaminho
( String caminho
) { return p2.matcher ( caminho) .matches ( ) ;
}
}
aW1wb3J0IGphdmEudXRpbC5yZWdleC5QYXR0ZXJuOwoKcHVibGljIGNsYXNzIE1haW4gewoKICAgIHByaXZhdGUgc3RhdGljIHZvaWQgdGVzdGFyKGJvb2xlYW4gcmVzdWx0YWRvLCBTdHJpbmcgdGVzdGUpIHsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oVmFsaWRhZG9yLnZhbGlkYXJDYW1pbmhvKHRlc3RlKSA9PSByZXN1bHRhZG8gPyAiT2siIDogIkVSUk8iKTsKICAgIH0KCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgdGVzdGFyKHRydWUsICJDOi9ob21lL1BhdWxvTmV0by9OZXRCZWFuc1Byb2plY3RzL0V4cHJlL3NyYy9leHByZS90ZXh0by50eHQiKTsKICAgICAgICB0ZXN0YXIodHJ1ZSwgIkM6L2hvbWUvUGF1bG8gTmV0by9OZXQgQmVhbnMgUHJvamVjdHMvRXhwcmUvc3JjL2V4cHJlL3RleHRvLnR4dCIpOwogICAgICAgIHRlc3Rhcih0cnVlLCAiL2hvbWUvUGF1bG9OZXRvL05ldEJlYW5zUHJvamVjdHMvRXhwcmUvc3JjL2V4cHJlL3RleHRvLnR4dCIpOwogICAgICAgIHRlc3Rhcih0cnVlLCAiL2hvbWUvUGF1bG8gTmV0by9OZXQgQmVhbnMgUHJvamVjdHMvRXhwcmUvc3JjL2V4cHJlL3RleHRvLnR4dCIpOwogICAgICAgIHRlc3Rhcih0cnVlLCAiaG9tZS9QYXVsb05ldG8vTmV0QmVhbnNQcm9qZWN0cy9FeHByZS9zcmMvZXhwcmUvdGV4dG8udHh0Iik7CiAgICAgICAgdGVzdGFyKHRydWUsICJob21lL1BhdWxvIE5ldG8vTmV0IEJlYW5zIFByb2plY3RzL0V4cHJlL3NyYy9leHByZS90Z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