customerserviceagent.java

来自「BOOK:Beginning Algorithms Code Example」· Java 代码 · 共 52 行

JAVA
52
字号
package com.wrox.algorithms.queues;/** * Services {@link Call}s by pulling them off a {@link Queue}. * */public class CustomerServiceAgent implements Runnable {    /** Indicates it's time for the agent to finish. */    public static final Call GO_HOME = new Call(-1, 0);    /** The id of the agent. */    private final int _id;    /** The queue from which to pull calls. */    private final Queue _calls;    /**     * Constructor.     *     * @param id The id of the agent.     * @param calls The queue from which to pull calls.     */    public CustomerServiceAgent(int id, Queue calls) {        assert calls != null : "calls can't be null";        _id = id;        _calls = calls;    }    public void run() {        System.out.println(this + " clocked on");        while (true) {            System.out.println(this + " waiting");            Call call = (Call) _calls.dequeue();            System.out.println(this + " answering " + call);            if (call == GO_HOME) {                break;            }            call.answer();        }        System.out.println(this + " going home");    }    public String toString() {        return "Agent " + _id;    }}

⌨️ 快捷键说明

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