Created
October 13, 2017 13:52
-
-
Save DuckHunter213/b3e187374163e850d1b7bc97607fc641 to your computer and use it in GitHub Desktop.
Cast ArrayList to List and List to ArrayList and Generate a ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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