Java世界

学习笔记

常用链接

统计

积分与排名

天籁村

新华网

雅虎

最新评论

海运项目: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();
    }
    

}

posted on 2007-11-16 14:03 Rabbit 阅读(610) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: