Skip to content

Instantly share code, notes, and snippets.

@DuckHunter213
Created October 13, 2017 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DuckHunter213/b3e187374163e850d1b7bc97607fc641 to your computer and use it in GitHub Desktop.
Save DuckHunter213/b3e187374163e850d1b7bc97607fc641 to your computer and use it in GitHub Desktop.
Cast ArrayList to List and List to ArrayList and Generate a ID
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
/**
*
* @author Luis Fernando Gomez Alejandre
*/
public class Util{
/**
* Esta clase genera un identificador que tiene formato YYYMMDDHHmmSS se
* (año, mes, día, hora, minuto y segundo). Se eligió ésta estructura pues
* garantiza que sean datos únicos e imposibles de recrear debido a su
* exactitud, además, otorga información extra de su registro
*
* @return se regresa un String del identificador ya generado
*/
public static String generarMatricula(){
Date fecha = new Date();
SimpleDateFormat formateadorDeFecha = new SimpleDateFormat("yyyMMddHHmmss");
String matricula = formateadorDeFecha.format(fecha);
matricula = (String) matricula.subSequence(1, matricula.length());
return matricula;
}
public static ArrayList castListToArray(List lista){
ArrayList resultado = new ArrayList<>();
for (Object object : lista){
resultado.add(object);
}
return resultado;
}
public static List castArrayToList(ArrayList lista){
List resultado = new ArrayList<>();
for (Object object : lista){
resultado.add(object);
}
return resultado;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment