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

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

Location:
trunk/ab5.0/ablib/src/Classes/System
Files:
2 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
  • trunk/ab5.0/ablib/src/Classes/System/Delegate.ab

    r352 r542  
    2929
    3030    Sub _Add( dg As DelegateBase )
    31         Dim i As Long
    32         For i=0 To ELM(dg.simpleDelegates.Count)
    33             simpleDelegates.Add( dg.simpleDelegates[i] )
    34         Next
     31        If Not ActiveBasic.IsNothing(dg) Then
     32            Dim i As Long
     33            For i=0 To ELM(dg.simpleDelegates.Count)
     34                simpleDelegates.Add( dg.simpleDelegates[i] )
     35            Next
     36        End If
    3537    End Sub
    3638
    3739    Sub _Delete( dg As DelegateBase )
    38         Dim i As Long
    39         For i=0 To ELM(This.simpleDelegates.Count)
    40             Dim i2 As Long
    41             Dim isExist = False
    42             For i2=0 To ELM(dg.simpleDelegates.Count)
    43                 If This.simpleDelegates[i].IsEqual( dg.simpleDelegates[i2] ) Then
    44                     isExist = True
     40        If Not ActiveBasic.IsNothing(dg) Then
     41            Dim i As Long
     42            For i=0 To ELM(This.simpleDelegates.Count)
     43                Dim i2 As Long
     44                Dim isExist = False
     45                For i2=0 To ELM(dg.simpleDelegates.Count)
     46                    If This.simpleDelegates[i].IsEqual( dg.simpleDelegates[i2] ) Then
     47                        isExist = True
     48                    End If
     49                Next
     50                If isExist Then
     51                    This.simpleDelegates.RemoveAt( i )
    4552                End If
    4653            Next
    47             If isExist Then
    48                 This.simpleDelegates.RemoveAt( i )
    49             End If
    50         Next
     54        End If
    5155    End Sub
    5256
Note: See TracChangeset for help on using the changeset viewer.