import java.util.*;
public class Vector_Personas {
public static void intercambia(Vector<Persona> vp, int i) {
Persona tmp = vp.get(i);
vp.setElementAt(vp.get(i + 1), i);
vp.setElementAt(tmp, i + 1);
}
public static void sort_apellido1(Vector<Persona> vp) {
Character pc1;
Character pc2;
for (int j = 1; j < vp.size(); j++) {
for (int i = 0; i < vp.size() - j; i++) {
pc1 = Character.toLowerCase(new Character(vp.get(i).getApellido1().charAt(0)));
pc2 = Character.toLowerCase(new Character(vp.get(i + 1).getApellido1().charAt(0)));
if (Character.getNumericValue(pc1) > Character.getNumericValue(pc2)) {
intercambia(vp, i);
}
}
}
}
public static void sort_nombre(Vector<Persona> vp) {
Character pc1;
Character pc2;
for (int j = 1; j < vp.size(); j++) {
for (int i = 0; i < vp.size() - j; i++) {
pc1 = Character.toLowerCase(new Character(vp.get(i).getNombre().charAt(0)));
pc2 = Character.toLowerCase(new Character(vp.get(i + 1).getNombre().charAt(0)));
if (Character.getNumericValue(pc1) > Character.getNumericValue(pc2)) {
intercambia(vp, i);
}
}
}
}
public static void sort_edad(Vector<Persona> vp) {
int pc1;
int pc2;
for (int j = 1; j < vp.size(); j++) {
for (int i = 0; i < vp.size() - j; i++) {
pc1 = vp.get(i).getEdad();
pc2 = vp.get(i + 1).getEdad();
if (pc1 > pc2) {
intercambia(vp, i);
}
}
}
}
public static void mostrar(Vector<Persona> vp) {
for (Enumeration it = vp.elements(); it.hasMoreElements();) {
Persona tmpperson = (Persona) it.nextElement();
System.out.print(" " + tmpperson.getNombre());
System.out.print(" " + tmpperson.getApellido1());
System.out.print(" " + tmpperson.getApellido2());
System.out.print(" " + tmpperson.getEdad());
System.out.println("");
}
}
public static void main(String[] args) {
Vector<Persona> vp = new Vector<Persona>();
//Estos datos se podrian Obtener de BD , files, etc.....
vp.add(new Persona("James", "Livingston", "", 22, "Italia"));
vp.add(new Persona("Jonathan", "Matthew", "", 16, "Madrid"));
vp.add(new Persona("Colin", "Walters", "", 25, "Suiza"));
vp.add(new Persona("Bastien", "Nocera", "", 30, "Mexico"));
vp.add(new Persona("Jose Manuel", "Vazquez", "Castro", 22, "Estado de Mexico - d.vinchi666@gmail.com"));
System.out.println("Antes de Ordenar");
mostrar(vp);
System.out.println("nnn");
sort_nombre(vp);
sort_apellido1(vp);
sort_edad(vp);
System.out.println("Despues de Ordenar");
mostrar(vp);
}
}