Add 'is' prefix to boolean getters if their meaning is ambiguous

- plus minor code cleanup
- ID -> Id or id
This commit is contained in:
Trustin Lee 2012-06-12 17:58:22 +09:00
parent 61e357049e
commit fdb66b6294
4 changed files with 59 additions and 60 deletions

View File

@ -36,7 +36,7 @@ public class DefaultSpdySettingsFrame implements SpdySettingsFrame {
} }
@Override @Override
public Set<Integer> getIDs() { public Set<Integer> getIds() {
return settingsMap.keySet(); return settingsMap.keySet();
} }
@ -86,7 +86,7 @@ public class DefaultSpdySettingsFrame implements SpdySettingsFrame {
} }
@Override @Override
public boolean persistValue(int ID) { public boolean isPersistValue(int ID) {
Integer key = new Integer(ID); Integer key = new Integer(ID);
if (settingsMap.containsKey(key)) { if (settingsMap.containsKey(key)) {
return settingsMap.get(key).getPersist(); return settingsMap.get(key).getPersist();
@ -167,33 +167,33 @@ public class DefaultSpdySettingsFrame implements SpdySettingsFrame {
private boolean persist; private boolean persist;
private boolean persisted; private boolean persisted;
public Setting(int value, boolean persist, boolean persisted) { Setting(int value, boolean persist, boolean persisted) {
this.value = value; this.value = value;
this.persist = persist; this.persist = persist;
this.persisted = persisted; this.persisted = persisted;
} }
public int getValue() { int getValue() {
return value; return value;
} }
public void setValue(int value) { void setValue(int value) {
this.value = value; this.value = value;
} }
public boolean getPersist() { boolean getPersist() {
return persist; return persist;
} }
public void setPersist(boolean persist) { void setPersist(boolean persist) {
this.persist = persist; this.persist = persist;
} }
public boolean getPersisted() { boolean getPersisted() {
return persisted; return persisted;
} }
public void setPersisted(boolean persisted) { void setPersisted(boolean persisted) {
this.persisted = persisted; this.persisted = persisted;
} }
} }

View File

@ -182,7 +182,7 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
SpdySettingsFrame spdySettingsFrame = (SpdySettingsFrame) msg; SpdySettingsFrame spdySettingsFrame = (SpdySettingsFrame) msg;
byte flags = spdySettingsFrame.clearPreviouslyPersistedSettings() ? byte flags = spdySettingsFrame.clearPreviouslyPersistedSettings() ?
SPDY_SETTINGS_CLEAR : 0; SPDY_SETTINGS_CLEAR : 0;
Set<Integer> IDs = spdySettingsFrame.getIDs(); Set<Integer> IDs = spdySettingsFrame.getIds();
int numEntries = IDs.size(); int numEntries = IDs.size();
int length = 4 + numEntries * 8; int length = 4 + numEntries * 8;
out.ensureWritableBytes(SPDY_HEADER_SIZE + length); out.ensureWritableBytes(SPDY_HEADER_SIZE + length);
@ -194,7 +194,7 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
for (Integer ID: IDs) { for (Integer ID: IDs) {
int id = ID.intValue(); int id = ID.intValue();
byte ID_flags = (byte) 0; byte ID_flags = (byte) 0;
if (spdySettingsFrame.persistValue(id)) { if (spdySettingsFrame.isPersistValue(id)) {
ID_flags |= SPDY_SETTINGS_PERSIST_VALUE; ID_flags |= SPDY_SETTINGS_PERSIST_VALUE;
} }
if (spdySettingsFrame.isPersisted(id)) { if (spdySettingsFrame.isPersisted(id)) {

View File

@ -33,26 +33,26 @@ final class SpdySession {
SpdySession() { SpdySession() {
} }
public int numActiveStreams() { int numActiveStreams() {
return activeStreams.size(); return activeStreams.size();
} }
public boolean noActiveStreams() { boolean noActiveStreams() {
return activeStreams.isEmpty(); return activeStreams.isEmpty();
} }
public boolean isActiveStream(int streamID) { boolean isActiveStream(int streamID) {
return activeStreams.containsKey(new Integer(streamID)); return activeStreams.containsKey(new Integer(streamID));
} }
// Stream-IDs should be iterated in priority order // Stream-IDs should be iterated in priority order
public Set<Integer> getActiveStreams() { Set<Integer> getActiveStreams() {
TreeSet<Integer> StreamIDs = new TreeSet<Integer>(new PriorityComparator()); TreeSet<Integer> StreamIDs = new TreeSet<Integer>(new PriorityComparator());
StreamIDs.addAll(activeStreams.keySet()); StreamIDs.addAll(activeStreams.keySet());
return StreamIDs; return StreamIDs;
} }
public void acceptStream( void acceptStream(
int streamID, byte priority, boolean remoteSideClosed, boolean localSideClosed, int streamID, byte priority, boolean remoteSideClosed, boolean localSideClosed,
int sendWindowSize, int receiveWindowSize) { int sendWindowSize, int receiveWindowSize) {
if (!remoteSideClosed || !localSideClosed) { if (!remoteSideClosed || !localSideClosed) {
@ -62,7 +62,7 @@ final class SpdySession {
} }
} }
public boolean removeStream(int streamID) { boolean removeStream(int streamID) {
Integer StreamID = new Integer(streamID); Integer StreamID = new Integer(streamID);
StreamState state = activeStreams.get(StreamID); StreamState state = activeStreams.get(StreamID);
activeStreams.remove(StreamID); activeStreams.remove(StreamID);
@ -73,12 +73,12 @@ final class SpdySession {
} }
} }
public boolean isRemoteSideClosed(int streamID) { boolean isRemoteSideClosed(int streamID) {
StreamState state = activeStreams.get(new Integer(streamID)); StreamState state = activeStreams.get(new Integer(streamID));
return state == null || state.isRemoteSideClosed(); return state == null || state.isRemoteSideClosed();
} }
public void closeRemoteSide(int streamID) { void closeRemoteSide(int streamID) {
Integer StreamID = new Integer(streamID); Integer StreamID = new Integer(streamID);
StreamState state = activeStreams.get(StreamID); StreamState state = activeStreams.get(StreamID);
if (state != null) { if (state != null) {
@ -89,12 +89,12 @@ final class SpdySession {
} }
} }
public boolean isLocalSideClosed(int streamID) { boolean isLocalSideClosed(int streamID) {
StreamState state = activeStreams.get(new Integer(streamID)); StreamState state = activeStreams.get(new Integer(streamID));
return state == null || state.isLocalSideClosed(); return state == null || state.isLocalSideClosed();
} }
public void closeLocalSide(int streamID) { void closeLocalSide(int streamID) {
Integer StreamID = new Integer(streamID); Integer StreamID = new Integer(streamID);
StreamState state = activeStreams.get(StreamID); StreamState state = activeStreams.get(StreamID);
if (state != null) { if (state != null) {
@ -109,30 +109,29 @@ final class SpdySession {
* hasReceivedReply and receivedReply are only called from messageReceived * hasReceivedReply and receivedReply are only called from messageReceived
* no need to synchronize access to the StreamState * no need to synchronize access to the StreamState
*/ */
boolean hasReceivedReply(int streamID) {
public boolean hasReceivedReply(int streamID) {
StreamState state = activeStreams.get(new Integer(streamID)); StreamState state = activeStreams.get(new Integer(streamID));
return state != null && state.hasReceivedReply(); return state != null && state.hasReceivedReply();
} }
public void receivedReply(int streamID) { void receivedReply(int streamID) {
StreamState state = activeStreams.get(new Integer(streamID)); StreamState state = activeStreams.get(new Integer(streamID));
if (state != null) { if (state != null) {
state.receivedReply(); state.receivedReply();
} }
} }
public int getSendWindowSize(int streamID) { int getSendWindowSize(int streamID) {
StreamState state = activeStreams.get(new Integer(streamID)); StreamState state = activeStreams.get(new Integer(streamID));
return state != null ? state.getSendWindowSize() : -1; return state != null ? state.getSendWindowSize() : -1;
} }
public int updateSendWindowSize(int streamID, int deltaWindowSize) { int updateSendWindowSize(int streamID, int deltaWindowSize) {
StreamState state = activeStreams.get(new Integer(streamID)); StreamState state = activeStreams.get(new Integer(streamID));
return state != null ? state.updateSendWindowSize(deltaWindowSize) : -1; return state != null ? state.updateSendWindowSize(deltaWindowSize) : -1;
} }
public int updateReceiveWindowSize(int streamID, int deltaWindowSize) { int updateReceiveWindowSize(int streamID, int deltaWindowSize) {
StreamState state = activeStreams.get(new Integer(streamID)); StreamState state = activeStreams.get(new Integer(streamID));
if (deltaWindowSize > 0) { if (deltaWindowSize > 0) {
state.setReceiveWindowSizeLowerBound(0); state.setReceiveWindowSizeLowerBound(0);
@ -140,12 +139,12 @@ final class SpdySession {
return state != null ? state.updateReceiveWindowSize(deltaWindowSize) : -1; return state != null ? state.updateReceiveWindowSize(deltaWindowSize) : -1;
} }
public int getReceiveWindowSizeLowerBound(int streamID) { int getReceiveWindowSizeLowerBound(int streamID) {
StreamState state = activeStreams.get(new Integer(streamID)); StreamState state = activeStreams.get(new Integer(streamID));
return state != null ? state.getReceiveWindowSizeLowerBound() : 0; return state != null ? state.getReceiveWindowSizeLowerBound() : 0;
} }
public void updateAllReceiveWindowSizes(int deltaWindowSize) { void updateAllReceiveWindowSizes(int deltaWindowSize) {
for (StreamState state: activeStreams.values()) { for (StreamState state: activeStreams.values()) {
state.updateReceiveWindowSize(deltaWindowSize); state.updateReceiveWindowSize(deltaWindowSize);
if (deltaWindowSize < 0) { if (deltaWindowSize < 0) {
@ -154,17 +153,17 @@ final class SpdySession {
} }
} }
public boolean putPendingWrite(int streamID, Object msg) { boolean putPendingWrite(int streamID, Object msg) {
StreamState state = activeStreams.get(Integer.valueOf(streamID)); StreamState state = activeStreams.get(Integer.valueOf(streamID));
return state != null && state.putPendingWrite(msg); return state != null && state.putPendingWrite(msg);
} }
public Object getPendingWrite(int streamID) { Object getPendingWrite(int streamID) {
StreamState state = activeStreams.get(Integer.valueOf(streamID)); StreamState state = activeStreams.get(Integer.valueOf(streamID));
return state != null ? state.getPendingWrite() : null; return state != null ? state.getPendingWrite() : null;
} }
public Object removePendingWrite(int streamID) { Object removePendingWrite(int streamID) {
StreamState state = activeStreams.get(Integer.valueOf(streamID)); StreamState state = activeStreams.get(Integer.valueOf(streamID));
return state != null ? state.removePendingWrite() : null; return state != null ? state.removePendingWrite() : null;
} }
@ -180,7 +179,7 @@ final class SpdySession {
private volatile int receiveWindowSizeLowerBound; private volatile int receiveWindowSizeLowerBound;
private final BlockingQueue<Object> pendingWriteQueue = QueueFactory.createQueue(); private final BlockingQueue<Object> pendingWriteQueue = QueueFactory.createQueue();
public StreamState( StreamState(
byte priority, boolean remoteSideClosed, boolean localSideClosed, byte priority, boolean remoteSideClosed, boolean localSideClosed,
int sendWindowSize, int receiveWindowSize) { int sendWindowSize, int receiveWindowSize) {
this.priority = priority; this.priority = priority;
@ -190,67 +189,67 @@ final class SpdySession {
this.receiveWindowSize = new AtomicInteger(receiveWindowSize); this.receiveWindowSize = new AtomicInteger(receiveWindowSize);
} }
public byte getPriority() { byte getPriority() {
return priority; return priority;
} }
public boolean isRemoteSideClosed() { boolean isRemoteSideClosed() {
return remoteSideClosed; return remoteSideClosed;
} }
public void closeRemoteSide() { void closeRemoteSide() {
remoteSideClosed = true; remoteSideClosed = true;
} }
public boolean isLocalSideClosed() { boolean isLocalSideClosed() {
return localSideClosed; return localSideClosed;
} }
public void closeLocalSide() { void closeLocalSide() {
localSideClosed = true; localSideClosed = true;
} }
public boolean hasReceivedReply() { boolean hasReceivedReply() {
return receivedReply; return receivedReply;
} }
public void receivedReply() { void receivedReply() {
receivedReply = true; receivedReply = true;
} }
public int getSendWindowSize() { int getSendWindowSize() {
return sendWindowSize.get(); return sendWindowSize.get();
} }
public int updateSendWindowSize(int deltaWindowSize) { int updateSendWindowSize(int deltaWindowSize) {
return sendWindowSize.addAndGet(deltaWindowSize); return sendWindowSize.addAndGet(deltaWindowSize);
} }
public int updateReceiveWindowSize(int deltaWindowSize) { int updateReceiveWindowSize(int deltaWindowSize) {
return receiveWindowSize.addAndGet(deltaWindowSize); return receiveWindowSize.addAndGet(deltaWindowSize);
} }
public int getReceiveWindowSizeLowerBound() { int getReceiveWindowSizeLowerBound() {
return receiveWindowSizeLowerBound; return receiveWindowSizeLowerBound;
} }
public void setReceiveWindowSizeLowerBound(int receiveWindowSizeLowerBound) { void setReceiveWindowSizeLowerBound(int receiveWindowSizeLowerBound) {
this.receiveWindowSizeLowerBound = receiveWindowSizeLowerBound; this.receiveWindowSizeLowerBound = receiveWindowSizeLowerBound;
} }
public boolean putPendingWrite(Object msg) { boolean putPendingWrite(Object msg) {
return pendingWriteQueue.offer(msg); return pendingWriteQueue.offer(msg);
} }
public Object getPendingWrite() { Object getPendingWrite() {
return pendingWriteQueue.peek(); return pendingWriteQueue.peek();
} }
public Object removePendingWrite() { Object removePendingWrite() {
return pendingWriteQueue.poll(); return pendingWriteQueue.poll();
} }
public boolean clearPendingWrites() { boolean clearPendingWrites() {
if (pendingWriteQueue.isEmpty()) { if (pendingWriteQueue.isEmpty()) {
return false; return false;
} }

View File

@ -35,24 +35,24 @@ public interface SpdySettingsFrame {
* Returns a {@code Set} of the setting IDs. * Returns a {@code Set} of the setting IDs.
* The set's iterator will return the IDs in ascending order. * The set's iterator will return the IDs in ascending order.
*/ */
Set<Integer> getIDs(); Set<Integer> getIds();
/** /**
* Returns {@code true} if the setting ID has a value. * Returns {@code true} if the setting ID has a value.
*/ */
boolean isSet(int ID); boolean isSet(int id);
/** /**
* Returns the value of the setting ID. * Returns the value of the setting ID.
* Returns -1 if the setting ID is not set. * Returns -1 if the setting ID is not set.
*/ */
int getValue(int ID); int getValue(int id);
/** /**
* Sets the value of the setting ID. * Sets the value of the setting ID.
* The ID must be positive and cannot exceed 16777215. * The ID must be positive and cannot exceed 16777215.
*/ */
void setValue(int ID, int value); void setValue(int id, int value);
/** /**
* Sets the value of the setting ID. * Sets the value of the setting ID.
@ -60,39 +60,39 @@ public interface SpdySettingsFrame {
* Sets if the setting is persisted (should only be set by the client). * Sets if the setting is persisted (should only be set by the client).
* The ID must be positive and cannot exceed 16777215. * The ID must be positive and cannot exceed 16777215.
*/ */
void setValue(int ID, int value, boolean persistVal, boolean persisted); void setValue(int id, int value, boolean persistVal, boolean persisted);
/** /**
* Removes the value of the setting ID. * Removes the value of the setting ID.
* Removes all persistance information for the setting. * Removes all persistence information for the setting.
*/ */
void removeValue(int ID); void removeValue(int id);
/** /**
* Returns {@code true} if this setting should be persisted. * Returns {@code true} if this setting should be persisted.
* Returns {@code false} if this setting should not be persisted * Returns {@code false} if this setting should not be persisted
* or if the setting ID has no value. * or if the setting ID has no value.
*/ */
boolean persistValue(int ID); boolean isPersistValue(int id);
/** /**
* Sets if this setting should be persisted. * Sets if this setting should be persisted.
* Has no effect if the setting ID has no value. * Has no effect if the setting ID has no value.
*/ */
void setPersistValue(int ID, boolean persistValue); void setPersistValue(int id, boolean persistValue);
/** /**
* Returns {@code true} if this setting is persisted. * Returns {@code true} if this setting is persisted.
* Returns {@code false} if this setting should not be persisted * Returns {@code false} if this setting should not be persisted
* or if the setting ID has no value. * or if the setting ID has no value.
*/ */
boolean isPersisted(int ID); boolean isPersisted(int id);
/** /**
* Sets if this setting is persisted. * Sets if this setting is persisted.
* Has no effect if the setting ID has no value. * Has no effect if the setting ID has no value.
*/ */
void setPersisted(int ID, boolean persisted); void setPersisted(int id, boolean persisted);
/** /**
* Returns {@code true} if previously persisted settings should be cleared. * Returns {@code true} if previously persisted settings should be cleared.