# Class goog.Uri.QueryData

code »

Class used to represent URI query parameters. It is essentially a hash of name-value pairs, though a name can be present more than once. Has the same interface as the collections in goog.structs.

## Constructor

goog.Uri.QueryData ( opt_query, opt_uri, opt_ignoreCase )

Parameters

opt_query: `?string=`
  Optional encoded query string to parse into the object.
opt_uri: `goog.Uri=`
  Optional uri object that should have its cache invalidated when this object updates. Deprecated -- this is no longer required.
opt_ignoreCase: `boolean=`
  If true, ignore the case of the parameter name in #get.

Show:Public Protected Private

## Instance Methods

code »add ( key, value ) ⇒ `!goog.Uri.QueryData`

Adds a key value pair.

Parameters

key: `string`
  Name.
value: `*`
  Value.

Returns

Instance of this object.

code »clear ( )

Clears the parameters.

code »clone ( ) ⇒ `!goog.Uri.QueryData`

Clone the query data instance.

Returns

New instance of the QueryData object.

code »containsKey ( key ) ⇒ `boolean`

Whether there is a parameter with the given name

Parameters

key: `string`
  The parameter name to check for.

Returns

Whether there is a parameter with the given name.

code »containsValue ( value ) ⇒ `boolean`

Whether there is a parameter with the given value.

Parameters

value: `*`
  The value to check for.

Returns

Whether there is a parameter with the given value.

code »ensureKeyMapInitialized_ ( )

If the underlying key map is not yet initialized, it parses the query string and fills the map with parsed data.

code »extend ( var_args )

Extends a query data object with another query data or map like object. This operates 'in-place', it does not create a new QueryData object.

Parameters

var_args: `...(goog.Uri.QueryData|goog.structs.Map|Object)`
  The object from which key value pairs will be copied.

code »filterKeys ( keys ) ⇒ `!goog.Uri.QueryData`

Removes all keys that are not in the provided list. (Modifies this object.)

Parameters

keys: `Array.<string>`
  The desired keys.

Returns

a reference to this object.

code »get ( key, opt_default ) ⇒ `*`

Returns the first value associated with the key. If the query data has no such key this will return undefined or the optional default.

Parameters

key: `string`
  The name of the parameter to get the value for.
opt_default: `*=`
  The default value to return if the query data has no such key.

Returns

The first string value associated with the key, or opt_default if there's no value.

code »getCount ( ) ⇒ `?number`

Returns

The number of parameters.

code »getKeyName_ ( arg ) ⇒ `string`

Helper function to get the key name from a JavaScript object. Converts the object to a string, and to lower case if necessary.

Parameters

arg: `*`
  The object to get a key name from.

Returns

valid key name which can be looked up in #keyMap_.

code »getKeys ( ) ⇒ `!Array.<string>`

Returns all the keys of the parameters. If a key is used multiple times it will be included multiple times in the returned array

Returns

All the keys of the parameters.

code »getValues ( opt_key ) ⇒ `!Array`

Returns all the values of the parameters with the given name. If the query data has no such key this will return an empty array. If no key is given all values wil be returned.

Parameters

opt_key: `string=`
  The name of the parameter to get the values for.

Returns

All the values of the parameters with the given name.

code »invalidateCache_ ( )

Invalidate the cache.

code »isEmpty ( ) ⇒ `boolean`

Returns

Whether we have any parameters.

code »remove ( key ) ⇒ `boolean`

Removes all the params with the given key.

Parameters

key: `string`
  Name.

Returns

Whether any parameter was removed.

code »set ( key, value ) ⇒ `!goog.Uri.QueryData`

Sets a key value pair and removes all other keys with the same value.

Parameters

key: `string`
  Name.
value: `*`
  Value.

Returns

Instance of this object.

code »setIgnoreCase ( ignoreCase )

Ignore case in parameter names. NOTE: If there are already key/value pairs in the QueryData, and ignoreCase_ is set to false, the keys will all be lower-cased.

Parameters

ignoreCase: `boolean`
  whether this goog.Uri should ignore case.

code »setValues ( key, values )

Sets the values for a key. If the key already exists, this will override all of the existing values that correspond to the key.

Parameters

key: `string`
  The key to set values for.
values: `Array`
  The values to set.

code »toDecodedString ( ) ⇒ `string`

Returns

Decoded query string.

code »toString ( ) ⇒ `string`

Returns

Encoded query string.

## Instance Properties

code »count_ : `?number`

The number of params, or null if it requires computing.

code »encodedQuery_ : `?string`

Encoded query string, or null if it requires computing from the key map.

code »ignoreCase_ : `boolean`

If true, ignore the case of the parameter name in #get.

code »keyMap_ : `goog.structs.Map.<string, Array>`

The map containing name/value or name/array-of-values pairs. May be null if it requires parsing from the query string. We need to use a Map because we cannot guarantee that the key names will not be problematic for IE.

## Static Functions

code »goog.Uri.QueryData.createFromKeysValues ( keys, values, opt_uri, opt_ignoreCase ) ⇒ `!goog.Uri.QueryData`

Creates a new query data instance from parallel arrays of parameter names and values. Allows for duplicate parameter names. Throws an error if the lengths of the arrays differ.

Parameters

keys: `Array.<string>`
  Parameter names.
values: `Array`
  Parameter values.
opt_uri: `goog.Uri=`
  URI object that should have its cache invalidated when this object updates.
opt_ignoreCase: `boolean=`
  If true, ignore the case of the parameter name in #get.

Returns

The populated query data instance.

code »goog.Uri.QueryData.createFromMap ( map, opt_uri, opt_ignoreCase ) ⇒ `!goog.Uri.QueryData`

Creates a new query data instance from a map of names and values.

Parameters

map: `(!goog.structs.Map|!Object)`
  Map of string parameter names to parameter value. If parameter value is an array, it is treated as if the key maps to each individual value in the array.
opt_uri: `goog.Uri=`
  URI object that should have its cache invalidated when this object updates.
opt_ignoreCase: `boolean=`
  If true, ignore the case of the parameter name in #get.

Returns

The populated query data instance.