Advertisement
N_Damyanov

ManagerImpl

Apr 13th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. package cresla.Manager;
  2.  
  3. import cresla.entities.modules.CooldownSystem;
  4. import cresla.entities.modules.CryogenRod;
  5. import cresla.entities.modules.HeatProcessor;
  6. import cresla.entities.reactors.CryoReactor;
  7. import cresla.entities.reactors.HeatReactor;
  8. import cresla.interfaces.AbsorbingModule;
  9. import cresla.interfaces.EnergyModule;
  10. import cresla.interfaces.Module;
  11. import cresla.interfaces.Reactor;
  12.  
  13. import java.util.HashMap;
  14. import java.util.List;
  15. import java.util.Map;
  16.  
  17. public class ManagerImpl implements cresla.interfaces.Manager {
  18.  
  19.     private int id = 0;
  20.     private Map<Integer, Reactor> reactors;
  21.     private Map<Integer, Module> modules;
  22.  
  23.     public ManagerImpl() {
  24.         this.id = 1;
  25.         this.reactors = new HashMap<>();
  26.         this.modules = new HashMap<>();
  27.     }
  28.  
  29.     @Override
  30.     public String reactorCommand(List<String> arguments) {
  31.         String type = arguments.get(0);
  32.         int additionalParameter = Integer.parseInt(arguments.get(1));
  33.         int moduleCapacity = Integer.parseInt(arguments.get(2));
  34.  
  35.         Reactor reactor = null;
  36.  
  37.         if (type.equalsIgnoreCase("Cryo")) {
  38.             reactor = new CryoReactor(this.id, additionalParameter, moduleCapacity);
  39.         } else {
  40.             reactor = new HeatReactor(this.id, additionalParameter, moduleCapacity);
  41.         }
  42.         reactors.putIfAbsent(this.id, reactor);
  43.  
  44.  
  45.         return String.format("Created %s Reactor - %d", type, this.id++);
  46.     }
  47.  
  48.     @Override
  49.     public String moduleCommand(List<String> arguments) {
  50.         int reactorId = Integer.parseInt(arguments.get(0));
  51.         String type = arguments.get(1);
  52.         int additionalParameter = Integer.parseInt(arguments.get(2));
  53.  
  54.         Module module = null;
  55.  
  56.         if (type.equalsIgnoreCase("CryogenRod")) {
  57.             module = new CryogenRod(this.id, additionalParameter);
  58.             reactors.get(reactorId).addEnergyModule((EnergyModule) module);
  59.         } else if (type.equalsIgnoreCase("HeatProcessor")) {
  60.             module = new HeatProcessor(this.id, additionalParameter);
  61.             reactors.get(reactorId).addAbsorbingModule((AbsorbingModule) module);
  62.         } else if (type.equalsIgnoreCase("CooldownSystem")) {
  63.             module = new CooldownSystem(this.id, additionalParameter);
  64.             reactors.get(reactorId).addAbsorbingModule((AbsorbingModule) module);
  65.         }
  66.         modules.putIfAbsent(this.id, module);
  67.  
  68.         return String.format("Added %s - %d to Reactor - %d", type, this.id++, reactorId);
  69.     }
  70.  
  71.     @Override
  72.     public String reportCommand(List<String> arguments) {
  73.         return null;
  74.     }
  75.  
  76.     @Override
  77.     public String exitCommand(List<String> arguments) {
  78.         return null;
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement