Created
November 30, 2012 01:17
-
-
Save mateusmaso/4173103 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void criaNovoEstado(Estado estado, Automato automato, String terminal) { | |
String nomeAFND; | |
Estado novoEstado; | |
List<Estado> transicoes; | |
List<Estado> conjunto = estado.getEstadosConjunto(); | |
List<Estado> listE = new ArrayList<Estado>(); | |
if (conjunto != null) { | |
for (Estado parte : conjunto) { | |
Map<String, List<Estado>> ts = parte.getTransicoes(); | |
if (ts != null && ts.size() > 0) { | |
List<Estado> t = ts.get(terminal); | |
if (t != null && t.size() > 0) { | |
listE.addAll(t); | |
} | |
} | |
} | |
} else { | |
listE = estado.getTransicoes().get(terminal); | |
} | |
nomeAFND = mergeNomes(listE); | |
novoEstado = new Estado(nomeAFND); | |
novoEstado.setIsFinal(verificaFinal(listE)); | |
estadosIniciais(listE); | |
novoEstado.setEstadosConjunto(listE); | |
List<Estado> novaLista = new ArrayList<Estado>(); | |
novaLista.add(novoEstado); | |
estado.addTransicao(terminal, novaLista); | |
automato.addNovoEstado(novoEstado); | |
Set<String> terminais = novoEstado.getEstadosConjunto().get(0).getTransicoes().keySet(); | |
for (String t : terminais) { | |
List<Estado> conjuntoPorTerminal = new ArrayList<Estado>(); | |
for (Estado es : novoEstado.getEstadosConjunto()) { | |
transicoes = es.getTransicoes().get(t); | |
if (transicoes != null) { | |
conjuntoPorTerminal.addAll(transicoes); | |
} | |
} | |
estadosIniciais(conjuntoPorTerminal); | |
if (conjuntoPorTerminal.size() > 1) { | |
Estado estadoAFNDExistente = getEstadoNaoDeterministico(conjuntoPorTerminal, automato); | |
if (estadoAFNDExistente != null) { | |
conjuntoPorTerminal.clear(); | |
conjuntoPorTerminal.add(estadoAFNDExistente); | |
novoEstado.addTransicao(t, conjuntoPorTerminal); | |
} else { | |
criaNovoEstado(novoEstado, automato, t); | |
} | |
} else if (conjuntoPorTerminal.size() == 1) { | |
novoEstado.addTransicao(t, conjuntoPorTerminal); | |
} else { | |
novoEstado.addTransicao(t, null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment