Top Description Fields Constructors Methods
io.vertx.core.http.impl

public Class CookieJar

extends AbstractSet<ServerCookie>
Class Inheritance
Imports
io.netty.handler.codec.http.cookie.ServerCookieDecoder, java.util.*

Vert.x cookie jar implementation. A Cookie Jar is a simple wrapped list that behaves like a Set with one difference. On adding an existing item, the underlying list is updated. This call also provides extra semantics for handling invalidation of cookies, which aren't plain removals as well as quick search utilities to find all matching cookies by name or by unique key.
Author
Paulo Lopes

Field Summary

Modifier and TypeField and Description
private static final CookieJar
private final List<ServerCookie>

Constructor Summary

AccessConstructor and Description
public
public
CookieJar(CharSequence cookieHeader)

private

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if cookie was added or replaced.
add
(ServerCookie
the cookie to add.
cookie
)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Adds a non null cookie to the cookie jar.

public void
public boolean
contains(Object
element whose presence in this set is to be tested
o
)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Returns true if this set contains the specified element.

private static int
cookieUniqueIdComparator(ServerCookie
base cookie
cookie
,
String
name to compare (not null)
name
,
String
maybe nullable domain
domain
,
String
maybe nullable path
path
)

Follows the Comparator interface guidelines to compare how the given cookie differs from the unique identifier, the tuple name, domain, path.

public ServerCookie

Returns:

cookie or null.
get
(String
name to search in the cookie jar
name
)

Get the first cookie that matches by name.

public ServerCookie

Returns:

a cookie or null
get
(String
cookie name
name
,
String
cookie domain
domain
,
String
cookie path
path
)

Get a unique cookie by the cookie unique identifier tuple.

public CookieJar

Returns:

read only cookie jar or an empty jar.
getAll
(String
name to search in the cookie jar
name
)

Get a read only slice of the cookie jar, with all cookies that matches by name.

public Iterator<ServerCookie>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Returns an iterator over the elements in this set.

public ServerCookie

Returns:

the matched cookie
removeOrInvalidate
(String
cookie name
name
,
String
cookie domain
domain
,
String
cookie path
path
,
boolean
true to invalidate the cookie, false to remove from the jar.
invalidate
)

Removes a unique cookie from the cookie jar using the cookies unique cookie identifier.

public ServerCookie

Returns:

the matched cookie
removeOrInvalidate
(String
cookie name
name
,
boolean
true to invalidate the cookie, false to remove from the jar.
invalidate
)

Removes the first cookie from the cookie jar that matches the cookies name.

public CookieJar

Returns:

read only cookie jar or an empty jar of cookies that were affected by the operation
removeOrInvalidateAll
(String
name to search in the cookie jar
name
,
boolean
true to invalidate the cookie, false to remove from the jar.
invalidate
)

Get a read only slice of the cookie jar, with all removed or invalidated cookies that matches by name.

private static void
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Returns the number of elements in this set (its cardinality).

Inherited from java.util.AbstractSet:
equalshashCoderemoveAll

Field Detail

EMPTYback to summary
private static final CookieJar EMPTY
listback to summary
private final List<ServerCookie> list

Constructor Detail

CookieJarback to summary
public CookieJar()
CookieJarback to summary
public CookieJar(CharSequence cookieHeader)
CookieJarback to summary
private CookieJar(List<ServerCookie> list)

Method Detail

addback to summary
public boolean add(ServerCookie cookie)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Adds a non null cookie to the cookie jar. Adding cookies is only allowed if the cookie jar is not a slice view of the original cookie jar. In other words if this object was acquired from getAll(String) or removeOrInvalidateAll(String, boolean) adding cookies will not be allowed.

Parameters
cookie:ServerCookie

the cookie to add.

Returns:boolean

true if cookie was added or replaced.

Annotations
@Override
Exceptions
UnsupportedOperationException:
if cookie jar is a slice view of the http exchange cookies
NullPointerException:
if cookie is null
clearback to summary
public void clear()

Overrides java.util.AbstractCollection.clear.

Implements java.util.Set.clear, java.util.Collection.clear.

Clears the cookie jar. Clearing the cookie jar is only allowed if the cookie jar is not a slice view of the original cookie jar. In other words if this object was acquired from getAll(String) or removeOrInvalidateAll(String, boolean) adding cookies will not be allowed.

Annotations
@Override
Exceptions
UnsupportedOperationException:
if cookie jar is a slice view of the http exchange cookies
containsback to summary
public boolean contains(Object o)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Doc from java.util.Set.contains.

Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that Objects.equals(o, e). A Subtle difference here is that matching of cookies is done against the cookie unique identifier, not the equals(Object) method.

Parameters
o:Object

element whose presence in this set is to be tested

Returns:boolean

true if this set contains the specified element

Annotations
@Override
cookieUniqueIdComparatorback to summary
private static int cookieUniqueIdComparator(ServerCookie cookie, String name, String domain, String path)

Follows the Comparator interface guidelines to compare how the given cookie differs from the unique identifier, the tuple name, domain, path.

Parameters
cookie:ServerCookie

base cookie

name:String

name to compare (not null)

domain:String

maybe nullable domain

path:String

maybe nullable path

getback to summary
public ServerCookie get(String name)

Get the first cookie that matches by name.

Parameters
name:String

name to search in the cookie jar

Returns:ServerCookie

cookie or null.

getback to summary
public ServerCookie get(String name, String domain, String path)

Get a unique cookie by the cookie unique identifier tuple.

Parameters
name:String

cookie name

domain:String

cookie domain

path:String

cookie path

Returns:ServerCookie

a cookie or null

getAllback to summary
public CookieJar getAll(String name)

Get a read only slice of the cookie jar, with all cookies that matches by name.

Parameters
name:String

name to search in the cookie jar

Returns:CookieJar

read only cookie jar or an empty jar.

Exceptions
UnsupportedOperationException:
of this cookie jar is a slice view
iteratorback to summary
public Iterator<ServerCookie> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Doc from java.util.Set.iterator.

Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).

Returns:Iterator<ServerCookie>

an iterator over the elements in this set

Annotations
@Override
removeOrInvalidateback to summary
public ServerCookie removeOrInvalidate(String name, String domain, String path, boolean invalidate)

Removes a unique cookie from the cookie jar using the cookies unique cookie identifier.

Parameters
name:String

cookie name

domain:String

cookie domain

path:String

cookie path

invalidate:boolean

true to invalidate the cookie, false to remove from the jar.

Returns:ServerCookie

the matched cookie

Exceptions
UnsupportedOperationException:
of this cookie jar is a slice view
removeOrInvalidateback to summary
public ServerCookie removeOrInvalidate(String name, boolean invalidate)

Removes the first cookie from the cookie jar that matches the cookies name.

Parameters
name:String

cookie name

invalidate:boolean

true to invalidate the cookie, false to remove from the jar.

Returns:ServerCookie

the matched cookie

Exceptions
UnsupportedOperationException:
of this cookie jar is a slice view
removeOrInvalidateAllback to summary
public CookieJar removeOrInvalidateAll(String name, boolean invalidate)

Get a read only slice of the cookie jar, with all removed or invalidated cookies that matches by name.

Parameters
name:String

name to search in the cookie jar

invalidate:boolean

true to invalidate the cookie, false to remove from the jar.

Returns:CookieJar

read only cookie jar or an empty jar of cookies that were affected by the operation

Exceptions
UnsupportedOperationException:
of this cookie jar is a slice view
removeOrInvalidateCookieback to summary
private static void removeOrInvalidateCookie(Iterator<ServerCookie> it, ServerCookie cookie, boolean invalidate)
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Doc from java.util.Set.size.

Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this set (its cardinality)

Annotations
@Override