gt: 		if (w == null) {
context: /*
   * Mars Simulation Project
   * Malfunction.java
   * @date 2021-11-16
   * @author Scott Davis
   */
  
  package org.mars_sim.msp.core.malfunction;
  
  import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.EnumMap;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import java.util.Map.Entry;
  import java.util.stream.Collectors;
  
  import org.mars_sim.msp.core.Unit;
  import org.mars_sim.msp.core.UnitType;
  import org.mars_sim.msp.core.logging.SimLogger;
  import org.mars_sim.msp.core.malfunction.MalfunctionMeta.EffortSpec;
  import org.mars_sim.msp.core.person.health.ComplaintType;
  import org.mars_sim.msp.core.resource.ItemResourceUtil;
  import org.mars_sim.msp.core.resource.ResourceUtil;
  import org.mars_sim.msp.core.structure.Settlement;
  import org.mars_sim.msp.core.tool.RandomUtil;
  import org.mars_sim.msp.core.vehicle.Vehicle;
  
  /**
   * The Malfunction class represents a malfunction in a vehicle, structure or
   * equipment.
   */
  public class Malfunction implements Serializable {
  
  	/**
  	 * Description of Repairer's effort
  	 */
  	public static class Repairer {
  		private String worker;
  		private boolean active;
  		private double workTime;
  
  		private Repairer(String worker, boolean active, double workTime) {
  			super();
  			this.worker = worker;
  			this.active = active;
  			this.workTime = workTime;
  		}
  
  		public String getWorker() {
  			return worker;
  		}
  
  		public boolean isActive() {
  			return active;
  		}
  
  		public double getWorkTime() {
  			return workTime;
  		}
  	}
  
  	/**
  	 * Records the effort spent of fixing one phase of the malfunction.
  	 */
  	private static final class RepairWork implements Serializable {
  
  		private static final long serialVersionUID = 1L;
  
  		String chiefRepairer;
  		String deputyRepairer;
  		double workExpected;
  		double workCompleted = 0D;
  		int desiredWorkers;
  
  		/** The map for storing how much work time the repairers spent in fixing this malfunction. */
  		private Map<String, Double> activeWorkers;
  		private Map<String, Double> previousWorkers;
  
  		public RepairWork(double actualEffort, int desiredWorkers) {
  			workExpected = actualEffort;
  			this.desiredWorkers = desiredWorkers;
  			activeWorkers = new HashMap<>();
  			previousWorkers = new HashMap<>();
  
  		}
  
  		public boolean isCompleted() {
  			return (workCompleted >= workExpected);
  		}
  
  		public int getAvailableSlots() {
  			return desiredWorkers - activeWorkers.size();
  		}
  
  		/**
  		 * Worker leaves the repair
  		 * @param name
  		 * @return If the worker was active
  		 */
  		public boolean leaveWork(String name) {
  			if (activeWorkers.containsKey(name)) {
  				Double previous = activeWorkers.remove(name);
  				// Don't remember worker who never contributed
  				if (previous.doubleValue() > 0D) {
  					previousWorkers.put(name, previous);
  				}
  				return true;
  			}
  			return false;
  		}
  
  		/**
  		 * Add some repair time for a worker
  		 * @param repairer
  		 * @param time
  		 */
  		public void addTime(String repairer, double time) {
  			double previousTime = 0D;
  			if (activeWorkers.containsKey(repairer)) {
  				previousTime = activeWorkers.get(repairer);
  			}
  			else if (previousWorkers.containsKey(repairer)) {
  				previousTime = previousWorkers.remove(repairer);
  			}
  
  			activeWorkers.put(repairer, previousTime + time);
  		}
  
  		/**
  		 * Get the repairers effort. For non-active works add a "*"
  		 * @return
  		 */
  		public List<Repairer> getEffort() {
  			List<Repairer> result = new ArrayList<>();
  			for(Entry<String, Double> entry : activeWorkers.entrySet()) {
  				result.add(new Repairer(entry.getKey(), true, entry.getValue()));
  			}
  			for(Entry<String, Double> entry : previousWorkers.entrySet()) {
  				result.add(new Repairer(entry.getKey(), false, entry.getValue()));
  			}
  			return result;
  		}
  	}
  
  	private static final long serialVersionUID = 1L;
  
  	/** default logger. */
  	private static SimLogger logger = SimLogger.getLogger(Malfunction.class.getName());
  
  	private static final String INCIDENT_NUM = " - Incident #";
  	private static final String REPAIR_REQUIRES = " - Repair requires ";
  	private static final String QUANTITY = " x";
  	private static final String CLOSE_B = ".";
  
  	// Data members
  	private int incidentNum;
  
  	private String name;
  	/* The person who are being the most traumatized by this malfunction. */
  	private String mostTraumatized = "None";
  	/* The definition instance of this malfunction. */
  	private MalfunctionMeta definition;
  	/* The map of repair part id and part quantity for this malfunction. */
  	private Map<Integer, Integer> repairParts;
  	/** Repair work required */
  	private EnumMap<MalfunctionRepairWork, RepairWork> work = new EnumMap<>(MalfunctionRepairWork.class);
  
  
  	/**
  	 * Create a new Malfunction instance based on a meta definition
  	 *
  	 * @param incident the incident id
  	 * @param definition the MalfunctionMeta instance
  	 * @param supportsInside Does the entity supports inside repairs
  	 */
  	Malfunction(int incident, MalfunctionMeta definition, boolean supportsInside) {
  		repairParts = new HashMap<>();
  
  		incidentNum = incident;
  		this.definition = definition;
  		StringBuilder builder = new StringBuilder().append(definition.getName()).append(INCIDENT_NUM)
  				.append(incidentNum);
  		this.name = builder.toString();
  
  		Map<MalfunctionRepairWork, EffortSpec> workEffort = definition.getRepairEffort();
  		for (Entry<MalfunctionRepairWork, EffortSpec> effort : workEffort.entrySet()) {
  			MalfunctionRepairWork type = effort.getKey();
  			
  			// If inside repairs; then change to EVA
  			if (!supportsInside && (type == MalfunctionRepairWork.INSIDE)) {
  				type = MalfunctionRepairWork.EVA;
  				logger.warning(0, name + " cannot do " + effort.getKey() + ", changed to " + type);
  			}
  			
  			double workTime = effort.getValue().getWorkTime();
  			double actualEffort = computeWorkTime(workTime);
  			if (actualEffort > (2 * Double.MIN_VALUE)) {
  				logger.info(10_000, name + " - Estimated " + type + " work time: "
  								+ Math.round(actualEffort*10.0)/10.0);
  				work.put(type, new RepairWork(actualEffort, effort.getValue().getDesiredWorkers()));
  			}
  		}
  
  		// What is need to repair malfunction
  		determineRepairParts();
  	}
  
  	/**
  	 * This find the details of a work type for this malfunction.
  	 * @param type Requested type
  	 * @return the RepairWork instance
  	 * @throws IllegalArgumentException If the type is not supported for this Malfunction
  	 */
  	private RepairWork getWorkType(MalfunctionRepairWork type) {
  		RepairWork w = work.get(type);
  