Adhere to our getter/setter naming rules

Motivation:

Persuit for consistent method naming across all classes

Modifications:

Remove 'get' prefix for the getter methods in codec-memcache

Result:

More consistent method naming
This commit is contained in:
Trustin Lee 2014-06-24 16:08:46 +09:00
parent 3c21b1cc43
commit cde319dabd
21 changed files with 108 additions and 124 deletions

View File

@ -29,7 +29,7 @@ public abstract class AbstractMemcacheObject implements MemcacheObject {
}
@Override
public DecoderResult getDecoderResult() {
public DecoderResult decoderResult() {
return decoderResult;
}
@ -41,5 +41,4 @@ public abstract class AbstractMemcacheObject implements MemcacheObject {
decoderResult = result;
}
}

View File

@ -92,6 +92,6 @@ public class DefaultMemcacheContent extends AbstractMemcacheObject implements Me
@Override
public String toString() {
return StringUtil.simpleClassName(this) +
"(data: " + content() + ", getDecoderResult: " + getDecoderResult() + ')';
"(data: " + content() + ", decoderResult: " + decoderResult() + ')';
}
}

View File

@ -66,7 +66,7 @@ public interface LastMemcacheContent extends MemcacheContent {
}
@Override
public DecoderResult getDecoderResult() {
public DecoderResult decoderResult() {
return DecoderResult.SUCCESS;
}

View File

@ -15,23 +15,9 @@
*/
package io.netty.handler.codec.memcache;
import io.netty.handler.codec.DecoderResult;
import io.netty.handler.codec.DecoderResultProvider;
/**
* Defines a common interface for all {@link MemcacheObject} implementations.
*/
public interface MemcacheObject {
/**
* Returns the result of decoding this message.
*/
DecoderResult getDecoderResult();
/**
* Updates the result of decoding this message.
* <p/>
* <p>Do not call this method unless you know what you are doing.</p>
*/
void setDecoderResult(DecoderResult result);
}
public interface MemcacheObject extends DecoderResultProvider { }

View File

@ -24,7 +24,6 @@ import io.netty.handler.codec.memcache.DefaultLastMemcacheContent;
import io.netty.handler.codec.memcache.DefaultMemcacheContent;
import io.netty.handler.codec.memcache.LastMemcacheContent;
import io.netty.handler.codec.memcache.MemcacheContent;
import io.netty.handler.codec.memcache.MemcacheMessage;
import io.netty.util.CharsetUtil;
import java.util.List;
@ -84,7 +83,7 @@ public abstract class AbstractBinaryMemcacheDecoder<M extends BinaryMemcacheMess
return;
}
case READ_EXTRAS: try {
byte extrasLength = currentMessage.getExtrasLength();
byte extrasLength = currentMessage.extrasLength();
if (extrasLength > 0) {
if (in.readableBytes() < extrasLength) {
return;
@ -99,7 +98,7 @@ public abstract class AbstractBinaryMemcacheDecoder<M extends BinaryMemcacheMess
return;
}
case READ_KEY: try {
short keyLength = currentMessage.getKeyLength();
short keyLength = currentMessage.keyLength();
if (keyLength > 0) {
if (in.readableBytes() < keyLength) {
return;
@ -116,9 +115,9 @@ public abstract class AbstractBinaryMemcacheDecoder<M extends BinaryMemcacheMess
return;
}
case READ_CONTENT: try {
int valueLength = currentMessage.getTotalBodyLength()
- currentMessage.getKeyLength()
- currentMessage.getExtrasLength();
int valueLength = currentMessage.totalBodyLength()
- currentMessage.keyLength()
- currentMessage.extrasLength();
int toRead = in.readableBytes();
if (valueLength > 0) {
if (toRead == 0) {
@ -201,8 +200,8 @@ public abstract class AbstractBinaryMemcacheDecoder<M extends BinaryMemcacheMess
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
super.channelInactive(ctx);
if (currentMessage != null && currentMessage.getExtras() != null) {
currentMessage.getExtras().release();
if (currentMessage != null && currentMessage.extras() != null) {
currentMessage.extras().release();
}
resetDecoder();

View File

@ -37,8 +37,8 @@ public abstract class AbstractBinaryMemcacheEncoder<M extends BinaryMemcacheMess
ByteBuf buf = ctx.alloc().buffer(DEFAULT_BUFFER_SIZE);
encodeHeader(buf, msg);
encodeExtras(buf, msg.getExtras());
encodeKey(buf, msg.getKey());
encodeExtras(buf, msg.extras());
encodeKey(buf, msg.key());
return buf;
}

View File

@ -56,12 +56,12 @@ public abstract class AbstractBinaryMemcacheMessage
}
@Override
public String getKey() {
public String key() {
return key;
}
@Override
public ByteBuf getExtras() {
public ByteBuf extras() {
return extras;
}
@ -78,7 +78,7 @@ public abstract class AbstractBinaryMemcacheMessage
}
@Override
public byte getMagic() {
public byte magic() {
return magic;
}
@ -89,18 +89,18 @@ public abstract class AbstractBinaryMemcacheMessage
}
@Override
public long getCAS() {
public long cas() {
return cas;
}
@Override
public BinaryMemcacheMessage setCAS(long cas) {
public BinaryMemcacheMessage setCas(long cas) {
this.cas = cas;
return this;
}
@Override
public int getOpaque() {
public int opaque() {
return opaque;
}
@ -111,7 +111,7 @@ public abstract class AbstractBinaryMemcacheMessage
}
@Override
public int getTotalBodyLength() {
public int totalBodyLength() {
return totalBodyLength;
}
@ -122,7 +122,7 @@ public abstract class AbstractBinaryMemcacheMessage
}
@Override
public byte getDataType() {
public byte dataType() {
return dataType;
}
@ -133,7 +133,7 @@ public abstract class AbstractBinaryMemcacheMessage
}
@Override
public byte getExtrasLength() {
public byte extrasLength() {
return extrasLength;
}
@ -144,7 +144,7 @@ public abstract class AbstractBinaryMemcacheMessage
}
@Override
public short getKeyLength() {
public short keyLength() {
return keyLength;
}
@ -155,7 +155,7 @@ public abstract class AbstractBinaryMemcacheMessage
}
@Override
public byte getOpcode() {
public byte opcode() {
return opcode;
}

View File

@ -35,7 +35,7 @@ public interface BinaryMemcacheMessage extends MemcacheMessage {
*
* @return the magic byte.
*/
byte getMagic();
byte magic();
/**
* Sets the magic byte.
@ -50,7 +50,7 @@ public interface BinaryMemcacheMessage extends MemcacheMessage {
*
* @return the opcode.
*/
byte getOpcode();
byte opcode();
/**
* Sets the opcode for the message.
@ -66,7 +66,7 @@ public interface BinaryMemcacheMessage extends MemcacheMessage {
*
* @return the key length.
*/
short getKeyLength();
short keyLength();
/**
* Set the key length of the message.
@ -84,7 +84,7 @@ public interface BinaryMemcacheMessage extends MemcacheMessage {
*
* @return the extras length.
*/
byte getExtrasLength();
byte extrasLength();
/**
* Set the extras length of the message.
@ -100,7 +100,7 @@ public interface BinaryMemcacheMessage extends MemcacheMessage {
*
* @return the data type of the message.
*/
byte getDataType();
byte dataType();
/**
* Sets the data type of the message.
@ -116,7 +116,7 @@ public interface BinaryMemcacheMessage extends MemcacheMessage {
*
* @return the total body length.
*/
int getTotalBodyLength();
int totalBodyLength();
/**
* Sets the total body length.
@ -132,7 +132,7 @@ public interface BinaryMemcacheMessage extends MemcacheMessage {
*
* @return the opaque value.
*/
int getOpaque();
int opaque();
/**
* Sets the opaque value.
@ -146,21 +146,21 @@ public interface BinaryMemcacheMessage extends MemcacheMessage {
*
* @return the CAS identifier.
*/
long getCAS();
long cas();
/**
* Sets the CAS identifier.
*
* @param cas the CAS identifier to use.
*/
BinaryMemcacheMessage setCAS(long cas);
BinaryMemcacheMessage setCas(long cas);
/**
* Returns the optional key of the document.
*
* @return the key of the document.
*/
String getKey();
String key();
/**
* Sets the key of the document.
@ -174,7 +174,7 @@ public interface BinaryMemcacheMessage extends MemcacheMessage {
*
* @return the optional extras.
*/
ByteBuf getExtras();
ByteBuf extras();
/**
* Sets the extras buffer on the message.

View File

@ -54,34 +54,34 @@ public class BinaryMemcacheObjectAggregator extends AbstractMemcacheObjectAggreg
private static FullBinaryMemcacheRequest toFullRequest(BinaryMemcacheRequest request, ByteBuf content) {
FullBinaryMemcacheRequest fullRequest =
new DefaultFullBinaryMemcacheRequest(request.getKey(), request.getExtras(), content);
new DefaultFullBinaryMemcacheRequest(request.key(), request.extras(), content);
fullRequest.setMagic(request.getMagic());
fullRequest.setOpcode(request.getOpcode());
fullRequest.setKeyLength(request.getKeyLength());
fullRequest.setExtrasLength(request.getExtrasLength());
fullRequest.setDataType(request.getDataType());
fullRequest.setTotalBodyLength(request.getTotalBodyLength());
fullRequest.setOpaque(request.getOpaque());
fullRequest.setCAS(request.getCAS());
fullRequest.setReserved(request.getReserved());
fullRequest.setMagic(request.magic());
fullRequest.setOpcode(request.opcode());
fullRequest.setKeyLength(request.keyLength());
fullRequest.setExtrasLength(request.extrasLength());
fullRequest.setDataType(request.dataType());
fullRequest.setTotalBodyLength(request.totalBodyLength());
fullRequest.setOpaque(request.opaque());
fullRequest.setCas(request.cas());
fullRequest.setReserved(request.reserved());
return fullRequest;
}
private static FullBinaryMemcacheResponse toFullResponse(BinaryMemcacheResponse response, ByteBuf content) {
FullBinaryMemcacheResponse fullResponse =
new DefaultFullBinaryMemcacheResponse(response.getKey(), response.getExtras(), content);
new DefaultFullBinaryMemcacheResponse(response.key(), response.extras(), content);
fullResponse.setMagic(response.getMagic());
fullResponse.setOpcode(response.getOpcode());
fullResponse.setKeyLength(response.getKeyLength());
fullResponse.setExtrasLength(response.getExtrasLength());
fullResponse.setDataType(response.getDataType());
fullResponse.setTotalBodyLength(response.getTotalBodyLength());
fullResponse.setOpaque(response.getOpaque());
fullResponse.setCAS(response.getCAS());
fullResponse.setStatus(response.getStatus());
fullResponse.setMagic(response.magic());
fullResponse.setOpcode(response.opcode());
fullResponse.setKeyLength(response.keyLength());
fullResponse.setExtrasLength(response.extrasLength());
fullResponse.setDataType(response.dataType());
fullResponse.setTotalBodyLength(response.totalBodyLength());
fullResponse.setOpaque(response.opaque());
fullResponse.setCas(response.cas());
fullResponse.setStatus(response.status());
return fullResponse;
}

View File

@ -25,7 +25,7 @@ public interface BinaryMemcacheRequest extends BinaryMemcacheMessage {
*
* @return the reserved field value.
*/
short getReserved();
short reserved();
/**
* Sets the reserved field value.

View File

@ -43,7 +43,7 @@ public class BinaryMemcacheRequestDecoder
header.setReserved(in.readShort());
header.setTotalBodyLength(in.readInt());
header.setOpaque(in.readInt());
header.setCAS(in.readLong());
header.setCas(in.readLong());
return header;
}

View File

@ -25,15 +25,15 @@ public class BinaryMemcacheRequestEncoder
@Override
protected void encodeHeader(ByteBuf buf, BinaryMemcacheRequest msg) {
buf.writeByte(msg.getMagic());
buf.writeByte(msg.getOpcode());
buf.writeShort(msg.getKeyLength());
buf.writeByte(msg.getExtrasLength());
buf.writeByte(msg.getDataType());
buf.writeShort(msg.getReserved());
buf.writeInt(msg.getTotalBodyLength());
buf.writeInt(msg.getOpaque());
buf.writeLong(msg.getCAS());
buf.writeByte(msg.magic());
buf.writeByte(msg.opcode());
buf.writeShort(msg.keyLength());
buf.writeByte(msg.extrasLength());
buf.writeByte(msg.dataType());
buf.writeShort(msg.reserved());
buf.writeInt(msg.totalBodyLength());
buf.writeInt(msg.opaque());
buf.writeLong(msg.cas());
}
}

View File

@ -25,7 +25,7 @@ public interface BinaryMemcacheResponse extends BinaryMemcacheMessage {
*
* @return the status of the response.
*/
short getStatus();
short status();
/**
* Sets the status of the response.

View File

@ -43,7 +43,7 @@ public class BinaryMemcacheResponseDecoder
header.setStatus(in.readShort());
header.setTotalBodyLength(in.readInt());
header.setOpaque(in.readInt());
header.setCAS(in.readLong());
header.setCas(in.readLong());
return header;
}

View File

@ -25,15 +25,15 @@ public class BinaryMemcacheResponseEncoder
@Override
protected void encodeHeader(ByteBuf buf, BinaryMemcacheResponse msg) {
buf.writeByte(msg.getMagic());
buf.writeByte(msg.getOpcode());
buf.writeShort(msg.getKeyLength());
buf.writeByte(msg.getExtrasLength());
buf.writeByte(msg.getDataType());
buf.writeShort(msg.getStatus());
buf.writeInt(msg.getTotalBodyLength());
buf.writeInt(msg.getOpaque());
buf.writeLong(msg.getCAS());
buf.writeByte(msg.magic());
buf.writeByte(msg.opcode());
buf.writeShort(msg.keyLength());
buf.writeByte(msg.extrasLength());
buf.writeByte(msg.dataType());
buf.writeShort(msg.status());
buf.writeInt(msg.totalBodyLength());
buf.writeInt(msg.opaque());
buf.writeLong(msg.cas());
}
}

View File

@ -66,7 +66,7 @@ public class DefaultBinaryMemcacheRequest extends AbstractBinaryMemcacheMessage
}
@Override
public short getReserved() {
public short reserved() {
return reserved;
}

View File

@ -66,7 +66,7 @@ public class DefaultBinaryMemcacheResponse extends AbstractBinaryMemcacheMessage
}
@Override
public short getStatus() {
public short status() {
return status;
}

View File

@ -105,19 +105,19 @@ public class DefaultFullBinaryMemcacheRequest extends DefaultBinaryMemcacheReque
@Override
public FullBinaryMemcacheRequest copy() {
ByteBuf extras = getExtras();
ByteBuf extras = extras();
if (extras != null) {
extras = extras.copy();
}
return new DefaultFullBinaryMemcacheRequest(getKey(), extras, content().copy());
return new DefaultFullBinaryMemcacheRequest(key(), extras, content().copy());
}
@Override
public FullBinaryMemcacheRequest duplicate() {
ByteBuf extras = getExtras();
ByteBuf extras = extras();
if (extras != null) {
extras = extras.duplicate();
}
return new DefaultFullBinaryMemcacheRequest(getKey(), extras, content().duplicate());
return new DefaultFullBinaryMemcacheRequest(key(), extras, content().duplicate());
}
}

View File

@ -105,19 +105,19 @@ public class DefaultFullBinaryMemcacheResponse extends DefaultBinaryMemcacheResp
@Override
public FullBinaryMemcacheResponse copy() {
ByteBuf extras = getExtras();
ByteBuf extras = extras();
if (extras != null) {
extras = extras.copy();
}
return new DefaultFullBinaryMemcacheResponse(getKey(), extras, content().copy());
return new DefaultFullBinaryMemcacheResponse(key(), extras, content().copy());
}
@Override
public FullBinaryMemcacheResponse duplicate() {
ByteBuf extras = getExtras();
ByteBuf extras = extras();
if (extras != null) {
extras = extras.duplicate();
}
return new DefaultFullBinaryMemcacheResponse(getKey(), extras, content().duplicate());
return new DefaultFullBinaryMemcacheResponse(key(), extras, content().duplicate());
}
}

View File

@ -90,12 +90,12 @@ public class BinaryMemcacheDecoderTest {
BinaryMemcacheRequest request = channel.readInbound();
assertThat(request, notNullValue());
assertThat(request.getKey(), notNullValue());
assertThat(request.getExtras(), nullValue());
assertThat(request.key(), notNullValue());
assertThat(request.extras(), nullValue());
assertThat(request.getKeyLength(), is((short) 3));
assertThat(request.getExtrasLength(), is((byte) 0));
assertThat(request.getTotalBodyLength(), is(3));
assertThat(request.keyLength(), is((short) 3));
assertThat(request.extrasLength(), is((byte) 0));
assertThat(request.totalBodyLength(), is(3));
request.release();
assertThat(channel.readInbound(), instanceOf(LastMemcacheContent.class));
@ -116,12 +116,12 @@ public class BinaryMemcacheDecoderTest {
BinaryMemcacheRequest request = channel.readInbound();
assertThat(request, notNullValue());
assertThat(request.getKey(), notNullValue());
assertThat(request.getExtras(), nullValue());
assertThat(request.key(), notNullValue());
assertThat(request.extras(), nullValue());
assertThat(request.getKeyLength(), is((short) 3));
assertThat(request.getExtrasLength(), is((byte) 0));
assertThat(request.getTotalBodyLength(), is(11));
assertThat(request.keyLength(), is((short) 3));
assertThat(request.extrasLength(), is((byte) 0));
assertThat(request.totalBodyLength(), is(11));
request.release();
@ -153,8 +153,8 @@ public class BinaryMemcacheDecoderTest {
BinaryMemcacheRequest request = channel.readInbound();
assertThat(request, notNullValue());
assertThat(request.getKey(), notNullValue());
assertThat(request.getExtras(), nullValue());
assertThat(request.key(), notNullValue());
assertThat(request.extras(), nullValue());
request.release();
@ -208,8 +208,8 @@ public class BinaryMemcacheDecoderTest {
// First message
BinaryMemcacheResponse response = channel.readInbound();
assertThat(response.getStatus(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
assertThat(response.getTotalBodyLength(), is(msgBody.length()));
assertThat(response.status(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
assertThat(response.totalBodyLength(), is(msgBody.length()));
response.release();
// First message first content chunk
@ -220,8 +220,8 @@ public class BinaryMemcacheDecoderTest {
// Second message
response = channel.readInbound();
assertThat(response.getStatus(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
assertThat(response.getTotalBodyLength(), is(msgBody.length()));
assertThat(response.status(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
assertThat(response.totalBodyLength(), is(msgBody.length()));
response.release();
// Second message first content chunk
@ -238,8 +238,8 @@ public class BinaryMemcacheDecoderTest {
// Third message
response = channel.readInbound();
assertThat(response.getStatus(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
assertThat(response.getTotalBodyLength(), is(msgBody.length()));
assertThat(response.status(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
assertThat(response.totalBodyLength(), is(msgBody.length()));
response.release();
// Third message first content chunk

View File

@ -61,8 +61,8 @@ public class BinaryMemcacheObjectAggregatorTest {
assertThat(request, instanceOf(FullBinaryMemcacheRequest.class));
assertThat(request, notNullValue());
assertThat(request.getKey(), notNullValue());
assertThat(request.getExtras(), nullValue());
assertThat(request.key(), notNullValue());
assertThat(request.extras(), nullValue());
assertThat(request.content().readableBytes(), is(8));
assertThat(request.content().readByte(), is((byte) 0x01));