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 790c63e8d2
commit 71dce0193f
13 changed files with 68 additions and 12 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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