Show / Hide Table of Contents

Class SortedDictionary

SortedList-based IDictionary implementation that allows null keys.

Inheritance
System.Object
SortedDictionary
Implements
System.Collections.IEnumerable
ISerializable
Namespace: Tangosol.Util.Collections
Assembly: Coherence.Core.dll
Syntax
public class SortedDictionary : SortedList, IEnumerable, ISerializable
Remarks

Note that null keys support intentionally breaks System.Collections.IDictionary contract, which states that an ArgumentNullException should be raised if the key is null.

However, this is necessary in order to match the behavior in Java and C++, where some Map implementations support null keys.

Note: This implementation is not thread safe. If you need it to be, you should wrap it with the SynchronizedDictionary.

Constructors

| Improve this Doc View Source

SortedDictionary()

Initializes a new instance of the SortedDictionary class that is empty, has the default initial capacity, and is sorted according to the System.IComparable interface implemented by each key added to the SortedDictionary object.

Declaration
public SortedDictionary()
| Improve this Doc View Source

SortedDictionary(SerializationInfo, StreamingContext)

Initializes a new instance of the SortedDictionary class that is serializable using the specified System.Runtime.Serialization.SerializationInfo and System.Runtime.Serialization.StreamingContext objects.

Declaration
protected SortedDictionary(SerializationInfo info, StreamingContext context)
Parameters
Type Name Description
SerializationInfo info

A System.Runtime.Serialization.SerializationInfo object containing the information required to serialize the HashDictionary object.

StreamingContext context

A System.Runtime.Serialization.StreamingContext object containing the source and destination of the serialized stream associated with the SortedDictionary.

Exceptions
Type Condition
System.ArgumentNullException

info is null.

| Improve this Doc View Source

SortedDictionary(IComparer)

Initializes a new instance of the SortedDictionary class that is empty, has the default initial capacity, and is sorted according to the specified System.Collections.IComparer interface.

Declaration
public SortedDictionary(IComparer comparer)
Parameters
Type Name Description
System.Collections.IComparer comparer

The System.Collections.IComparer implementation to use when comparing keys.-or- null to use the System.IComparable implementation of each key.

| Improve this Doc View Source

SortedDictionary(IComparer, Int32)

Initializes a new instance of the SortedDictionary class that is empty, has the specified initial capacity, and is sorted according to the specified System.Collections.IComparer interface.

Declaration
public SortedDictionary(IComparer comparer, int capacity)
Parameters
Type Name Description
System.Collections.IComparer comparer

The System.Collections.IComparer implementation to use when comparing keys.-or- null to use the System.IComparable implementation of each key.

System.Int32 capacity

The initial number of elements this SortedDictionary object can contain.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

capacity is less than zero.

System.OutOfMemoryException

There is not enough available memory to create a SortedDictionary object with the specified capacity.

| Improve this Doc View Source

SortedDictionary(IDictionary)

Initializes a new instance of the SortedDictionary class that contains elements copied from the specified dictionary, has the same initial capacity as the number of elements copied, and is sorted according to the System.IComparable interface implemented by each key.

Declaration
public SortedDictionary(IDictionary d)
Parameters
Type Name Description
System.Collections.IDictionary d

The System.Collections.IDictionary implementation to copy to a new SortedDictionary object.

Exceptions
Type Condition
System.ArgumentNullException

d is null.

System.InvalidCastException

One or more elements in d do not implement the System.IComparable interface.

| Improve this Doc View Source

SortedDictionary(IDictionary, IComparer)

Initializes a new instance of the SortedDictionary class that contains elements copied from the specified dictionary, has the same initial capacity as the number of elements copied, and is sorted according to the specified System.Collections.IComparer interface.

Declaration
public SortedDictionary(IDictionary d, IComparer comparer)
Parameters
Type Name Description
System.Collections.IDictionary d

The System.Collections.IDictionary implementation to copy to a new SortedDictionary object.

System.Collections.IComparer comparer

The System.Collections.IComparer implementation to use when comparing keys.-or- null to use the System.IComparable implementation of each key.

Exceptions
Type Condition
System.ArgumentNullException

d is null.

System.InvalidCastException

comparer is null, and one or more elements in d do not implement the System.IComparable interface.

| Improve this Doc View Source

SortedDictionary(Int32)

Initializes a new instance of the SortedDictionary class that is empty, has the specified initial capacity, and is sorted according to the System.IComparable interface implemented by each key added to the SortedDictionary object.

Declaration
public SortedDictionary(int initialCapacity)
Parameters
Type Name Description
System.Int32 initialCapacity

The initial number of elements this SortedDictionary object can contain.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

initialCapacity is less than zero.

System.OutOfMemoryException

There is not enough available memory to create a SortedDictionary object with the specified initialCapacity.

Properties

| Improve this Doc View Source

Comparer

Return the System.Collections.IComparer associated with this SortedDictionary.

Declaration
public virtual IComparer Comparer { get; }
Property Value
Type Description
System.Collections.IComparer
| Improve this Doc View Source

Count

Gets the number of elements contained in the System.Collections.ICollection.

Declaration
public override int Count { get; }
Property Value
Type Description
System.Int32

The number of elements contained in the System.Collections.ICollection.

| Improve this Doc View Source

IsNullValueSet

Returns true is the value for the null key is set, false otherwise.

Declaration
protected bool IsNullValueSet { get; }
Property Value
Type Description
System.Boolean

true is the value for the null key is set, false otherwise.

| Improve this Doc View Source

Item[Object]

Gets or sets the element with the specified key.

Declaration
public override object this[object key] { get; set; }
Parameters
Type Name Description
System.Object key

The key of the element to get or set.

Property Value
Type Description
System.Object

The element with the specified key.

Exceptions
Type Condition
System.NotSupportedException

The property is set and the dictionary is read-only. -or- The property is set, key does not exist in the collection, and the dictionary has a fixed size.

| Improve this Doc View Source

Keys

Gets an System.Collections.ICollection object containing the keys of this dictionary.

Declaration
public override ICollection Keys { get; }
Property Value
Type Description
System.Collections.ICollection

An System.Collections.ICollection object containing the keys of this dictionary object.

| Improve this Doc View Source

Values

Gets an System.Collections.ICollection object containing the values in this dictionary.

Declaration
public override ICollection Values { get; }
Property Value
Type Description
System.Collections.ICollection

An System.Collections.ICollection object containing the values in this dictionary object.

Methods

| Improve this Doc View Source

Add(Object, Object)

Adds an element with the provided key and value to the System.Collections.IDictionary object.

Declaration
public override void Add(object key, object value)
Parameters
Type Name Description
System.Object key

The System.Object to use as the key of the element to add.

System.Object value

The System.Object to use as the value of the element to add.

Exceptions
Type Condition
System.ArgumentException

An element with the same key already exists in the System.Collections.IDictionary object.

System.NotSupportedException

The System.Collections.IDictionary is read-only. -or- The System.Collections.IDictionary has a fixed size.

| Improve this Doc View Source

AssertIsVariableSize()

Throw an exception if this dictionary is fixed size.

Declaration
protected void AssertIsVariableSize()
| Improve this Doc View Source

AssertIsWriteable()

Throw an exception if this dictionary is read-only.

Declaration
protected void AssertIsWriteable()
| Improve this Doc View Source

Clear()

Removes all elements from the System.Collections.IDictionary object.

Declaration
public override void Clear()
Exceptions
Type Condition
System.NotSupportedException

The System.Collections.IDictionary object is read-only.

| Improve this Doc View Source

Clone()

Creates a new object that is a copy of the current instance.

Declaration
public override object Clone()
Returns
Type Description
System.Object

A new object that is a copy of this instance.

| Improve this Doc View Source

Contains(Object)

