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 Utilitaire;
- import Modele.Compte;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.Serializable;
- import java.util.List;
- /**
- *
- * @author p1603766
- */
- public class Conteneur<Compte extends Serializable>{
- private int indiceCourant = 0;
- private List<Compte> lesValeurs;
- public Conteneur(){
- }
- public Conteneur(List<Compte> m){
- this.lesValeurs = m;
- }
- public void charger(String nomFic) throws FileNotFoundException, IOException, ClassNotFoundException{
- File CompteFile = new File(nomFic);
- FileInputStream fis = new FileInputStream(CompteFile);
- ObjectInputStream ois = new ObjectInputStream(fis);
- List<Compte> tab = (List<Compte>)ois.readObject();
- ois.close();
- this.lesValeurs = tab;
- }
- public void dernier(){
- this.indiceCourant = this.lesValeurs.size()-1;
- }
- public boolean estVide(){
- return lesValeurs.isEmpty();
- }
- public int nbElements(){
- return this.lesValeurs.size();
- }
- public Compte obtenir(){
- return this.lesValeurs.get(indiceCourant);
- }
- public void precedent(){
- this.indiceCourant--;
- }
- public void premier(){
- this.indiceCourant = 0;
- }
- public void sauvegarder(String nomFic) throws FileNotFoundException, IOException{
- File CompteFile = new File(nomFic);
- FileOutputStream fos = new FileOutputStream(CompteFile);
- ObjectOutputStream obs = new ObjectOutputStream(fos);
- obs.writeObject(this.lesValeurs);
- obs.close();
- }
- public void suivant(){
- this.indiceCourant++;
- }
- public void vider(){
- this.lesValeurs.clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement