⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tennisball.java

📁 利用mina框架写的一个通信实例。初学者的一个好教程。
💻 JAVA
字号:
/*
 * @(#) $Id: TennisBall.java 357871 2005-12-20 01:56:40Z trustin $
 */
package org.apache.mina.examples.tennis;

/**
 * A tennis ball which has TTL value and state whose value is one of 'PING' and
 * 'PONG'.
 * 
 * @author The Apache Directory Project (dev@directory.apache.org)
 * @version $Rev: 357871 $, $Date: 2005-12-20 10:56:40 +0900 (Tue, 20 Dec 2005) $
 */
public class TennisBall {
	private final boolean ping;

	private final int ttl;

	/**
	 * Creates a new ball with the specified TTL (Time To Live) value.
	 */
	public TennisBall(int ttl) {
		this(ttl, true);
	}

	/**
	 * Creates a new ball with the specified TTL value and PING/PONG state.
	 */
	private TennisBall(int ttl, boolean ping) {
		this.ttl = ttl;
		this.ping = ping;
	}

	/**
	 * Returns the TTL value of this ball.
	 */
	public int getTTL() {
		return ttl;
	}

	/**
	 * Returns the ball after {@link TennisPlayer}'s stroke. The returned ball
	 * has decreased TTL value and switched PING/PONG state.
	 */
	public TennisBall stroke() {
		return new TennisBall(ttl - 1, !ping);
	}

	/**
	 * Returns string representation of this message (<code>[PING|PONG]
	 * (TTL)</code>).
	 */
	public String toString() {
		if (ping) {
			return "PING (" + ttl + ")";
		} else {
			return "PONG (" + ttl + ")";
		}
	}
}

⌨️ 快捷键说明

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