Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.webservices.model.beans;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.ObjectOutputStream;
- import java.util.ArrayList;
- import java.util.List;
- public class AdminEmpleados {
- private static AdminEmpleados instance = null;
- public List<Empleado> empleados;
- private AdminEmpleados() {
- this.empleados = new ArrayList<Empleado>();
- }
- public static AdminEmpleados getInstance() {
- if (instance == null) {
- instance = new AdminEmpleados();
- }
- return instance;
- }
- public List<Empleado> getEmpleados() {
- return empleados;
- }
- public void setEmpleados(List<Empleado> empleados) {
- this.empleados = empleados;
- }
- public boolean addEmployee(Empleado empleado){
- boolean added = false;
- for(Empleado emp: empleados){
- if(!emp.getIdEmpleado().equals(empleado.getIdEmpleado())){
- empleados.add(empleado);
- added = true;
- }//if
- }//for
- saveEmployeeList();
- return added;
- }
- private void saveEmployeeList() {
- try {
- File file = new File("Users.dat");
- FileOutputStream fos;
- fos = new FileOutputStream(file);
- ObjectOutputStream oos = new ObjectOutputStream(fos);
- oos.writeObject(empleados);
- oos.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement