Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package com.webservices.model.beans;
  7.  
  8. import java.io.File;
  9. import java.io.FileOutputStream;
  10. import java.io.ObjectOutputStream;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13.  
  14. public class AdminEmpleados {
  15.  
  16. private static AdminEmpleados instance = null;
  17.  
  18. public List<Empleado> empleados;
  19.  
  20. private AdminEmpleados() {
  21. this.empleados = new ArrayList<Empleado>();
  22. }
  23.  
  24. public static AdminEmpleados getInstance() {
  25. if (instance == null) {
  26. instance = new AdminEmpleados();
  27. }
  28. return instance;
  29. }
  30.  
  31. public List<Empleado> getEmpleados() {
  32. return empleados;
  33. }
  34.  
  35. public void setEmpleados(List<Empleado> empleados) {
  36. this.empleados = empleados;
  37. }
  38.  
  39. public boolean addEmployee(Empleado empleado){
  40. boolean added = false;
  41. for(Empleado emp: empleados){
  42. if(!emp.getIdEmpleado().equals(empleado.getIdEmpleado())){
  43. empleados.add(empleado);
  44. added = true;
  45. }//if
  46. }//for
  47. saveEmployeeList();
  48. return added;
  49. }
  50.  
  51. private void saveEmployeeList() {
  52. try {
  53. File file = new File("Users.dat");
  54. FileOutputStream fos;
  55. fos = new FileOutputStream(file);
  56. ObjectOutputStream oos = new ObjectOutputStream(fos);
  57. oos.writeObject(empleados);
  58. oos.close();
  59. } catch (Exception e) {
  60. e.printStackTrace();
  61. }
  62.  
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement