Rename fromByte() to valueOf()

Motivation:

Persuit the consistency in method naming

Modifications:

Rename fromByte(byte) to valueOf(byte)

Result:

Consistency
This commit is contained in:
Trustin Lee 2014-06-24 16:34:52 +09:00
parent 33b9bc02ed
commit 45fde9abba
13 changed files with 68 additions and 12 deletions

View File

@ -28,7 +28,15 @@ public enum SocksAddressType {
this.b = b;
}
/**
* @deprecated Use {@link #valueOf(byte)} instead.
*/
@Deprecated
public static SocksAddressType fromByte(byte b) {
return valueOf(b);
}
public static SocksAddressType valueOf(byte b) {
for (SocksAddressType code : values()) {
if (code.b == b) {
return code;

View File

@ -42,7 +42,7 @@ public class SocksAuthRequestDecoder extends ReplayingDecoder<SocksAuthRequestDe
protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> out) throws Exception {
switch (state()) {
case CHECK_PROTOCOL_VERSION: {
version = SocksSubnegotiationVersion.fromByte(byteBuf.readByte());
version = SocksSubnegotiationVersion.valueOf(byteBuf.readByte());
if (version != SocksSubnegotiationVersion.AUTH_PASSWORD) {
break;
}

View File

@ -40,14 +40,14 @@ public class SocksAuthResponseDecoder extends ReplayingDecoder<SocksAuthResponse
throws Exception {
switch (state()) {
case CHECK_PROTOCOL_VERSION: {
version = SocksSubnegotiationVersion.fromByte(byteBuf.readByte());
version = SocksSubnegotiationVersion.valueOf(byteBuf.readByte());
if (version != SocksSubnegotiationVersion.AUTH_PASSWORD) {
break;
}
checkpoint(State.READ_AUTH_RESPONSE);
}
case READ_AUTH_RESPONSE: {
authStatus = SocksAuthStatus.fromByte(byteBuf.readByte());
authStatus = SocksAuthStatus.valueOf(byteBuf.readByte());
msg = new SocksAuthResponse(authStatus);
}
}

View File

@ -28,7 +28,15 @@ public enum SocksAuthScheme {
this.b = b;
}
/**
* @deprecated Use {@link #valueOf(byte)} instead.
*/
@Deprecated
public static SocksAuthScheme fromByte(byte b) {
return valueOf(b);
}
public static SocksAuthScheme valueOf(byte b) {
for (SocksAuthScheme code : values()) {
if (code.b == b) {
return code;

View File

@ -26,7 +26,15 @@ public enum SocksAuthStatus {
this.b = b;
}
/**
* @deprecated Use {@link #valueOf(byte)} instead.
*/
@Deprecated
public static SocksAuthStatus fromByte(byte b) {
return valueOf(b);
}
public static SocksAuthStatus valueOf(byte b) {
for (SocksAuthStatus code : values()) {
if (code.b == b) {
return code;

View File

@ -52,9 +52,9 @@ public class SocksCmdRequestDecoder extends ReplayingDecoder<SocksCmdRequestDeco
checkpoint(State.READ_CMD_HEADER);
}
case READ_CMD_HEADER: {
cmdType = SocksCmdType.fromByte(byteBuf.readByte());
cmdType = SocksCmdType.valueOf(byteBuf.readByte());
reserved = byteBuf.readByte();
addressType = SocksAddressType.fromByte(byteBuf.readByte());
addressType = SocksAddressType.valueOf(byteBuf.readByte());
checkpoint(State.READ_CMD_ADDRESS);
}
case READ_CMD_ADDRESS: {

View File

@ -45,16 +45,16 @@ public class SocksCmdResponseDecoder extends ReplayingDecoder<SocksCmdResponseDe
protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> out) throws Exception {
switch (state()) {
case CHECK_PROTOCOL_VERSION: {
version = SocksProtocolVersion.fromByte(byteBuf.readByte());
version = SocksProtocolVersion.valueOf(byteBuf.readByte());
if (version != SocksProtocolVersion.SOCKS5) {
break;
}
checkpoint(State.READ_CMD_HEADER);
}
case READ_CMD_HEADER: {
cmdStatus = SocksCmdStatus.fromByte(byteBuf.readByte());
cmdStatus = SocksCmdStatus.valueOf(byteBuf.readByte());
reserved = byteBuf.readByte();
addressType = SocksAddressType.fromByte(byteBuf.readByte());
addressType = SocksAddressType.valueOf(byteBuf.readByte());
checkpoint(State.READ_CMD_ADDRESS);
}
case READ_CMD_ADDRESS: {

View File

@ -34,7 +34,15 @@ public enum SocksCmdStatus {
this.b = b;
}
/**
* @deprecated Use {@link #valueOf(byte)} instead.
*/
@Deprecated
public static SocksCmdStatus fromByte(byte b) {
return valueOf(b);
}
public static SocksCmdStatus valueOf(byte b) {
for (SocksCmdStatus code : values()) {
if (code.b == b) {
return code;

View File

@ -28,7 +28,15 @@ public enum SocksCmdType {
this.b = b;
}
/**
* @deprecated Use {@link #valueOf(byte)} instead.
*/
@Deprecated
public static SocksCmdType fromByte(byte b) {
return valueOf(b);
}
public static SocksCmdType valueOf(byte b) {
for (SocksCmdType code : values()) {
if (code.b == b) {
return code;

View File

@ -41,7 +41,7 @@ public class SocksInitRequestDecoder extends ReplayingDecoder<SocksInitRequestDe
protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> out) throws Exception {
switch (state()) {
case CHECK_PROTOCOL_VERSION: {
version = SocksProtocolVersion.fromByte(byteBuf.readByte());
version = SocksProtocolVersion.valueOf(byteBuf.readByte());
if (version != SocksProtocolVersion.SOCKS5) {
break;
}
@ -51,7 +51,7 @@ public class SocksInitRequestDecoder extends ReplayingDecoder<SocksInitRequestDe
authSchemes.clear();
authSchemeNum = byteBuf.readByte();
for (int i = 0; i < authSchemeNum; i++) {
authSchemes.add(SocksAuthScheme.fromByte(byteBuf.readByte()));
authSchemes.add(SocksAuthScheme.valueOf(byteBuf.readByte()));
}
msg = new SocksInitRequest(authSchemes);
break;

View File

@ -40,14 +40,14 @@ public class SocksInitResponseDecoder extends ReplayingDecoder<SocksInitResponse
protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> out) throws Exception {
switch (state()) {
case CHECK_PROTOCOL_VERSION: {
version = SocksProtocolVersion.fromByte(byteBuf.readByte());
version = SocksProtocolVersion.valueOf(byteBuf.readByte());
if (version != SocksProtocolVersion.SOCKS5) {
break;
}
checkpoint(State.READ_PREFFERED_AUTH_TYPE);
}
case READ_PREFFERED_AUTH_TYPE: {
authScheme = SocksAuthScheme.fromByte(byteBuf.readByte());
authScheme = SocksAuthScheme.valueOf(byteBuf.readByte());
msg = new SocksInitResponse(authScheme);
break;
}

View File

@ -27,7 +27,15 @@ public enum SocksProtocolVersion {
this.b = b;
}
/**
* @deprecated Use {@link #valueOf(byte)} instead.
*/
@Deprecated
public static SocksProtocolVersion fromByte(byte b) {
return valueOf(b);
}
public static SocksProtocolVersion valueOf(byte b) {
for (SocksProtocolVersion code : values()) {
if (code.b == b) {
return code;

View File

@ -26,7 +26,15 @@ public enum SocksSubnegotiationVersion {
this.b = b;
}
/**
* @deprecated Use {@link #valueOf(byte)} instead.
*/
@Deprecated
public static SocksSubnegotiationVersion fromByte(byte b) {
return valueOf(b);
}
public static SocksSubnegotiationVersion valueOf(byte b) {
for (SocksSubnegotiationVersion code : values()) {
if (code.b == b) {
return code;