Package net.sf.cannagrower.data

Source Code of net.sf.cannagrower.data.Variety

package net.sf.cannagrower.data;

import java.io.Serializable;

import net.sf.cannagrower.i18n.Messages;
import net.sf.orexio.lopf.Data;
import net.sf.orexio.lopf.DataSettings;

/**
* This class store a plantation variety
*
* @author alois_cochard@users.sf.net
*
*/
public class Variety extends Data implements Serializable,Cloneable {
  static final long serialVersionUID = 1L;

  private String    name=Messages.getMessage(Messages.messageNoName);

  private int      flowering=7;      // Number of weeks for flowering
 
  private String     informations;
 
  transient private Variety  unlinked=null;

  public DataSettings getSettings(){return new DataSettings(Variety.class,5);}
 
  public int compare(Data data){
    if(data instanceof Variety){
      Variety variety=(Variety)data;
      return this.getName().compareTo(variety.getName());
    }
    return super.compare(data);
  }
 
  public Object clone() {
      try {
        return super.clone();
      } catch(CloneNotSupportedException e) {
          Messages.showException(e);
      }
      return null;
    }
 
  public String toString(){return getName();}

  public long getRank(){
    String rank="";
    //  Generate rank
    for(byte value:getName().getBytes()){
      String sValue=String.valueOf(value);
      while(sValue.length()<3){sValue="0"+sValue;}
      rank+=sValue;
      if(rank.length()>=9){break;}
    }
    while(rank.length()<9){rank=rank+"0";}
    return Long.parseLong(rank);
  }
 

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
    setModified(true);
  }

  public int getFlowering() {
    return flowering;
  }

  public void setFlowering(int flowering) {
    this.flowering = flowering;
    setModified(true);
  }

  public String getInformations() {
    return informations;
  }

  public void setInformations(String informations) {
    this.informations = informations;
  }
 
  public Variety getUnlinked(){
    if(unlinked==null){
      unlinked=(Variety)this.clone();
      unlinked.setParent(null);
    }
    return unlinked;
  }
}
TOP

Related Classes of net.sf.cannagrower.data.Variety

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.