/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package inport; import inport.ConversionUtils.Utils; import java.util.*; /** * * @author topazh_ag */ public class Operation { private OperationTemplate template; private boolean fixation = false; private double start; private double duration; private MovingObject executor; private Optional bunker = Optional.empty(); private Optional intensity = Optional.empty(); private List resources; public void setIntensity(Optional intensity) { this.intensity = intensity; } public Optional getIntensity() { return intensity; } public Optional getBunker() { return bunker; } public void setBunker(Optional bunker) { this.bunker = bunker; } public boolean getFixation() { return fixation; } public void setFixation(boolean fixation) { this.fixation = fixation; } public List getResources() { return resources; } public void setResources(List resources) { this.resources = resources; } public MovingObject getExecutor() { return executor; } public void setExecutor(MovingObject executor) { this.executor = executor; } /** * Get the value of duration * * @return the value of duration */ public double getDuration() { return duration; } /** * Set the value of duration * * @param duration new value of duration */ public void setDuration(double duration) { this.duration = duration; } /** * Get the value of start * * @return the value of start */ public double getStart() { return start; } /** * Set the value of start * * @param start new value of start */ public void setStart(double start) { this.start = start; } /** * Get the value of template * * @return the value of template */ public OperationTemplate getTemplate() { return template; } /** * Set the value of template * * @param template new value of template */ public void setTemplate(OperationTemplate template) { this.template = template; } public Operation() { } @Override public String toString() { if (executor == null) { executor = Utils.getExecutor(template); } if (resources == null) { resources = Utils.getResources(template); } StringBuilder sb = new StringBuilder(); sb.append(template.getId()).append("; "); sb.append(fixation ? "F" : "R").append("; ").append(start).append("; ").append(duration); sb.append(" (").append(executor.getId()).append(" "); sb.append(bunker.map(b -> b.getId() + " ").orElse("")).append("["); boolean isFirst = true; for (MovingObject obj : resources) { if (isFirst) { isFirst = false; } else { sb.append(", "); } sb.append(obj.getId()); } sb.append("]"); sb.append(intensity.map(i -> " " + i).orElse("")); sb.append(")"); return sb.toString(); } public Operation(String str, Map m_vessel, Map m_bunker, Map m_equipment, Map m_template) { String lStr = str.substring(0, str.indexOf('(')).trim(); String rStr = str.substring(str.indexOf('(') + 1, str.indexOf(')')).trim(); { String[] items = lStr.split(";"); setStart(Double.parseDouble(items[2].trim())); setDuration(Double.parseDouble(items[3].trim())); setTemplate(m_template.get(Integer.parseInt(items[0].trim()))); setFixation(items[1].trim().equals("F")); } { String[] items = rStr.substring(rStr.indexOf('[') + 1, rStr.indexOf(']')).split(","); ArrayList resources = new ArrayList<>(); for (String item : items) { if (item.trim().isEmpty()) { continue; } resources.add(m_equipment.get(Integer.valueOf(item.trim()))); } setResources(resources); } { String[] items = rStr.substring(0, rStr.indexOf('[')).split(" "); MovingObject ex = m_vessel.get(Integer.valueOf(items[0].trim())); if (ex == null) { ex = m_bunker.get(Integer.valueOf(items[0].trim())); } setExecutor(ex); if (items.length > 1) { setBunker(Optional.of(m_bunker.get(Integer.valueOf(items[1].trim())))); } } String intensity = rStr.substring(rStr.indexOf(']') + 1).trim(); if (! intensity.isEmpty()) { setIntensity(Optional.of(Integer.valueOf(intensity))); } } }