2017-06-28 23:54:27 -04:00
|
|
|
/* Copyright (c) 2017 Christopher Cromer
|
|
|
|
* Copyright (c) 2017 Carlos Faúndez
|
|
|
|
*
|
|
|
|
* This file is part of mt. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution.
|
|
|
|
* This file may not be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.
|
|
|
|
*/
|
2017-07-03 20:46:11 -04:00
|
|
|
package cl.cromer.mt;
|
2017-06-28 23:54:27 -04:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2017-07-06 11:59:51 -04:00
|
|
|
/**
|
|
|
|
* Clase que almanecerá un estado con su subindices y sus enlaces adyacentes
|
|
|
|
*/
|
2017-06-28 23:54:27 -04:00
|
|
|
public class Estado {
|
2017-07-07 02:49:18 -04:00
|
|
|
/**
|
|
|
|
* El estado actual
|
|
|
|
*/
|
2017-06-28 23:54:27 -04:00
|
|
|
private final int q;
|
2017-07-07 02:49:18 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Los enlaces que tiene este estado
|
|
|
|
*/
|
2017-06-28 23:54:27 -04:00
|
|
|
private final ArrayList<Enlace> enlaces;
|
|
|
|
|
2017-07-06 11:59:51 -04:00
|
|
|
/**
|
|
|
|
* Contructor de la clase
|
|
|
|
*
|
|
|
|
* @param q Subindice del estado
|
|
|
|
*/
|
2017-07-05 23:41:07 -04:00
|
|
|
public Estado(int q) {
|
2017-06-28 23:54:27 -04:00
|
|
|
this.q = q;
|
|
|
|
enlaces = new ArrayList<>();
|
|
|
|
}
|
|
|
|
|
2017-07-06 11:59:51 -04:00
|
|
|
/**
|
|
|
|
* Retorna una lista con los enlaces de un estado
|
|
|
|
*
|
|
|
|
* @return ArrayList de Enlaces
|
|
|
|
*/
|
2017-07-05 23:41:07 -04:00
|
|
|
public ArrayList<Enlace> getEnlaces() {
|
2017-06-28 23:54:27 -04:00
|
|
|
return enlaces;
|
|
|
|
}
|
|
|
|
|
2017-07-06 11:59:51 -04:00
|
|
|
/**
|
|
|
|
* Retorna el subindice asociado al estado
|
|
|
|
*
|
|
|
|
* @return Subindice
|
|
|
|
*/
|
2017-07-05 23:41:07 -04:00
|
|
|
public int getQ() {
|
2017-06-28 23:54:27 -04:00
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
2017-07-06 11:59:51 -04:00
|
|
|
/**
|
|
|
|
* Crea un enlace entre dos estados ó a si mismo
|
|
|
|
*
|
|
|
|
* @param si Simbolo a analizar en la cadena
|
|
|
|
* @param qj Estado adyacente
|
|
|
|
* @param sj Simbolo que escribe en la cadena
|
2017-07-07 00:39:13 -04:00
|
|
|
* @param mover Movimiento del cabezal (indice de la cadena)
|
2017-07-06 11:59:51 -04:00
|
|
|
*/
|
2017-07-07 00:39:13 -04:00
|
|
|
public void crearEnlace(char si, Estado qj, char sj, char mover) {
|
2017-06-28 23:54:27 -04:00
|
|
|
if (enlaces.isEmpty()) {
|
2017-07-07 00:39:13 -04:00
|
|
|
enlaces.add(new Enlace(si, qj, sj, mover));
|
2017-06-28 23:54:27 -04:00
|
|
|
}
|
2017-07-07 00:39:13 -04:00
|
|
|
for (Enlace enlace : enlaces) {
|
|
|
|
if (enlace.getSi() == si) {
|
|
|
|
return;
|
2017-06-28 23:54:27 -04:00
|
|
|
}
|
|
|
|
}
|
2017-07-07 00:39:13 -04:00
|
|
|
enlaces.add(new Enlace(si, qj, sj, mover));
|
2017-06-28 23:54:27 -04:00
|
|
|
}
|
|
|
|
|
2017-07-06 11:59:51 -04:00
|
|
|
/**
|
|
|
|
* Retorna un String con la/s función/es de transición asociado a un estado
|
|
|
|
*
|
|
|
|
* @return String con la/s función/es
|
|
|
|
*/
|
2017-06-28 23:54:27 -04:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
StringBuilder _return = new StringBuilder();
|
|
|
|
for (Enlace enlace : enlaces) {
|
|
|
|
_return.append("(q").append(q).append(enlace).append("\n");
|
|
|
|
}
|
|
|
|
return _return.toString();
|
|
|
|
}
|
|
|
|
}
|