Determines whether this dictionary contains an entry with the specified key.

Declaration
public override bool Contains(object key)
Parameters
Type Name Description
System.Object key

The key to locate in this dictionary.

Returns
Type Description
System.Boolean

true if the dictionary contains an element with the key; otherwise, false.

| Improve this Doc View Source

ContainsKey(Object)

Determines whether the SortedDictionary contains a specific key.

Declaration
public override bool ContainsKey(object key)
Parameters
Type Name Description
System.Object key

The key to locate in the SortedDictionary.

Returns
Type Description
System.Boolean

true if the SortedDictionary contains an element with the specified key; otherwise, false.

| Improve this Doc View Source

ContainsValue(Object)

Determines whether the SortedDictionary contains a specific value.

Declaration
public override bool ContainsValue(object value)
Parameters
Type Name Description
System.Object value

The value to locate in the SortedDictionary. The value can be null.

Returns
Type Description
System.Boolean

true if the SortedDictionary contains an element with the specified value; otherwise, false.

| Improve this Doc View Source

CopyTo(Array, Int32)

Copies the elements of the collection to an array, starting at a particular array index.

Declaration
public override void CopyTo(Array array, int index)
Parameters
Type Name Description
System.Array array

The one-dimensional array that is the destination of the elements copied from the collection. The array must have zero-based indexing.

System.Int32 index

The zero-based index in the array at which copying begins.

Exceptions
Type Condition
System.ArgumentNullException

array is null.

System.ArgumentOutOfRangeException

index is less than zero.

System.ArgumentException

array is multidimensional.-or- index is equal to or greater than the length of array.-or- The number of elements in the source collection is greater than the available space from index to the end of the destination array.

System.ArgumentException

The type of the source collection cannot be cast automatically to the type of the destination array.

| Improve this Doc View Source

Equals(IDictionary)

Compares this dictionary with another dictionary for equality.

Declaration
public virtual bool Equals(IDictionary dict)
Parameters
Type Name Description
System.Collections.IDictionary dict

Dictionary to compare this dictionary with.

Returns
Type Description
System.Boolean

true if the two dictionaries are equal; false otherwise.

Remarks

This method returns true if this dictionary and the specified dictionary have exactly the same entry set.

| Improve this Doc View Source

Equals(Object)

Determines whether the specified object is equal to this object.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj

The object to compare with this object.

Returns
Type Description
System.Boolean

true if the specified object is equal to this object; otherwise, false.

| Improve this Doc View Source

GetEnumerator()

Returns an System.Collections.IDictionaryEnumerator object for this dictionary.

Declaration
public override IDictionaryEnumerator GetEnumerator()
Returns
Type Description
System.Collections.IDictionaryEnumerator

An System.Collections.IDictionaryEnumerator object for this dictionary.

| Improve this Doc View Source

GetHashCode()

Returns a hash code for this object.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

A hash code for this object.

| Improve this Doc View Source

GetObjectData(SerializationInfo, StreamingContext)

Overrides serialization method to add support for null value serialization.

Declaration
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type Name Description
SerializationInfo info

Serialization info.

StreamingContext context

Serialization context.

| Improve this Doc View Source

Remove(Object)

Removes the element with the specified key from the System.Collections.IDictionary object.

Declaration
public override void Remove(object key)
Parameters
Type Name Description
System.Object key

The key of the element to remove.

Exceptions
Type Condition
System.NotSupportedException

The dictionary is read-only. -or- The dictionary has a fixed size.

| Improve this Doc View Source

ToString()

Returns string representation of this instance.

Declaration
public override string ToString()
Returns
Type Description
System.String

String representation of this instance.

Explicit Interface Implementations

| Improve this Doc View Source

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type Description
System.Collections.IEnumerator

An System.Collections.IEnumerator object that can be used to iterate through the collection.

Implements

System.Collections.IEnumerable
ISerializable
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2000, 2020, Oracle and/or its affiliates. All rights reserved.