trip.java

来自「Program helping you to remember the rout」· Java 代码 · 共 35 行

JAVA
35
字号
public class Trip { 
    String  description;
    Point[] points;
    int     time;
    int     id;

    byte[] pack() { 
        byte[] desc = Converter.packString(description);
        byte[] buf = new byte[desc.length + 8];
        Converter.packInt(buf, 4, time);
        System.arraycopy(desc, 0, buf, 8, desc.length);
        return buf;
    }

    void unpack(byte[] buf) {        
        time = Converter.unpackInt(buf, 4);
        description = Converter.unpackString(buf, 8, buf.length - 8);
    }

    Trip(int id, byte[] buf) { 
        this.id = id;
        unpack(buf);
    }

    int duration() { 
        return points.length > 0 ? points[points.length-1].time - time : 0;
    }

    Trip(String description, int time) { 
        this.description = description;
        this.time = time;
        points = new Point[0];
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?