I have the following code, what I do is read a dataset with the .csv format and pass its information to linked nodes.
It turns out that I want to add a new node to the linked list that I have and rewrite the dataset again with the new record, that is, with the new node. The idea is that to verify if the record already exists, if it does not exist, add it.
I guess it's up to glue the node (with its attributes) to the list but I can not find a way to add it to the list and write it in the dataset.
Here it reads the line and assign it to a node. The line has several attributes separated by ";". I also do a reading test.
package controller;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.xml.soap.Node;
import model.Nodo;
import java.io.BufferedReader;
public class Datos<E> {
public static String PATH = "resources\data.csv";
private FileReader fr = null;
private BufferedReader br = null;
private Nodo<String> node = null;
public Datos() {
try {
fr = new FileReader(PATH);
br = new BufferedReader(fr);
String lineaActual;
try {
while((lineaActual = br.readLine()) != null) {
node = new Nodo<String>(lineaActual);
System.out.println(node.getTitulo());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) {
Datos d = new Datos ();
}
}
The interface.
package interfaces;
public interface INodo <E> {
public E obtenerId();
}
//
And finally the node.
package model;
import interfaces.INodo;
public class Nodo <E> implements INodo<E> {
private E elemento;
private Nodo<E> siguiente;
private String titulo, estudio, estado, versiones, precio, clasificacion,
anio, genero, fechaPublicacionDVD, id;
public E getElemento() {
return elemento;
}
public String getTitulo() {
return titulo;
}
public String getEstudio() {
return estudio;
}
public String getEstado() {
return estado;
}
public String getVersiones() {
return versiones;
}
public String getPrecio() {
return precio;
}
public String getClasificacion() {
return clasificacion;
}
public String getAnio() {
return anio;
}
public String getGenero() {
return genero;
}
public String getFechaPublicacionDVD() {
return fechaPublicacionDVD;
}
public Nodo(E pElem) {
elemento = pElem;
String[] aux = elemento.toString().split(";");
titulo = aux[0];
estudio = aux[1];
estado = aux[2];
versiones = aux[3];
precio = aux[4];
clasificacion = aux[5];
anio = aux[6];
genero = aux[7];
fechaPublicacionDVD = aux[8];
id = aux[9];
siguiente = null;
}
public void enlazarSiguiente(Nodo<E> n) {
siguiente = n;
}
public Nodo<E> obtenerSiguiente(){
return siguiente;
}
@Override
public E obtenerId() {
return (E) id;
}
}
One hand, thank you.