Package net.sf.cannagrower.data.event

Source Code of net.sf.cannagrower.data.event.Plants

package net.sf.cannagrower.data.event;

import java.util.Vector;
import java.io.Serializable;

import net.sf.cannagrower.data.Event;
import net.sf.cannagrower.data.Variety;
import net.sf.cannagrower.gui.PanelEvent;
import net.sf.cannagrower.gui.PanelEventPlants;

public class Plants extends Event {
  static final long serialVersionUID = 1L;
 
  private Vector<PlantsPerVariety>  plantsPerVarieties=new Vector<PlantsPerVariety>();
 
  public String toString() {
    String append="";
   
    if(getVarieties().size()<=0){return super.toString();}
   
    for(Variety variety:getVarieties()){
      if(!append.equals("")){append+=" / ";}
      append+=getPlants(variety)+" x "+variety.getName();
    }
   
    return toString(append);
  }
 
  public PanelEvent getViewer() {
    return new PanelEventPlants();
  }
 
  public Vector<Variety> getVarieties(){
    Vector<Variety> varieties=new Vector<Variety>();
    for(PlantsPerVariety plantsPerVariety:plantsPerVarieties){
      varieties.add(plantsPerVariety.getVariety());
    }
    return varieties;
  }
  public int getPlants(Variety variety){
    PlantsPerVariety plantsPerVariety;
    plantsPerVariety=search(variety);
    if(plantsPerVariety==null){return 0;}
    return plantsPerVariety.getPlants();
  }
 
  public void setPlants(Variety variety,int plants){
    PlantsPerVariety plantsPerVariety=search(variety);
    if(plantsPerVariety==null){
      if(plants==0){return;}
      // Retrieve unlinked variety
      variety=variety.getUnlinked();
      // Add
      plantsPerVariety=new PlantsPerVariety();
      plantsPerVariety.setPlants(plants);
      plantsPerVariety.setVariety(variety);
      plantsPerVarieties.add(plantsPerVariety);
    }else{
      if(plants==0){
        plantsPerVarieties.remove(plantsPerVariety);
      }else{
        plantsPerVariety.setPlants(plants);
      }
    }
    setModified(true);
  }
 
  private PlantsPerVariety search(Variety variety){
    for(PlantsPerVariety plantsPerVariety:plantsPerVarieties){
      if(plantsPerVariety.getVariety().equals(variety)){return plantsPerVariety;}
    }
    return null;
  }
}

class PlantsPerVariety implements Serializable{
  static final long serialVersionUID = 1L;
 
  private int     plants;
  private Variety   variety;
 
  public int getPlants() {
    return plants;
  }
  public void setPlants(int plants) {
    this.plants = plants;
  }
  public Variety getVariety() {
    return variety;
  }
  public void setVariety(Variety variety) {
    this.variety = variety;
  }
 
}
TOP

Related Classes of net.sf.cannagrower.data.event.Plants

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.