Headers set/add/contains timeMillis methods

Motivation:
The new Headers interface contains methods to getTimeMillis but no add/set/contains variants.  These should be added for consistency.

Modifications:
- Add three new methods: addTimeMillis, setTimeMillis, containsTimeMillis to the Headers interface.
- Add a new method to the Headers.ValueConverter interface: T convertTimeMillis(long)
- Bring these new interfaces up the class hierarchy

Result:
All Headers classes have setters/getters for timeMillis.
This commit is contained in:
Scott Mitchell 2014-11-02 21:05:47 -05:00 committed by Trustin Lee
parent 216cbd9e31
commit eb0e127ee9
13 changed files with 163 additions and 0 deletions

View File

@ -140,6 +140,12 @@ public class DefaultSpdyHeaders extends DefaultTextHeaders implements SpdyHeader
return this;
}
@Override
public SpdyHeaders addTimeMillis(CharSequence name, long value) {
super.addTimeMillis(name, value);
return this;
}
@Override
public SpdyHeaders add(TextHeaders headers) {
super.add(headers);
@ -230,6 +236,12 @@ public class DefaultSpdyHeaders extends DefaultTextHeaders implements SpdyHeader
return this;
}
@Override
public SpdyHeaders setTimeMillis(CharSequence name, long value) {
super.setTimeMillis(name, value);
return this;
}
@Override
public SpdyHeaders set(TextHeaders headers) {
super.set(headers);

View File

@ -98,6 +98,9 @@ public interface SpdyHeaders extends TextHeaders {
@Override
SpdyHeaders addDouble(CharSequence name, double value);
@Override
SpdyHeaders addTimeMillis(CharSequence name, long value);
@Override
SpdyHeaders add(TextHeaders headers);
@ -134,6 +137,9 @@ public interface SpdyHeaders extends TextHeaders {
@Override
SpdyHeaders setDouble(CharSequence name, double value);
@Override
SpdyHeaders setTimeMillis(CharSequence name, long value);
@Override
SpdyHeaders setObject(CharSequence name, Object value);

View File

@ -105,6 +105,12 @@ public class DefaultStompHeaders extends DefaultTextHeaders implements StompHead
return this;
}
@Override
public StompHeaders addTimeMillis(CharSequence name, long value) {
super.addTimeMillis(name, value);
return this;
}
@Override
public StompHeaders add(TextHeaders headers) {
super.add(headers);
@ -195,6 +201,12 @@ public class DefaultStompHeaders extends DefaultTextHeaders implements StompHead
return this;
}
@Override
public StompHeaders setTimeMillis(CharSequence name, long value) {
super.setTimeMillis(name, value);
return this;
}
@Override
public StompHeaders set(TextHeaders headers) {
super.set(headers);

View File

@ -86,6 +86,9 @@ public interface StompHeaders extends TextHeaders {
@Override
StompHeaders addDouble(CharSequence name, double value);
@Override
StompHeaders addTimeMillis(CharSequence name, long value);
@Override
StompHeaders add(TextHeaders headers);
@ -131,6 +134,9 @@ public interface StompHeaders extends TextHeaders {
@Override
StompHeaders setDouble(CharSequence name, double value);
@Override
StompHeaders setTimeMillis(CharSequence name, long value);
@Override
StompHeaders set(TextHeaders headers);

View File

@ -76,6 +76,9 @@ public interface BinaryHeaders extends Headers<AsciiString> {
@Override
BinaryHeaders addDouble(AsciiString name, double value);
@Override
BinaryHeaders addTimeMillis(AsciiString name, long value);
/**
* See {@link Headers#add(Headers)}
*/
@ -123,6 +126,9 @@ public interface BinaryHeaders extends Headers<AsciiString> {
@Override
BinaryHeaders setDouble(AsciiString name, double value);
@Override
BinaryHeaders setTimeMillis(AsciiString name, long value);
/**
* See {@link Headers#set(Headers)}
*/

View File

@ -81,6 +81,11 @@ public class DefaultBinaryHeaders extends DefaultHeaders<AsciiString> implements
return value.parseLong();
}
@Override
public AsciiString convertTimeMillis(long value) {
return new AsciiString(String.valueOf(value));
}
@Override
public long convertToTimeMillis(AsciiString value) {
try {
@ -239,6 +244,12 @@ public class DefaultBinaryHeaders extends DefaultHeaders<AsciiString> implements
return this;
}
@Override
public BinaryHeaders addTimeMillis(AsciiString name, long value) {
super.addTimeMillis(name, value);
return this;
}
@Override
public BinaryHeaders add(BinaryHeaders headers) {
super.add(headers);
@ -329,6 +340,12 @@ public class DefaultBinaryHeaders extends DefaultHeaders<AsciiString> implements
return this;
}
@Override
public BinaryHeaders setTimeMillis(AsciiString name, long value) {
super.setTimeMillis(name, value);
return this;
}
@Override
public BinaryHeaders set(BinaryHeaders headers) {
super.set(headers);

View File

@ -378,6 +378,11 @@ public class DefaultHeaders<T> implements Headers<T> {
return contains(name, valueConverter.convertDouble(checkNotNull(value, "value")));
}
@Override
public boolean containsTimeMillis(T name, long value) {
return contains(name, valueConverter.convertTimeMillis(checkNotNull(value, "value")));
}
@Override
public boolean contains(T name, T value, Comparator<? super T> comparator) {
return contains(name, value, comparator, comparator);
@ -550,6 +555,11 @@ public class DefaultHeaders<T> implements Headers<T> {
return add(name, valueConverter.convertDouble(value));
}
@Override
public Headers<T> addTimeMillis(T name, long value) {
return add(name, valueConverter.convertTimeMillis(value));
}
@Override
public Headers<T> addChar(T name, char value) {
return add(name, valueConverter.convertChar(value));
@ -690,6 +700,11 @@ public class DefaultHeaders<T> implements Headers<T> {
return set(name, valueConverter.convertDouble(value));
}
@Override
public Headers<T> setTimeMillis(T name, long value) {
return set(name, valueConverter.convertTimeMillis(value));
}
@Override
public Headers<T> setFloat(T name, float value) {
return set(name, valueConverter.convertFloat(value));

View File

@ -119,6 +119,11 @@ public class DefaultTextHeaders extends DefaultConvertibleHeaders<CharSequence,
return Long.parseLong(value.toString());
}
@Override
public AsciiString convertTimeMillis(long value) {
return new AsciiString(String.valueOf(value));
}
@Override
public long convertToTimeMillis(CharSequence value) {
try {
@ -268,6 +273,12 @@ public class DefaultTextHeaders extends DefaultConvertibleHeaders<CharSequence,
return this;
}
@Override
public TextHeaders addTimeMillis(CharSequence name, long value) {
super.addTimeMillis(name, value);
return this;
}
@Override
public TextHeaders add(TextHeaders headers) {
super.add(headers);
@ -358,6 +369,12 @@ public class DefaultTextHeaders extends DefaultConvertibleHeaders<CharSequence,
return this;
}
@Override
public TextHeaders setTimeMillis(CharSequence name, long value) {
super.setTimeMillis(name, value);
return this;
}
@Override
public TextHeaders set(TextHeaders headers) {
super.set(headers);

View File

@ -104,6 +104,12 @@ public class EmptyBinaryHeaders extends EmptyHeaders<AsciiString> implements Bin
return this;
}
@Override
public BinaryHeaders addTimeMillis(AsciiString name, long value) {
super.addTimeMillis(name, value);
return this;
}
@Override
public BinaryHeaders add(BinaryHeaders headers) {
super.add(headers);
@ -194,6 +200,12 @@ public class EmptyBinaryHeaders extends EmptyHeaders<AsciiString> implements Bin
return this;
}
@Override
public BinaryHeaders setTimeMillis(AsciiString name, long value) {
super.setTimeMillis(name, value);
return this;
}
@Override
public BinaryHeaders set(BinaryHeaders headers) {
super.set(headers);

View File

@ -292,6 +292,11 @@ public class EmptyHeaders<T> implements Headers<T> {
return false;
}
@Override
public boolean containsTimeMillis(T name, long value) {
return false;
}
@Override
public boolean contains(T name, T value, Comparator<? super T> comparator) {
return false;
@ -404,6 +409,11 @@ public class EmptyHeaders<T> implements Headers<T> {
throw new UnsupportedOperationException("read only");
}
@Override
public Headers<T> addTimeMillis(T name, long value) {
throw new UnsupportedOperationException("read only");
}
@Override
public Headers<T> add(Headers<T> headers) {
throw new UnsupportedOperationException("read only");
@ -479,6 +489,11 @@ public class EmptyHeaders<T> implements Headers<T> {
throw new UnsupportedOperationException("read only");
}
@Override
public Headers<T> setTimeMillis(T name, long value) {
throw new UnsupportedOperationException("read only");
}
@Override
public Headers<T> set(Headers<T> headers) {
throw new UnsupportedOperationException("read only");

View File

@ -114,6 +114,12 @@ public class EmptyTextHeaders extends EmptyConvertibleHeaders<CharSequence, Stri
return this;
}
@Override
public TextHeaders addTimeMillis(CharSequence name, long value) {
super.addTimeMillis(name, value);
return this;
}
@Override
public TextHeaders add(TextHeaders headers) {
super.add(headers);
@ -204,6 +210,12 @@ public class EmptyTextHeaders extends EmptyConvertibleHeaders<CharSequence, Stri
return this;
}
@Override
public TextHeaders setTimeMillis(CharSequence name, long value) {
super.setTimeMillis(name, value);
return this;
}
@Override
public TextHeaders set(TextHeaders headers) {
super.set(headers);

View File

@ -78,6 +78,8 @@ public interface Headers<T> extends Iterable<Map.Entry<T, T>> {
long convertToLong(T value);
T convertTimeMillis(long value);
long convertToTimeMillis(T value);
T convertFloat(float value);
@ -626,6 +628,15 @@ public interface Headers<T> extends Iterable<Map.Entry<T, T>> {
*/
boolean containsDouble(T name, double value);
/**
* Returns {@code true} if a header with the name and value exists.
*
* @param name the header name
* @param value the header value
* @return {@code true} if it contains it {@code false} otherwise
*/
boolean containsTimeMillis(T name, long value);
/**
* Returns {@code true} if a header with the name and value exists.
*
@ -857,6 +868,14 @@ public interface Headers<T> extends Iterable<Map.Entry<T, T>> {
*/
Headers<T> addDouble(T name, double value);
/**
* Add the {@code name} to {@code value}.
* @param name The name to modify
* @param value The value
* @return {@code this}
*/
Headers<T> addTimeMillis(T name, long value);
/**
* Adds all header entries of the specified {@code headers}.
*
@ -1034,6 +1053,14 @@ public interface Headers<T> extends Iterable<Map.Entry<T, T>> {
*/
Headers<T> setDouble(T name, double value);
/**
* Set the {@code name} to {@code value}. This will remove all previous values associated with {@code name}.
* @param name The name to modify
* @param value The value
* @return {@code this}
*/
Headers<T> setTimeMillis(T name, long value);
/**
* Cleans the current header entries and copies all header entries of the specified {@code headers}.
*

View File

@ -95,6 +95,9 @@ public interface TextHeaders extends ConvertibleHeaders<CharSequence, String> {
@Override
TextHeaders addDouble(CharSequence name, double value);
@Override
TextHeaders addTimeMillis(CharSequence name, long value);
/**
* See {@link Headers#add(Headers)}
*/
@ -142,6 +145,9 @@ public interface TextHeaders extends ConvertibleHeaders<CharSequence, String> {
@Override
TextHeaders setDouble(CharSequence name, double value);
@Override
TextHeaders setTimeMillis(CharSequence name, long value);
/**
* See {@link Headers#set(Headers)}
*/