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
ModifierConstructorDescriptionBasicHeader
(String name, Object value) Constructor.BasicHeader
(String name, Supplier<Object> value) Constructor with delayed value.protected
BasicHeader
(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.boolean
boolean
equalsIgnoreCase
(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()
int
hashCode()
boolean
Returnstrue if the value exists and is not empty.boolean
Returnstrue if the value exists.static BasicHeader
Static creator.static BasicHeader
of
(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:
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.
-
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.
-
getName
- Specified by:
getName
in interfaceNameValuePair
-
getValue
- Specified by:
getValue
in interfaceNameValuePair
-
getElements
- Specified by:
getElements
in interfaceHeader
- Throws:
ParseException
-
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.
-
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
-
isPresent
Returnstrue if the value exists.This is a shortcut for calling
asString().isPresent() .- Returns:
true if the value exists.
-
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.
-
get
If a value is present, returns the value, otherwise throwsNoSuchElementException
.This is a shortcut for calling
asString().get() .- Returns:
- The value if present.
-
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.
-
equals
-
hashCode
-
toString
-