?? tennisball.java
字號(hào):
/*
* @(#) $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 + ")";
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -