Package org.apache.juneau.http.header
Class BasicHeader
java.lang.Object
org.apache.juneau.http.header.BasicHeader
- All Implemented Interfaces:
Serializable,Cloneable,Header,NameValuePair
- Direct Known Subclasses:
BasicBooleanHeader,BasicCsvHeader,BasicDateHeader,BasicEntityTagHeader,BasicEntityTagsHeader,BasicIntegerHeader,BasicLongHeader,BasicStringHeader,BasicStringRangesHeader,BasicUriHeader,ResponseHeader,SerializedHeader
Superclass of all headers defined in this package.
Provides the following features:
- Default support for various streams and readers.
-
Content from
Suppliers. - Caching.
- Fluent setters.
- Fluent assertions.
See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionBasicHeader(String name, Object value) Constructor.BasicHeader(String name, Supplier<Object> value) Constructor with delayed value.protectedBasicHeader(BasicHeader copyFrom) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionProvides an object for performing assertions against the name of this header.Provides an object for performing assertions against the value of this header.asString()Returns the value of this header as a string.booleanbooleanequalsIgnoreCase(String compare) Returnstrue if the specified value is the same usingString.equalsIgnoreCase(String).get()If a value is present, returns the value, otherwise throwsNoSuchElementException.getName()getValue()inthashCode()booleanReturnstrue if the value exists and is not empty.booleanReturnstrue if the value exists.static BasicHeaderStatic creator.static BasicHeaderof(NameValuePair o) Static creator.If a value is present, returns the value, otherwise returns other.toString()
-
Constructor Details
-
BasicHeader
Constructor.- Parameters:
name- The parameter name.value- The parameter value.
Any non-String value will be converted to a String usingObject.toString().
Can also be anObject Supplier.- Throws:
IllegalArgumentException- If name isnull or empty.
-
BasicHeader
Constructor with delayed value.Header value is re-evaluated on each call to
getValue().- Parameters:
name- The header name.value- The supplier of the header value.
Can benull .- Throws:
IllegalArgumentException- If name isnull or empty.
-
BasicHeader
Copy constructor.- Parameters:
copyFrom- The object to copy.
-
-
Method Details
-
of
Static creator.- Parameters:
o- The name value pair that makes up the header name and value. The parameter value.
Any non-String value will be converted to a String usingObject.toString().- Returns:
- A new header bean.
-
of
Static creator.- Parameters:
name- The parameter name.value- The parameter value.
Can benull .- Returns:
- A new header bean, or
null if value isnull . - Throws:
IllegalArgumentException- If name isnull or empty.
-
assertName
Provides an object for performing assertions against the name of this header.- Returns:
- An object for performing assertions against the name of this header.
-
assertStringValue
Provides an object for performing assertions against the value of this header.- Returns:
- An object for performing assertions against the value of this header.
-
asString
Returns the value of this header as a string.- Returns:
- The value of this header as a string, or
Optional.empty()if the value isnull
-
equals
-
equalsIgnoreCase
Returnstrue if the specified value is the same usingString.equalsIgnoreCase(String).- Parameters:
compare- The value to compare against.- Returns:
true if the specified value is the same.
-
get
If a value is present, returns the value, otherwise throwsNoSuchElementException.This is a shortcut for calling
asString().get() .- Returns:
- The value if present.
-
getElements
- Specified by:
getElementsin interfaceHeader- Throws:
ParseException
-
getName
- Specified by:
getNamein interfaceNameValuePair
-
getValue
- Specified by:
getValuein interfaceNameValuePair
-
hashCode
-
isNotEmpty
Returnstrue if the value exists and is not empty.This is a shortcut for calling
!asString().orElse( ."" ).isEmpty()- Returns:
true if the value exists and is not empty.
-
isPresent
Returnstrue if the value exists.This is a shortcut for calling
asString().isPresent() .- Returns:
true if the value exists.
-
orElse
If a value is present, returns the value, otherwise returns other.This is a shortcut for calling
asString().orElse( .other )- Parameters:
other- The other value.- Returns:
- The value if present or the other value if not.
-
toString
-