Ignore:
Timestamp:
Jul 13, 2008, 2:29:17 AM (16 years ago)
Author:
イグトランス (egtra)
Message:

Controlをデリゲートベースにした。DictionaryのContainsKeyとTryGetValueを実装。デリゲートの追加・削除の右辺にNothingを指定可能にした。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/ablib/src/Classes/System/Collections/Generic/Dictionary.ab

    r537 r542  
    4747        Dim a = al[hash] As ArrayList
    4848
    49         If Not Object.ReferenceEquals(a, Nothing) Then
     49        If Not ActiveBasic.IsNothing(a) Then
    5050            Dim i As Long
    5151            For i = 0 To ELM(a.Count)
     
    7777                If pair.Key.Equals(key) Then
    7878                    pair.Value = value
     79                    Exit Sub
    7980                End If
    8081            Next
     
    135136    End Function
    136137
    137 '   Function ContainsKey(key As Key) As Boolean
    138 '   End Function
     138    /*!
     139    @biref  指定されたキーが格納されているか調べる。
     140    @date   2008/07/11
     141    @param[in] key  検索対象のキー
     142    @retval True    格納されていたとき
     143    @retval False   格納されていなかったとき
     144    @throw ArgumentNullException    keyがNothingだったとき
     145    @author Egtra
     146    */
     147    Function ContainsKey(key As Key) As Boolean
     148        If ActiveBasic.IsNothing(key) Then
     149            Throw New ArgumentNullException("key")
     150        End If
     151        ContainsKey = False
     152
     153        Dim hash = getHash(key)
     154        Dim a = al[hash] As ArrayList
     155
     156        If Not ActiveBasic.IsNothing(a) Then
     157            Dim i As Long
     158            For i = 0 To ELM(a.Count)
     159                Dim pair = a[i] As Detail.Pair
     160                If pair.Key.Equals(key) Then
     161                    ContainsKey = True
     162                    Exit Function
     163                End If
     164            Next
     165        End If
     166    End Function
     167
    139168'   Function ContainsValue(value As T) As Boolean
    140169'   End Function
     
    169198    End Function
    170199
    171 '   Function TryGetValue(key As Key, ByRef value As T) As Boolean
    172 '   End Function
     200    Function TryGetValue(key As Key, ByRef value As T) As Boolean
     201        If ActiveBasic.IsNothing(key) Then
     202            Throw New ArgumentNullException("key")
     203        End If
     204        TryGetValue = False
     205        value = Nothing
     206
     207        Dim hash = getHash(key)
     208        Dim a = al[hash] As ArrayList
     209
     210        If Not ActiveBasic.IsNothing(a) Then
     211            Dim i As Long
     212            For i = 0 To ELM(a.Count)
     213                Dim pair = a[i] As Detail.Pair
     214                If pair.Key.Equals(key) Then
     215                    TryGetValue = True
     216                    value = pair.Value
     217                    Exit Function
     218                End If
     219            Next
     220        End If
     221    End Function
    173222
    174223    'Classses
Note: See TracChangeset for help on using the changeset viewer.