HashMap<String,Argumento> mapaCadeias;
Argumento argumento = new Argumento();
ManipArquivo mArq = new ManipArquivo();
Automato automato = new Automato();
String cadeia = "";
String tipoCadeia = "";
public Compilador() {
mapaCadeias = new HashMap<String,Argumento>();
}
public void compilar(String caminho) {
// Lê o arquivo texto pra um HashMap
HashMap linhaLida = mArq.lerArquivo(caminho);
for (int numLinha = 0; numLinha < linhaLida.size(); numLinha++){
// Recupera o texto linha a linha
String textoLinha = (String) linhaLida.get(numLinha);
// Passamos o texto para Tokenizer para ser lido palavra por palavra
StringTokenizer st = new StringTokenizer(textoLinha);
while (st.hasMoreTokens()){
cadeia = st.nextToken();
tipoCadeia = automato.reconhecerCadeia(cadeia);
argumento.setCadeia(cadeia);
argumento.setIdentificador(tipoCadeia);
//argumento.setQuantidade(1);
argumento.setLinhasOcorrencia(numLinha+1);
mapaCadeias.put(cadeia, argumento);
}
}
}
public void varredura(){
System.out.println(mapaCadeias.get(automato));
// System.out.println(mapaCadeias.values()); //Aqui pega o endereço de memória
}
package exemplos.guj;
public class ClasseDemo {
public String atributoA;
public String atributoB;
public ClasseDemo(String atrA, String atrB) {
this.atributoA = atrA;
this.atributoB = atrB;
}
//Aqui está a sobrescrita do método toString
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("Valor do atributoA = ");
sb.append(this.atributoA);
sb.append("\n");
sb.append("Valor do atributoB = ");
sb.append(this.atributoB);
return sb.toString();
}
}
package exemplos.guj;
public class ClasseTeste {
public static void main(String[] args) {
ClasseDemo demo1 = new ClasseDemo("1", "2");
ClasseDemo demo2 = new ClasseDemo("3", "4");
System.out.println(demo1.toString());
System.out.println(demo2.toString());
}
}
public class Dados{
//"args" é um array de String onde cada elemento é um argumento passado pela linha de comando momento na "inicialização" da execução.
public static void main(String[] args){
Map<Integer, List<String>> mapLines= new HashMap<Integer, List<String>>();
try {
//leitura do ficheiro, prepara-o para ser aberto
BufferedReader in = new BufferedReader(new FileReader("conteudo.txt"));
String str;
int i = 0;
//vai percorrer todo o ficheiro
while((str = in.readLine()) != null)
{
if(str.startsWith("#"))
{
str= "";
}
else{ //esta a dividir a frase em varias strings imprimindo o seu resultado
List<String> values = new ArrayList<String>();
String words[] = str.split(";");
for(String word : words) {
values.add(word);
System.out.println(word);
}
mapLines.put(i, values);
i++;
}
}// fim do while
in.close();
} catch (IOException e){
// possiveis erros são tratatos aqui
//JOptionPane.showMessageDialog(null, this.word, "NÂO FOI POSSÍVEL ABRIR O SEU FICHEIRO", JOptionPane.ERROR_MESSAGE);
System.out.println("ERRO-->NÃO FOI ENCONTRADO O SEU FICHEIRO DE DESTINO,TENTE DE NOVO");
}
// Apresenta o contéudo do Map
Map<Integer, List<String>> m = new HashMap<Integer, List<String>>();
for(Integer key : m.keySet()) {
for(String word : m.get(key)) {
System.out.println(word);
}
}
}
public static void main2(String[] args){
Map<Integer, List<String>> mapLines= new HashMap<Integer, List<String>>();
try {
BufferedReader in2 = new BufferedReader(new FileReader("conteudo2.txt"));
String str;
int i = 0;
while((str = in2.readLine()) != null)
{
if(str.startsWith("#"))
{
str= "";
}
else{ //esta a dividir a frase em varias strings
List<String> values = new ArrayList<String>();
String words[] = str.split(" ");
for(String word : words) {
values.add(word);
System.out.println(word);
}
mapLines.put(i, values);
i++;
}
}// fim do while
in2.close();
} catch (IOException e){
// possiveis erros são tratatos aqui
System.out.println("ERRO-->NÃO FOI ENCONTRADO O SEU FICHEIRO DE DESTINO,TENTE DE NOVO");
}
// Apresenta o contéudo do Map
Map<Integer, List<String>> m = new HashMap<Integer, List<String>>();
for(Integer key : m.keySet()) {
for(String word : m.get(key)) {
System.out.println(word);
}
}
}
}