diff --git a/diagrama.uml b/diagrama.uml index 3037eb3..795d7c6 100644 --- a/diagrama.uml +++ b/diagrama.uml @@ -3,341 +3,54 @@ JAVA - cl.cromer.estructuras.InsercionController - cl.cromer.estructuras.Grafico.Destacados - cl.cromer.estructuras.ShellController - cl.cromer.estructuras.QuickController - cl.cromer.estructuras.EnlaceNormal - cl.cromer.estructuras.HashTableController - cl.cromer.estructuras.EnlaceCircular - cl.cromer.estructuras.ColaController - cl.cromer.estructuras.Colores - cl.cromer.estructuras.ListaEnlazadaTipos - cl.cromer.estructuras.HashTable - cl.cromer.estructuras.Enlace - cl.cromer.estructuras.Cola - cl.cromer.estructuras.ListaEnlazadaCircular - cl.cromer.estructuras.MenuController - cl.cromer.estructuras.BurbujaController - cl.cromer.estructuras.ListaEnlazada - cl.cromer.estructuras.PilaController - cl.cromer.estructuras.SeleccionController - cl.cromer.estructuras.Logs - cl.cromer.estructuras.Array - cl.cromer.estructuras.Pila - cl.cromer.estructuras.HashItem - cl.cromer.estructuras.Grafico - cl.cromer.estructuras.Array.ParticionarResult - cl.cromer.estructuras.TextFieldLimited - cl.cromer.estructuras.ListaEnlazdaController - cl.cromer.estructuras.ArrayController - cl.cromer.estructuras.TextFieldLimited.StyleableProperties - cl.cromer.estructuras.Main + cl.cromer.estructuras.InsercionController + cl.cromer.estructuras.Grafico.Destacados + cl.cromer.estructuras.ShellController + cl.cromer.estructuras.QuickController + cl.cromer.estructuras.EnlaceNormal + cl.cromer.estructuras.EnlaceCircular + cl.cromer.estructuras.ColaController + cl.cromer.estructuras.Colores + cl.cromer.estructuras.ListaEnlazadaTipos + cl.cromer.estructuras.Enlace + cl.cromer.estructuras.TablaHash + cl.cromer.estructuras.Cola + cl.cromer.estructuras.ListaEnlazadaCircular + cl.cromer.estructuras.MenuController + cl.cromer.estructuras.TablaHashController + cl.cromer.estructuras.BurbujaController + cl.cromer.estructuras.ListaEnlazada + cl.cromer.estructuras.PilaController + cl.cromer.estructuras.SeleccionController + cl.cromer.estructuras.Logs + cl.cromer.estructuras.Array + cl.cromer.estructuras.Pila + cl.cromer.estructuras.HashItem + cl.cromer.estructuras.Grafico + cl.cromer.estructuras.TextFieldLimited + cl.cromer.estructuras.ListaEnlazdaController + cl.cromer.estructuras.ArrayController + cl.cromer.estructuras.TextFieldLimited.StyleableProperties + cl.cromer.estructuras.Main - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + - - Fields - Constructors - Methods - Properties - Inner Classes - + All private diff --git a/doc/cl/cromer/estructuras/HashTable.html b/doc/cl/cromer/estructuras/HashTable.html index e91dc24..ca4da29 100644 --- a/doc/cl/cromer/estructuras/HashTable.html +++ b/doc/cl/cromer/estructuras/HashTable.html @@ -100,7 +100,7 @@ var activeTableTab = "activeTableTab";
  • java.lang.Object
    • -
    • cl.cromer.estructuras.HashTable
    • +
    • cl.cromer.estructuras.TablaHash
  • diff --git a/doc/cl/cromer/estructuras/HashTableController.html b/doc/cl/cromer/estructuras/HashTableController.html index dbc78fa..a1be86f 100644 --- a/doc/cl/cromer/estructuras/HashTableController.html +++ b/doc/cl/cromer/estructuras/HashTableController.html @@ -100,7 +100,7 @@ var activeTableTab = "activeTableTab";
  • java.lang.Object
    • -
    • cl.cromer.estructuras.HashTableController
    • +
    • cl.cromer.estructuras.TablaHashController
  • diff --git a/doc/cl/cromer/estructuras/class-use/HashTable.html b/doc/cl/cromer/estructuras/class-use/HashTable.html index 5c52240..3daa4dc 100644 --- a/doc/cl/cromer/estructuras/class-use/HashTable.html +++ b/doc/cl/cromer/estructuras/class-use/HashTable.html @@ -4,7 +4,7 @@ -Uses of Class cl.cromer.estructuras.HashTable +Uses of Class cl.cromer.estructuras.TablaHash @@ -70,7 +70,7 @@
    -

    Uses of Class
    cl.cromer.estructuras.HashTable

    +

    Uses of Class
    cl.cromer.estructuras.TablaHash

      diff --git a/doc/cl/cromer/estructuras/class-use/HashTableController.html b/doc/cl/cromer/estructuras/class-use/HashTableController.html index ec08ef1..600024e 100644 --- a/doc/cl/cromer/estructuras/class-use/HashTableController.html +++ b/doc/cl/cromer/estructuras/class-use/HashTableController.html @@ -4,7 +4,7 @@ -Uses of Class cl.cromer.estructuras.HashTableController +Uses of Class cl.cromer.estructuras.TablaHashController @@ -70,9 +70,9 @@
    -

    Uses of Class
    cl.cromer.estructuras.HashTableController

    +

    Uses of Class
    cl.cromer.estructuras.TablaHashController

    -
    No usage of cl.cromer.estructuras.HashTableController
    +
    No usage of cl.cromer.estructuras.TablaHashController
    diff --git a/src/cl/cromer/estructuras/HashTable.java b/src/cl/cromer/estructuras/TablaHash.java similarity index 98% rename from src/cl/cromer/estructuras/HashTable.java rename to src/cl/cromer/estructuras/TablaHash.java index 5b7af51..fbb9050 100644 --- a/src/cl/cromer/estructuras/HashTable.java +++ b/src/cl/cromer/estructuras/TablaHash.java @@ -5,7 +5,7 @@ package cl.cromer.estructuras; * * @author Chris Cromer */ -public class HashTable { +public class TablaHash { /** * El array donde están todos los elementos de la tabla hash. */ @@ -26,7 +26,7 @@ public class HashTable { * * @param tamano int: El tamaño maximo de la tabla hash. */ - public HashTable(int tamano) { + public TablaHash(int tamano) { this.tamano = tamano; hashArray = new HashItem[tamano]; } diff --git a/src/cl/cromer/estructuras/HashTableController.java b/src/cl/cromer/estructuras/TablaHashController.java similarity index 83% rename from src/cl/cromer/estructuras/HashTableController.java rename to src/cl/cromer/estructuras/TablaHashController.java index 439c268..e75c0f1 100644 --- a/src/cl/cromer/estructuras/HashTableController.java +++ b/src/cl/cromer/estructuras/TablaHashController.java @@ -12,11 +12,11 @@ import java.util.ResourceBundle; import java.util.logging.Level; /** - * Esta clase es para controlar todos la interfaz de HashTable. + * Esta clase es para controlar todos la interfaz de TablaHash. * * @author Chris Cromer */ -public class HashTableController implements Initializable { +public class TablaHashController implements Initializable { /** * La caja para ingresar la llave. */ @@ -30,7 +30,7 @@ public class HashTableController implements Initializable { private TextFieldLimited valorHashTable; /** - * Donde poner el contenido de hashTable. + * Donde poner el contenido de tablaHash. */ @FXML private VBox contenidoHashTable; @@ -52,9 +52,9 @@ public class HashTableController implements Initializable { private ResourceBundle resourceBundle; /** - * El hashTable usado en la aplicación. + * El tablaHash usado en la aplicación. */ - private HashTable hashTable; + private TablaHash tablaHash; /** * Grafico rectangulos. @@ -81,7 +81,7 @@ public class HashTableController implements Initializable { } /** - * Llenar el hashTable con numeros al azar. + * Llenar el tablaHash con numeros al azar. */ @FXML protected void botonLlenar() { @@ -98,8 +98,8 @@ public class HashTableController implements Initializable { for (int i = 0; i < 10; i++) { int numero = random.nextInt(rango) + minimo; - while (! hashTable.insertar(palabras.getPalabra(), numero)) { - if (hashTable.size() == 10) { + while (! tablaHash.insertar(palabras.getPalabra(), numero)) { + if (tablaHash.size() == 10) { break; } } @@ -108,12 +108,12 @@ public class HashTableController implements Initializable { } /** - * Crear el hashTable de tamaño 10. + * Crear el tablaHash de tamaño 10. */ private void initializeHashTable() { scene = contenidoHashTable.getScene(); grafico = new Grafico(scene); - this.hashTable = new HashTable(10); + this.tablaHash = new TablaHash(10); } /** @@ -122,13 +122,13 @@ public class HashTableController implements Initializable { private void generarGrafico() { grafico.removerDestacar(); for (int i = 0; i < 10; i++) { - if (hashTable.getIndice(i) != null) { + if (tablaHash.getIndice(i) != null) { Text text = (Text) scene.lookup("#indice_texto_" + String.valueOf(i)); text.setText(String.valueOf(i)); text = (Text) scene.lookup("#llave_texto_" + String.valueOf(i)); - text.setText(hashTable.getIndice(i).getLlave()); + text.setText(tablaHash.getIndice(i).getLlave()); text = (Text) scene.lookup("#valor_texto_" + String.valueOf(i)); - text.setText(String.valueOf(hashTable.getIndice(i).getValor())); + text.setText(String.valueOf(tablaHash.getIndice(i).getValor())); } else { Text text = (Text) scene.lookup("#indice_texto_" + String.valueOf(i)); @@ -142,7 +142,7 @@ public class HashTableController implements Initializable { } /** - * Vaciar el hashTable de todos los valores. + * Vaciar el tablaHash de todos los valores. */ @FXML protected void botonVaciar() { @@ -150,12 +150,12 @@ public class HashTableController implements Initializable { initializeHashTable(); } - hashTable = new HashTable(10); + tablaHash = new TablaHash(10); generarGrafico(); } /** - * Insertar un valor al hashTable y mostrar el codigo en la pantalla. + * Insertar un valor al tablaHash y mostrar el codigo en la pantalla. */ @FXML protected void botonInsertar() { @@ -164,20 +164,20 @@ public class HashTableController implements Initializable { } // Mostrar el codigo - /*String tipo = (hashTable.isOrdered()) ? "Ordenado" : "Simple"; - String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/hashTable" + tipo + "/insertar")).useDelimiter("\\Z").next(); + /*String tipo = (tablaHash.isOrdered()) ? "Ordenado" : "Simple"; + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/tablaHash" + tipo + "/insertar")).useDelimiter("\\Z").next(); codigoHashTable.setText(codigoTexto);*/ if (llaveHashTable.getText() != null && ! llaveHashTable.getText().trim().equals("") && valorHashTable.getText() != null && ! valorHashTable.getText().trim().equals("")) { try { - boolean exito = hashTable.insertar(llaveHashTable.getText().trim(), Integer.valueOf(valorHashTable.getText())); + boolean exito = tablaHash.insertar(llaveHashTable.getText().trim(), Integer.valueOf(valorHashTable.getText())); if (exito) { llaveHashTable.setText(""); valorHashTable.setText(""); generarGrafico(); } else { - if (hashTable.size() == 10) { + if (tablaHash.size() == 10) { Main.mostrarError(resourceBundle.getString("tablaHashLleno"), resourceBundle); } else { @@ -197,7 +197,7 @@ public class HashTableController implements Initializable { } /** - * Eliminar un valor del hashTable si existe y mostrar el codigo en la pantalla. + * Eliminar un valor del tablaHash si existe y mostrar el codigo en la pantalla. */ @FXML protected void botonEliminar() { @@ -206,13 +206,13 @@ public class HashTableController implements Initializable { } // Mostrar el codigo - /*String tipo = (hashTable.isOrdered()) ? "Ordenado" : "Simple"; - String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/hashTable" + tipo + "/eliminar")).useDelimiter("\\Z").next(); + /*String tipo = (tablaHash.isOrdered()) ? "Ordenado" : "Simple"; + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/tablaHash" + tipo + "/eliminar")).useDelimiter("\\Z").next(); codigoHashTable.setText(codigoTexto);*/ try { if (llaveHashTable.getText() != null && ! llaveHashTable.getText().trim().equals("")) { - boolean exito = hashTable.eliminar(llaveHashTable.getText()); + boolean exito = tablaHash.eliminar(llaveHashTable.getText()); if (exito) { llaveHashTable.setText(""); valorHashTable.setText(""); @@ -234,7 +234,7 @@ public class HashTableController implements Initializable { } /** - * Buscar si existe un elemento en el hashTable y mostrar el codigo en la pantalla + * Buscar si existe un elemento en el tablaHash y mostrar el codigo en la pantalla * Si existe el valor destacarlo. */ @FXML @@ -244,13 +244,13 @@ public class HashTableController implements Initializable { } // Mostrar el codigo - /*String tipo = (hashTable.isOrdered()) ? "Ordenado" : "Simple"; - String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/hashTable" + tipo + "/buscar")).useDelimiter("\\Z").next(); + /*String tipo = (tablaHash.isOrdered()) ? "Ordenado" : "Simple"; + String codigoTexto = new Scanner(getClass().getResourceAsStream("/cl/cromer/estructuras/code/tablaHash" + tipo + "/buscar")).useDelimiter("\\Z").next(); codigoHashTable.setText(codigoTexto);*/ try { if (llaveHashTable.getText() != null && ! llaveHashTable.getText().trim().equals("")) { - HashItem hashItem = hashTable.buscar(llaveHashTable.getText()); + HashItem hashItem = tablaHash.buscar(llaveHashTable.getText()); if (hashItem != null) { generarGrafico(); grafico = new Grafico(scene); diff --git a/src/cl/cromer/estructuras/code/tablaHash/buscar b/src/cl/cromer/estructuras/code/tablaHash/buscar new file mode 100644 index 0000000..5a7d78e --- /dev/null +++ b/src/cl/cromer/estructuras/code/tablaHash/buscar @@ -0,0 +1,17 @@ +public class HashItem { + final private String llave; + final private int valor; + + public HashItem(String llave, int valor) { + this.llave = llave; + this.valor = valor; + } + + public String getLlave() { + return llave; + } + + public int getValor() { + return valor; + } +} \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/tablaHash/eliminar b/src/cl/cromer/estructuras/code/tablaHash/eliminar new file mode 100644 index 0000000..5a7d78e --- /dev/null +++ b/src/cl/cromer/estructuras/code/tablaHash/eliminar @@ -0,0 +1,17 @@ +public class HashItem { + final private String llave; + final private int valor; + + public HashItem(String llave, int valor) { + this.llave = llave; + this.valor = valor; + } + + public String getLlave() { + return llave; + } + + public int getValor() { + return valor; + } +} \ No newline at end of file diff --git a/src/cl/cromer/estructuras/code/tablaHash/insertar b/src/cl/cromer/estructuras/code/tablaHash/insertar new file mode 100644 index 0000000..588b2e0 --- /dev/null +++ b/src/cl/cromer/estructuras/code/tablaHash/insertar @@ -0,0 +1,40 @@ +public void insertar(String llave, int valor) { + // Crear un HashItem que contiene la llave y valor. + HashItem hashItem = new HashItem(llave, valor); + int hashIndice = hash(hashItem.getLlave()); + int i = 0; + // Buscar un indice vacio. + while (hashArray[hashIndice] != null && hashArray[hashIndice].getLlave() != null && i < tamano) { + if (hashArray[hashIndice].getLlave().equals(llave)) { + //La llave ya existe. + return; + } + hashIndice++; + // Si hashIndice es mayor que el tamaño maximo, hay que empezar desde 0. + hashIndice = hashIndice % tamano; + i++; + } + + if (i != 10) { + // Insertar el HashItem en el array. + hashArray[hashIndice] = hashItem; + } +} + +public class HashItem { + final private String llave; + final private int valor; + + public HashItem(String llave, int valor) { + this.llave = llave; + this.valor = valor; + } + + public String getLlave() { + return llave; + } + + public int getValor() { + return valor; + } +} \ No newline at end of file diff --git a/src/cl/cromer/estructuras/fxml/hashTable.fxml b/src/cl/cromer/estructuras/fxml/hashTable.fxml index 0eec402..415cef2 100644 --- a/src/cl/cromer/estructuras/fxml/hashTable.fxml +++ b/src/cl/cromer/estructuras/fxml/hashTable.fxml @@ -5,7 +5,7 @@ + xmlns="http://javafx.com/javafx/8.0.92" fx:controller="cl.cromer.estructuras.TablaHashController">