Skip to content

Commit

Permalink
regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
vigusmao committed May 26, 2021
1 parent 22c7cd1 commit 4c5f899
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 1 deletion.
1 change: 0 additions & 1 deletion Album/src/AlbumTest.java
Expand Up @@ -143,5 +143,4 @@ public void testarTiposDeColecionavelDistintos() {
assertEquals(3, albumFig.getQuantItensColados());
assertEquals(2, albumSelo.getQuantItensColados());
}

}
95 changes: 95 additions & 0 deletions TuiterLite/src/TuiterLite.java
@@ -1,3 +1,6 @@
import java.util.ArrayList;
import java.util.List;

/**
* Esta classe implementa um sistema de mensagens curtas estilo Twitter.
* É preciso cadastrar um usuário, identificado pelo seu e-mail, para que tuítes possam ser feitos.
Expand Down Expand Up @@ -44,4 +47,96 @@ public String getHashtagMaisComum() {
// ToDo IMPLEMENT ME!!!
return null;
}

public static void main(String[] args) {
String tuite = "#####test#lab estou resolvendo. O exercicio ###lab7. Então, , , , , ,vamos ver!####";

List<String> hashtags = new ArrayList<>();
//
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < tuite.length(); i++) {
// final char c = tuite.charAt(i);
// if (c == '#') {
// if (sb.length() > 0) {
// if (sb.charAt(sb.length() - 1) == '#') {
// continue; // ignorando a # corrente, já que o anterior tb era #
// }
// String hashtag = sb.toString();
// hashtags.add(hashtag);
// sb.setLength(1); // vai manter apenas o primeiro caracter, que já é uma hashtag
// } else {
// sb.append("#");
// }
// } else if (isAlphanumeric(c)) {
// if (sb.length() > 0) {
// sb.append(c);
// }
//
// } else { // não é alfanumérico e nem o símbolo #
// if (sb.length() > 0) {
// String hashtag = sb.toString();
// hashtags.add(hashtag);
// sb.setLength(0);
// }
// }
// }





String[] palavrasDaFrase = tuite.split("([^(a-z|A-Z|0-9|ã-ü|#)])+"); // "escapando" a contrabarra para que minha string seja "CONTRABARRA S"
System.out.println(tuite);

for (String palavra : palavrasDaFrase) {

if (palavra.charAt(0) == '#') {
palavra = palavra.replaceAll("#+", "#");

String[] tags = palavra.split("#");
for (String tag : tags) {
if (tag.length() > 0) {
hashtags.add("#" + tag);
}
}
}
}

for (String hashtag : hashtags) {
System.out.println(hashtag);
}



//
// String numerosSeparadosPorVirgula = "13+54++++7000+4,78,,,,98989+8";
// String[] numeros = numerosSeparadosPorVirgula.split("(\\++)|,+"); // "escapando" a contrabarra para que minha string seja "CONTRABARRA S"
// System.out.println(numerosSeparadosPorVirgula);
// for (String numeroComoString : numeros) {
//// int x = Integer.parseInt(numeroComoString);
// System.out.println(numeroComoString);
// }
//
// String regex1 = ".*[A-Z]+.*";
// String regex2 = ".*[a-z]+.*";
// String regex3 = ".*[0-9]+.*";
// String palavra = "VyuyH87aa";
//
//
// if (palavra.matches(regex1) && palavra.matches(regex2) && palavra.matches(regex3)) {
// System.out.println("Ok! Casou com a regexp");
// } else {
// System.out.println("Não casou com a regexp!!!");
// }
//


}

private static boolean isAlphanumeric(char c) {
return Character.isAlphabetic(c) || Character.isDigit(c);
}



}
9 changes: 9 additions & 0 deletions TuiterLite/src/TuiterLiteTest.java
Expand Up @@ -140,6 +140,15 @@ public void testeHashtags()
"#LAB7", tuiterLite.getHashtagMaisComum());
}

// @Test
// public void testarMultiplosSimbolosDeHashtag() {
// Tuite tuite = tuiterLite.tuitarAlgo(usuario, "###LAB7 ######LAB7");
// assertTrue("O número de caracteres # não deve importar",
// tuite.getHashtags().contains("#LAB7"));
// assertFalse("Para consulta, devemos usar sempre uma única #",
// tuite.getHashtags().contains("###LAB7"));
// }

// @Test
// public void testeTipoUsuario() throws TamanhoMaximoExcedidoException, UsuarioDesconhecidoException {
// // sanity check
Expand Down

0 comments on commit 4c5f899

Please sign in to comment.