Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.80 KB | None | 0 0
  1. package C2;
  2.  
  3. import C1.GPiece;
  4.  
  5. import java.util.ArrayList;
  6. import java.util.Collection;
  7.  
  8. import metier.PC;
  9. import metier.Piece;
  10.  
  11. public class ServiceProd extends ServiceGeneral {
  12.     /**
  13.      */
  14.     private static ServiceProd instance;
  15.  
  16.     /**
  17.      */
  18.     private ServiceProd(){}
  19.  
  20.     /**
  21.      * @param nom
  22.      * @param pa
  23.      * @return
  24.      */
  25.     public Integer ajouterPB(String nom, double pa) {
  26.         return GPiece.getInstance().nouvellePB(nom, pa);
  27.     }
  28.  
  29.     /**
  30.      * @param nom
  31.      * @param ca
  32.      * @param composants
  33.      * @return
  34.      */
  35.     public Integer ajouterPC(String nom, double ca, Collection<Integer> composants) {
  36.         ArrayList<Piece> listPc=new ArrayList<Piece>();
  37.         for(Integer id : composants){
  38.             listPc.add(GPiece.getInstance().getPiece(id));
  39.         }
  40.        
  41.         return GPiece.getInstance().nouvellePC(nom, ca,listPc);
  42.     }
  43.  
  44.     public void ajouterComposant(Integer idComposant, Integer idPieceComposite) {
  45.         PC pC =(PC)GPiece.getInstance().getPiece(idPieceComposite);
  46.         Piece p2 = GPiece.getInstance().getPiece(idComposant);
  47.        
  48.        
  49.         //On récupère les pièces dispos
  50.         if(pC!=null && pC.getType().equals("PC")){
  51.             ArrayList<Piece> pieceDispo=new ArrayList<Piece>(GPiece.getInstance().listerPieces());
  52.             for(Piece piece : GPiece.getInstance().listerPieces()){
  53.                 if(piece.getType().equals("PC")){
  54.                     PC piececompo=(PC)piece;
  55.                     for(Piece piece2 : piececompo.getComposants()){
  56.                         pieceDispo.remove(piece2);
  57.                     }
  58.                 }
  59.             }
  60.             //On vérifie si p2 est dispo
  61.             if(pieceDispo.contains(p2)){
  62.                 pC.rajouterPiece(p2);
  63.             }
  64.         }
  65.     }
  66.    
  67.  
  68.     public String getPieceComplexe() {
  69.         int id=GPiece.getInstance().listerPieces().get(1).getId();
  70.         for(Piece p : GPiece.getInstance().listerPieces()){
  71.             if(p.getComplexite()>GPiece.getInstance().getPiece(id).getComplexite()){
  72.                 id=p.getId();
  73.             }
  74.         }
  75.         return GPiece.getInstance().getPiece(id).descriptionStandard();
  76.     }
  77.  
  78.     public void supprimerPiece(Integer numid) {
  79.         if(GPiece.getInstance().getPiece(numid).getType().equals("PC")){
  80.             PC pieceCompo=(PC)GPiece.getInstance().getPiece(numid);
  81.             for(Piece p : pieceCompo.getComposants()){
  82.                 supprimerPiece(p.getId());
  83.                 pieceCompo.supprimerComposant(p);
  84.             }
  85.         }
  86.         GPiece.getInstance().supprimerPiece(numid);
  87.        
  88.     }
  89.  
  90.     public static ServiceProd getInstance() {
  91.         if(instance==null){
  92.             instance=new ServiceProd();
  93.         }
  94.         return instance;
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement