Top Description Inners Fields Constructors Methods
org.eclipse.jetty.util

public Class Fields

extends Object
implements Iterable<Fields.Field>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Imports
java.util.ArrayList, .Collections, .Iterator, .LinkedHashMap, .LinkedHashSet, .List, .Map, .Objects, .Set, .TreeMap, java.util.stream.Collectors, .Stream

A container for name/value pairs, known as fields.

A Field is composed of a name string that can be case-sensitive or case-insensitive (by specifying the option at the constructor) and of a case-sensitive set of value strings.

The implementation of this class is not thread safe.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Fields.Field

A named list of string values.

Field Summary

Modifier and TypeField and Description
public static final Fields
private final Map<String, Fields.Field>

Constructor Summary

AccessConstructor and Description
public
Fields()

Creates an empty, modifiable, case insensitive Fields instance.

public
Fields(boolean
whether this Fields instance must be case sensitive
caseSensitive
)

Creates an empty, modifiable, case insensitive Fields instance.

public

Method Summary

Modifier and TypeMethod and Description
public void
add(String
the field name
name
,
String
the field value to add
value
)

Adds the given value to a field with the given name, creating a Field is none exists for the given name.

public void
add(Fields.Field
the field to add
field
)

Adds the given field, storing it if none exists for the given name, or adding all the values to the existing field with the given name.

public void
addAll(Fields fields)

public Fields
public void
clear()

Empties this Fields instance from all fields.

public static Fields

Returns:

Fields, which may be empty, but never null.
combine
(Fields
The base Fields or null
a
,
Fields
The overlayed Fields or null
b
)

Combine two Fields

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public Fields.Field
get(String
the field name
name
)

Returns: the Field with the given name, or null if no such field exists

public Set<String>
getNames()

Returns: a set of field names

public int

Returns:

the number of fields
getSize
()

Get the number of fields.

public String
getValue(String
the field name
name
)

Returns: the first value of the field with the given name, or null if no such field exists

public List<String>
getValues(String
the field name
name
)

Returns: the values of the field with the given name, or null if no such field exists

public List<String>
getValuesOrEmpty(String
the field name
name
)

Returns: the values of the field with the given name, or empty list if no such field exists

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
isEmpty()

Returns: whether this Fields instance is empty

public Iterator<Fields.Field>

Returns:

an iterator over the Fields present in this instance
iterator
()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public void
put(String
the field name
name
,
String
the field value
value
)

Inserts or replaces the given name/value pair as a single-valued Field.

public void
put(Fields.Field
the field to put
field
)

Inserts or replaces the given Field, mapped to the field's name

public Fields.Field

Returns:

the removed field, or null if no such field existed
remove
(String
the name of the field to remove
name
)

Removes the Field with the given name.

public Stream<Fields.Field>
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public Map<String, String[]>
toStringArrayMap()

Returns: the fields (name and values) of this instance copied into a Map

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

EMPTYback to summary
public static final Fields EMPTY
fieldsback to summary
private final Map<String, Fields.Field> fields

Constructor Detail

Fieldsback to summary
public Fields()

Creates an empty, modifiable, case insensitive Fields instance.

Fieldsback to summary
public Fields(boolean caseSensitive)

Creates an empty, modifiable, case insensitive Fields instance.

**
Parameters
caseSensitive:boolean

whether this Fields instance must be case sensitive

Fieldsback to summary
public Fields(Map<String, Fields.Field> fields)

Method Detail

addback to summary
public void add(String name, String value)

Adds the given value to a field with the given name, creating a Field is none exists for the given name.

Parameters
name:String

the field name

value:String

the field value to add

addback to summary
public void add(Fields.Field field)

Adds the given field, storing it if none exists for the given name, or adding all the values to the existing field with the given name.

Parameters
field:Fields.Field

the field to add

addAllback to summary
public void addAll(Fields fields)
asImmutableback to summary
public Fields asImmutable()
clearback to summary
public void clear()

Empties this Fields instance from all fields.

See Also
isEmpty()
combineback to summary
public static Fields combine(Fields a, Fields b)

Combine two Fields

Parameters
a:Fields

The base Fields or null

b:Fields

The overlayed Fields or null

Returns:Fields

Fields, which may be empty, but never null.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getback to summary
public Fields.Field get(String name)
Parameters
name:String

the field name

Returns:Fields.Field

the Field with the given name, or null if no such field exists

getNamesback to summary
public Set<String> getNames()
Returns:Set<String>

a set of field names

getSizeback to summary
public int getSize()

Get the number of fields.

Returns:int

the number of fields

getValueback to summary
public String getValue(String name)
Parameters
name:String

the field name

Returns:String

the first value of the field with the given name, or null if no such field exists

getValuesback to summary
public List<String> getValues(String name)
Parameters
name:String

the field name

Returns:List<String>

the values of the field with the given name, or null if no such field exists

getValuesOrEmptyback to summary
public List<String> getValuesOrEmpty(String name)
Parameters
name:String

the field name

Returns:List<String>

the values of the field with the given name, or empty list if no such field exists

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()
Returns:boolean

whether this Fields instance is empty

iteratorback to summary
public Iterator<Fields.Field> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:Iterator<Fields.Field>

an iterator over the Fields present in this instance

Annotations
@Override
putback to summary
public void put(String name, String value)

Inserts or replaces the given name/value pair as a single-valued Field.

Parameters
name:String

the field name

value:String

the field value

putback to summary
public void put(Fields.Field field)

Inserts or replaces the given Field, mapped to the field's name

Parameters
field:Fields.Field

the field to put

removeback to summary
public Fields.Field remove(String name)

Removes the Field with the given name.

Parameters
name:String

the name of the field to remove

Returns:Fields.Field

the removed field, or null if no such field existed

streamback to summary
public Stream<Fields.Field> stream()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
toStringArrayMapback to summary
public Map<String, String[]> toStringArrayMap()
Returns:Map<String, String[]>

the fields (name and values) of this instance copied into a Map

org.eclipse.jetty.util back to summary

public Class Fields.Field

extends Object
Class Inheritance

A named list of string values.

The name is case-sensitive and there must be at least one value.

Field Summary

Modifier and TypeField and Description
private final String
private final List<String>

Constructor Summary

AccessConstructor and Description
public
Field(String name, String value)

private
Field(String name, List<String> values, String... moreValues)

private
Field(String name, List<String> values, List<String> moreValues)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public String
getName()

Returns: the field's name

public String
getValue()

Returns: the first field's value

public Integer

Returns:

the result of getValue() converted to an integer, or null
getValueAsInt
()

Attempts to convert the result of getValue() to an integer, returning it if the conversion is successful; returns null if the result of getValue() is null.

public List<String>
getValues()

Returns: the field's values

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
hasMultipleValues()

Returns: whether the field has multiple values

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

nameback to summary
private final String name
valuesback to summary
private final List<String> values

Constructor Detail

Fieldback to summary
public Field(String name, String value)
Fieldback to summary
private Field(String name, List<String> values, String... moreValues)
Fieldback to summary
private Field(String name, List<String> values, List<String> moreValues)

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getNameback to summary
public String getName()
Returns:String

the field's name

getValueback to summary
public String getValue()
Returns:String

the first field's value

getValueAsIntback to summary
public Integer getValueAsInt()

Attempts to convert the result of getValue() to an integer, returning it if the conversion is successful; returns null if the result of getValue() is null.

Returns:Integer

the result of getValue() converted to an integer, or null

Exceptions
NumberFormatException:
if the conversion fails
getValuesback to summary
public List<String> getValues()
Returns:List<String>

the field's values

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
hasMultipleValuesback to summary
public boolean hasMultipleValues()
Returns:boolean

whether the field has multiple values

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override