-
Notifications
You must be signed in to change notification settings - Fork 0
/
esteeselbueno.java
243 lines (230 loc) · 6.61 KB
/
esteeselbueno.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/**
* Importar .txt | .bin | .col
*/
public void importarTexto() throws IOException{
Path ruta = Rutas.pathToFileInFolderOnDesktop(namefolder,namefiletxt);
File file = ruta.toFile();
if(file.exists()){
try{
ArrayList<String> lineas = (ArrayList<String>) readAllLines(ruta);
for(String i : lineas){
String[] campos = i.split(delim);
Objeto objeto = Objeto.factory(campos);
if(objeto!=null){
listaObjetos.add(objeto);
}else{
System.err.printf("Error.%n");
}
}
}catch(IOException e){
e.printStackTrace();
}
}else{
System.err.printf("Error.%n");
}
}
public void importarBin(){
Path ruta =Rutas.pathToFileInFolderOnDesktop(namefolder,namefilebin);
File file = ruta.toFile();
try{
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(bis);
listaObjetos = (ArrayList<String>) ois.readObject();
ois.close();
}catch(IOException | ClassNotFoundException ex){
ex.printStackTrace();
}
}
public void importarCol(){
Path ruta =Rutas.pathToFileInFolderOnDesktop(namefolder,namefilecol);
File file = ruta.toFile();
try{
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(bis);
listaObjetos = (ArrayList<String>) ois.readObject();
ois.close();
}catch(IOException | ClassNotFoundException ex){
ex.printStackTrace();
}
}
/**
* Exportar .txt | .bin | .col | .html
*/
public void exportarTexto(){
Path ruta = Rutas.pathToFileInFolderOnDesktop(namefolder,namefiletxt);
File file = ruta.toFile();
String[][] data = new String[listaObjetos.size()][];
for(int i=0;i<listaObjetos.size();i++){
data[i] = listaObjetos.get(i).toString.split(delim);
}
try{
exportToDisk(data,file,delim);
}catch(IOException e){
e.printStackTrace();
}
}
public void exportarBinario(){
Path ruta = Rutas.pathToFileInFolderOnDesktop(namefolder,namefilebin);
File file = ruta.toFile();
try{
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(listaObjetos);
oos.close();
}catch(IOException e){
e.printStackTrace();
}
}
public void exportarCol() throws Exception{
boolean aux = true;
File file = new File(Rutas.pathToFolderOnDesktop(folder).toFile() + separador + "directores" + ".col");
Path p = f.toPath();
List<String> obj = new ArrayList<>();
for(Objetos o : listaobjetos){
obj.add(o.exportStateAsCol(aux));
}
Files.write(p,obj,Charset.forName("UTF-8"));
}
//en objeto
public String exportStateAsCol(boolean aux) throws ParseException{
String tituto = new String();
if(aux == true){
for(int i=0; i < this.caracteristicas.size();i++){
titulo += this.caracteristicas.get(i).getCaracteristica() + "\t";
}
}else{
return String.format("%-30s%-20s%-20s%-70s",this.Atr1,this.Atr2,this.Atr3,this.Atr4);
}
return String.format("%-30s%-20s%-20s%-70s%-80s",this.Atr1,this.Atr2,this.Atr3,this.Atr4,caracteristica);
}
public void exportarHTML(){
File f = new File(Rutas.pathToFolderOnDesktop(folder).toFile()+separador+namearchivo);
PrintWriter pw = new PrintWriter(f);
pw.printf(formatohtml);
for(Objeto o : listaObjetos){
pw.printf("%s%n",o.exportAsHTML());
}
pw.print(cierrehtml);
pw.close();
}
//en objeto
public void exportAsHTML(){
return String.format("<TD>%s</TD>"
+ "<TD>%d</TD>"
+ "<TD>%d</TD>"
+ "<TD>%s</TD>",
this.Atr1,this.Atr2,this.Atr3);
}
/**
* Mapas
*/
public void prepararMapa(){
for(Objeto obj : listaObjetos){
mapa.put(obj.getAtr2,obj);
}
}
public String datosComoStringDelimMapa(String Atr2, String delim){
Objeto obj = mapa.get(Atr2);
String token = obj.getAtr1)+delim+obj.getAtr2()+delim+obj.getAtr3)+delim;
return token;
}
/**
* Modificar o Consultar
*/
public void modificar(String Atr1, String newAtr1){
for(Objeto obj : listaObjetos){
if(obj.getAtr1().equalsIgnoreCase(Atr1)){
obj.setAtr1(newAtr1);
}
}
}
public String consultar(String Atr1){
String consulta = "";
for(Objeto obj : listaObjetos){
if(obj.getAtr1().equalsIgnoreCase(Atr1)){
consulta=obj.getAtr1()+" "+obj.getAtr2()+" "+obj.getAtr3()+" ";
for(String caracteristicas : objeto.caracteristicas){
consulta=consulta+carecteristicas+"\n";
}
}
}
return consulta;
}
/**
* Ordenar
*/
public void ordenar(){
listaObjetos.sort(Comparator.comparing(Objeto::getAtr1).thenComparing(Objeto::getAtr2).thenComparing(Objeto::getAtr3));
}
public String[] ordenar(){
String[] objordenado = new String[listaobjetos.size()];
Collections.sort(listaobjetos, new Comparato<Objeto>()){
public int compare(Objeto o1, Objeto o2){
return o1.getAtr1().compateTo(o2.getAtr1());
}
});
for(int i=0;i<listaObjetos.size();i++){
objordenado[i]= listaObjetos.get(i).exportStateAsCol()
}
return objordenado;
}
/**
* ToString y Mostrar por pantalla
*/
public void toString(){
return atr1+"#"+atr2+"#"+atr3+"#"+atr4+"#";
}
public void toString(){
String data = "";
data = o.getAtr1()+"#"+o.getAtr2()+"#"+o.Atr3+"#"+o.Atr4+"#";
for(String i : Atr5){
data = data +" "+i;
}
}
public String[] estadoComoArrayDeCadenas(){
String[] linea = null;
linea[0] = this.nombre;
linea[1] = this.ap1;
linea[2] = this.ap2;
linea[3] = String.valueOf(this.edad);
linea[4] = String.valueOf(this.talla);
linea[5] = String.valueOf(this.peso);
return linea;
}
public void ArrayListToMatrix(){
String[][] data = new String[listaObjetos.size()][];
for(int i=0;i<listaObjetos.size();i++){
data[i] = listaObjetos.get(i).toString().split("#");
}
return data;
printToScreen3(data);
}
/**
* Factory
*/
public static Objeto factory(String linea, String delim){
String[] campos = linea.split(delim);
try{
int tok1 = Integer.parseInt(campos[4]);
float tok2 = Float.parseFloat(campos[5]);
double tok3 = Double.parseDouble(campos[6]);
return new Objeto(campos[0],campos[1],campos[2],campos[3],tok1,tok2,tok3);
}catch(NumberFormatException e){
e.printStackTrace();
return null;
}
}
public static Objeto factory(String[] campos){
try{
int tok1 = Integer.parseInt(campos[4]);
float tok2 = Float.parseFloat(campos[5]);
double tok3 = Double.parseDouble(campos[6]);
return new Objeto(campos[0],campos[1],campos[2],campos[3],tok1,tok2,tok3);
}catch(NumberFormatException e){
e.printStackTrace();
return null;
}
}