Skip to content
Snippets Groups Projects
Commit 592b14bf authored by Bergony Bandeira De Melo Silva's avatar Bergony Bandeira De Melo Silva
Browse files

Funcao ordenar e remover repetido

parent 6c43a6fe
No related branches found
No related tags found
No related merge requests found
/Docs/
/br/
......@@ -2,84 +2,37 @@ package br.ufrn.imd.controle;
import java.io.FileNotFoundException;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import br.ufrn.imd.modelo.ArqCsv;
import br.ufrn.imd.modelo.ArqWeb;
import br.ufrn.imd.modelo.Noticia;
public class ControladorArquivo {
private ArqCsv csv;
private ArqWeb web;
ArrayList<String> listCsv;
public ControladorArquivo() throws FileNotFoundException {
this.csv = new ArqCsv();
this.listCsv = new ArrayList<String>();
}
private ArqCsv arqCsv;
private ArqWeb arqWeb;
private HashMap<String , Noticia> Map;
public ArqCsv getCsv() {
return csv;
}
public void setCsv(ArqCsv csv) {
this.csv = csv;
}
public ArqWeb getWeb() {
return web;
}
public void setWeb(ArqWeb web) {
this.web = web;
}
public void dataCsv(String s) {
listCsv.add(s);
}
public ArrayList<String> getListCsv() {
return listCsv;
}
public void setListCsv(ArrayList<String> listCsv) {
this.listCsv = listCsv;
}
public String removePalavraMenor(String palavra, int tamanho) {
String[] s = palavra.split(" ");
String out = "";
int count = 0;
public ControladorArquivo() throws arquivoException {
Map = new HashMap<String, Noticia>();
arqWeb = new ArqWeb();
System.out.println(" oust "+ s.length+ "couyt "+ count);
while(s.length > count) {
if(s[count].length() > tamanho) {
out += s[count];
out += " ";
}
System.out.println(" oust "+ s.length+ "couyt "+ count);
count++;
try {
arqCsv = new ArqCsv();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return out;
}
public String palavraMinuscula( String palavra ) {
return palavra.toLowerCase().replaceAll("[^a-z ]", "");
}
public void palavrasOrdenar() {
Collections.sort(listCsv);
}
}
package br.ufrn.imd.controle;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class ControladorProcesso {
public static String removePalavraMenor(String palavra, int tamanho) {
String[] s = palavra.split(" ");
String out = "";
int count = 0;
while(s.length > count) {
if(s[count].length() > tamanho) {
out += s[count];
out += " ";
}
count++;
}
return out;
}
public static String palavraMinuscula( String palavra ) {
return palavra.toLowerCase().replaceAll("[^a-z ]", "");
}
public static String palavrasOrdenarRepitidas(String frase) {
String[] s = frase.split(" ");
String aux = "";
String out = "";
int count = 0;
int index = 0;
int charAt = 0;
while(s.length-1 > index) {
if(s[index].charAt(charAt) > s[count].charAt(charAt)) {
aux = s[index];
s[index] = s[count];
s[count] = aux;
}
if(s[index].charAt(charAt) == s[count].charAt(charAt)) {
if(s[index].length()-1 > charAt) {
charAt++;
continue;
}
}
if(count == s.length-1 ) {
out += s[index];
out += " ";
index++;
count = index;
charAt = 0;
}
charAt = 0;
count++;
}
return palavrasRepetidas(out);
}
private static String palavrasRepetidas(String palavra) {
String[] s = palavra.split(" ");
String out = "";
int count = 0;
while(s.length-1 > count) {
if(s[count].equals(s[count+1])) {
}else{
out += s[count];
out += " ";
}
count++;
}
if(s[count-1].equals(s[count])) {
}else{
out += s[count];
out += " ";
}
return out;
}
//Fonte https://www.geeksforgeeks.org/sha-1-hash-in-java/
public static String SHA(String palavra)
{
String hashtext;
try {
// getInstance() method is called with algorithm SHA-1
MessageDigest md = MessageDigest.getInstance("SHA-1");
// digest() method is called
// to calculate message digest of the input string
// returned as array of byte
byte[] messageDigest = md.digest(palavra.getBytes());
// Convert byte array into signum representation
BigInteger no = new BigInteger(1, messageDigest);
// Convert message digest into hex value
hashtext = no.toString(16);
// Add preceding 0s to make it 32 bit
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
// return the HashText
return hashtext;
}
// For specifying wrong message digest algorithms
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
}
......@@ -4,17 +4,11 @@ import java.sql.Timestamp;
public class Noticia {
private int id;
private String conteudo = "";
private String formatado = "";
private String link = "";
private Timestamp time;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getConteudo() {
return conteudo;
}
......
......@@ -3,26 +3,13 @@ package br.ufrn.imd.visao;
import java.io.IOException;
import br.ufrn.imd.controle.ControladorArquivo;
import br.ufrn.imd.modelo.ArqCsv;
import br.ufrn.imd.controle.ControladorProcesso;
public class Principal {
public static void main(String[] args) throws IOException {
ControladorArquivo ca = new ControladorArquivo();
ca.getCsv().abrir();
ca.getCsv().ler(0);
String palavra = ca.removePalavraMenor(ca.getCsv().ler(0), 3);
System.out.println(palavra);
palavra = ca.palavraMinuscula(palavra);
ca.dataCsv(palavra);
ca.palavrasOrdenar();
System.out.println(ca.getListCsv());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment