海運項目:Exporter類
package com.sinojava.haiyun;import java.io.*;
import java.util.*;
import java.util.regex.*;
import java.util.Properties;
//給服務器端使用的類
public class Exporter extends AbstractBL implements Serializable {
?? ?//海運中的變量參數
?? ?private String shipname;
?? ?private String voyage;
?? ?private String blno;
?? ?private String destination;
?? ?private String cnttype;
?? ?private int cntsize;
?? ?private int cntqnt;
?? ?private String cntoperator;
?? ?private String remark = "無";
?? ?//集合來存放解析出來的對象
?? ?ArrayList list = new ArrayList();
?? ?//創建Operator的對象op
?? ?Operator op = new Operator();
?? ?
?? ?//獲取與設置
?? ?public String getBlno() {
?? ??? ?return blno;
?? ?}
?? ?public void setBlno(String blno) {
?? ??? ?this.blno = blno;
?? ?}
?? ?public String getCntoperator() {
?? ??? ?return cntoperator;
?? ?}
?? ?public void setCntoperator(String cntoperator) {
?? ??? ?this.cntoperator = cntoperator;
?? ?}
?? ?public int getCntqnt() {
?? ??? ?return cntqnt;
?? ?}
?? ?public void setCntqnt(int cntqnt) {
?? ??? ?this.cntqnt = cntqnt;
?? ?}
?? ?public int getCntsize() {
?? ??? ?return cntsize;
?? ?}
?? ?public void setCntsize(int cntsize) {
?? ??? ?this.cntsize = cntsize;
?? ?}
?? ?public String getCnttype() {
?? ??? ?return cnttype;
?? ?}
?? ?public void setCnttype(String cnttype) {
?? ??? ?this.cnttype = cnttype;
?? ?}
?? ?public String getDestination() {
?? ??? ?return destination;
?? ?}
?? ?public void setDestination(String destination) {
?? ??? ?this.destination = destination;
?? ?}
?? ?public String getRemark() {
?? ??? ?return remark;
?? ?}
?? ?public void setRemark(String remark) {
?? ??? ?this.remark = remark;
?? ?}
?? ?public String getShipname() {
?? ??? ?return shipname;
?? ?}
?? ?public void setShipname(String shipname) {
?? ??? ?this.shipname = shipname;
?? ?}
?? ?public String getVoyage() {
?? ??? ?return voyage;
?? ?}
?? ?public void setVoyage(String voyage) {
?? ??? ?this.voyage = voyage;
?? ?}
?? ?
?? ?//字符串的解析
?? ?public void splitText(String str) {
?? ??? ?//解析出一行,換行處代替成空格
?? ??? ?String s1[] = str.replace("\n"," ").split("\\#");?? ?
?? ??? ?//解析然后放入集合中
?? ??? ?for(int i=0;i<s1.length-1;i++) {
?? ??? ??? ?//定義一個Exporter的局部對象
?? ??? ??? ?Exporter exe2 = new Exporter();
?? ??? ??? ?//解析單個字符
?? ??? ??? ?String s2[] = s1[i].trim().split(":");
??????????? //判斷字符開頭一字母開頭
?? ??? ??? ?boolean b = Pattern.matches("[A-Z]*+",s2[0]);
?? ??? ??? ?//true時進行單頭操作,false時進行箱子的操作
?? ??? ??? ?try {
?? ??? ??? ??? ?if(b) {?? ?
?? ??? ??? ??? ??? ?exe2.setShipname(s2[0]);
?? ??? ??? ??? ??? ?exe2.setVoyage(s2[1]);
?? ??? ??? ??? ??? ?exe2.setBlno(s2[2]);
?? ??? ??? ??? ??? ?exe2.setDestination(s2[3]);
?? ??? ??? ??? ??? ?list.add(exe2);
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else {
?? ??? ??? ??? ??? ?//返回指定位置上的元素
?? ??? ??? ??? ??? ?exe2 = (Exporter)list.get(list.size()-1);
?? ??? ??? ??? ??? ?//判斷是否單頭處理完
?? ??? ??? ??? ??? ?if(exe2.getCntsize()!=0)
?? ??? ??? ??? ??? ?{
?? ??? ??? ??? ??? ??? ?Exporter old = exe2;
?? ??? ??? ??? ??? ??? ?exe2 = new Exporter();
?? ??? ??? ??? ??? ??? ?exe2.setShipname(old.getShipname());
?? ??? ??? ??? ??? ??? ?exe2.setVoyage(old.getVoyage());
?? ??? ??? ??? ??? ??? ?exe2.setBlno(old.getBlno());
?? ??? ??? ??? ??? ??? ?exe2.setDestination(old.getDestination());
?? ??? ??? ??? ??? ??? ?list.add(exe2);
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?//放入箱子的內容
?? ??? ??? ??? ??? ?exe2.setCntsize(Integer.parseInt(s2[0]));
?? ??? ??? ??? ??? ?exe2.setCnttype(s2[1]);
?? ??? ??? ??? ??? ?exe2.setCntqnt(Integer.parseInt(s2[2]));
?? ??? ??? ??? ??? ?exe2.setCntoperator(s2[3]);
?? ??? ??? ??? ?}
?? ??? ??? ?}catch(Exception e) {
?? ??? ??? ??? ?e.printStackTrace();
?? ??? ??? ?}
?? ??? ?}
?? ??? ?
?? ?}
?? ?
?? ?//取單號
?? ?public String getIsequence() {
?? ??? ?String strBlno = this.getBlno().substring(this.getBlno().indexOf(" "),this.getBlno().length()).trim();
?? ??? ?return strBlno;
?? ?}
?? ?//取單頭
?? ?public String getIBlHead() {
?? ??? ?String strHead = this.getBlno().substring(0,this.getBlno().indexOf(" ")).trim();
?? ??? ?return strHead;
?? ?}
?? ?
?? ?public String toString() {
?? ??? ?return "船名:"+"\t"+shipname+
?? ??? ?"\n航次:"+"\t"+voyage+
?? ??? ?"\n提單號:"+"\t"+blno+
?? ??? ?"\n目的港:"+"\t"+destination+
?? ??? ?"\n集裝箱尺寸:"+"\t"+cntsize+
?? ??? ?"\n箱型:"+"\t"+cnttype+
?? ??? ?"\n箱量:"+"\t"+cntqnt+
?? ??? ?"\n經紀人:"+"\t"+getAllName()+
?? ??? ?"\n備注:"+"\t"+getRRmark()+"\n\n";?? ?
?? ?}
?? ?//實現輔助功能
?? ?public String getRRmark() {?? ??? ?
?? ??? ?if(getIBlHead().equals("HUB")) {
?? ??? ??? ?setRemark("SOC");
?? ??? ?} else if(getIBlHead().equals("SNL")) {
?? ??? ??? ?setRemark("SOC");
?? ??? ?}
?? ??? ?return getRemark();
?? ?}
?? ?//如果經紀人符合則改變其名字
?? ?public String getAllName(){
?? ??? ?if (getCntoperator().equals("HUB"))
?? ??? ??? ?setCntoperator(op.getNameOne());
?? ??? ?if (getCntoperator().equals("SNL"))
?? ??? ??? ?setCntoperator(op.getNameTwo());
?? ??? ?if (getCntoperator().equals("JL"))
?? ??? ??? ?setCntoperator(op.getNameThree());
?? ??? ?return getCntoperator();
?? ?}
?? ?
}