Package org.apache.solr.common.util

# Class SimpleOrderedMap<T>

java.lang.Object
org.apache.solr.common.util.NamedList<T>
org.apache.solr.common.util.SimpleOrderedMap<T>

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `Iterable<Map.Entry<String,T>>`, `Map<String,T>`, `MapSerializable`, `MapWriter`, `NavigableObject`, `org.noggit.JSONWriter.Writable`

public class SimpleOrderedMap<T> extends NamedList<T> implements Map<String,T>
`SimpleOrderedMap` is a `NamedList` where access by key is more important than maintaining order when it comes to representing the held data in other forms, as ResponseWriters normally do. It's normally not a good idea to repeat keys or use null keys, but this is not enforced. If key uniqueness enforcement is desired, use a regular `Map`.

For example, a JSON response writer may choose to write a SimpleOrderedMap as {"foo":10,"bar":20} and may choose to write a NamedList as ["foo",10,"bar",20]. An XML response writer may choose to render both the same way.

This class does not provide efficient lookup by key. The lookup performance is only O(N), and not O(1) or O(Log N) as it is for the most common Map-implementations. Its main purpose is to hold data to be serialized. It aims to minimize overhead and to be efficient at adding new elements.

See Also:
  - Serialized Form

## Nested Class Summary

## Nested classes/interfaces inherited from class org.apache.solr.common.util.NamedList

`NamedList.NamedListEntry<T>`

## Nested classes/interfaces inherited from interface java.util.Map

`Map.Entry<K,V>`

## Nested classes/interfaces inherited from interface org.apache.solr.common.MapWriter

`MapWriter.EntryWriter`

## Field Summary

### Fields inherited from class org.apache.solr.common.util.NamedList

`nvPairs`

## Constructor Summary

Constructors
Constructor
Description
`SimpleOrderedMap()`
Creates an empty instance
`SimpleOrderedMap(int sz)`
`SimpleOrderedMap(Map.Entry<String,T>[] nameValuePairs)`
`SimpleOrderedMap(MapWriter mapWriter)`
Can convert a `SolrParams` and other things.

## Method Summary

Modifier and Type
Method
Description
`SimpleOrderedMap<T>`
`clone()`
Makes a shallow copy of the named list.
`boolean`
`containsKey(Object key)`
`boolean`
`containsValue(Object value)`
`Set<Map.Entry<String,T>>`
`entrySet()`
`boolean`
`equals(Object obj)`
`T`
`get(Object key)`
`int`
`hashCode()`
`boolean`
`isEmpty()`
`Set<String>`
`keySet()`
`static SimpleOrderedMap<Object>`
`of()`
Returns a shared, empty, and immutable instance of `SimpleOrderedMap`.
`static <T> SimpleOrderedMap<T>`
`of(String name, T val)`
Returns an immutable instance of `SimpleOrderedMap` with a single key-value pair.
`T`
`put(String key, T value)`
`void`
`putAll(Map<? extends String,? extends T> m)`
`T`
`remove(Object key)`
`Collection<T>`
`values()`

### Methods inherited from class org.apache.solr.common.util.NamedList

`add, addAll, addAll, asMap, asShallowMap, asShallowMap, clear, forEach, get, get, getAll, getBooleanArg, getImmutableCopy, getName, getOrDefault, getVal, indexOf, indexOf, iterator, remove, remove, removeAll, removeBooleanArg, removeConfigArgs, setName, setVal, size, toSolrParams, toString, writeMap`

### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

### Methods inherited from interface java.util.Map

`clear, compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll, size`

### Methods inherited from interface org.apache.solr.common.MapWriter

`jsonStr, toMap, write`

### Methods inherited from interface org.apache.solr.common.NavigableObject

`_forEachEntry, _forEachEntry, _forEachEntry, _get, _get, _getStr, _getStr, _size`

## Constructor Details

### SimpleOrderedMap

public SimpleOrderedMap()
Creates an empty instance

### SimpleOrderedMap

public SimpleOrderedMap(int sz)

### SimpleOrderedMap

public SimpleOrderedMap(Map.Entry<String,T>[] nameValuePairs)

### SimpleOrderedMap

public SimpleOrderedMap(MapWriter mapWriter)
Can convert a `SolrParams` and other things.

## Method Details

### clone

public SimpleOrderedMap<T> clone()
Description copied from class: `NamedList`
Makes a shallow copy of the named list.

Overrides:
  `clone` in class `NamedList<T>`

### equals

public boolean equals(Object obj)

Specified by:
  `equals` in interface `Map<String,T>`
Overrides:
  `equals` in class `NamedList<T>`

### hashCode

public int hashCode()

Specified by:
  `hashCode` in interface `Map<String,T>`
Overrides:
  `hashCode` in class `NamedList<T>`

### isEmpty

public boolean isEmpty()

Specified by:
  `isEmpty` in interface `Map<String,T>`

### containsKey

public boolean containsKey(Object key)

Specified by:
  `containsKey` in interface `Map<String,T>`

### containsValue

public boolean containsValue(Object value)

Specified by:
  `containsValue` in interface `Map<String,T>`

### get

public T get(Object key)

Has linear lookup time O(N)

Specified by:
  `get` in interface `Map<String,T>`
See Also:
  - `NamedList.get(String)`

### put

public T put(String key, T value)

Specified by:
  `put` in interface `Map<String,T>`

### remove

public T remove(Object key)

Specified by:
  `remove` in interface `Map<String,T>`
See Also:
  - `NamedList.remove(String)`

### putAll

public void putAll(Map<? extends String,? extends T> m)

Specified by:
  `putAll` in interface `Map<String,T>`

### keySet

public Set<String> keySet()

Specified by:
  `keySet` in interface `Map<String,T>`

### values

public Collection<T> values()

Specified by:
  `values` in interface `Map<String,T>`

### entrySet

public Set<Map.Entry<String,T>> entrySet()

Specified by:
  `entrySet` in interface `Map<String,T>`

### of

public static <T> SimpleOrderedMap<T> of(String name, T val)
Returns an immutable instance of `SimpleOrderedMap` with a single key-value pair.

Returns:
  `SimpleOrderedMap` containing one key-value pair

### of

public static SimpleOrderedMap<Object> of()
Returns a shared, empty, and immutable instance of `SimpleOrderedMap`.

Returns:
  Empty `SimpleOrderedMap` (immutable)