📄 rangedarraylist.cls
字号:
Set mList(mIndex + Index) = RHS
mVersion = mVersion + 1
End Property
Private Property Let ArrayList_Item(ByVal Index As Long, RHS As Variant)
Call VerifyVersion
If Index < 0 Or Index >= mCount Then _
Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_Index), "index", Index)
mList(mIndex + Index) = RHS
mVersion = mVersion + 1
End Property
Private Property Get ArrayList_Item(ByVal Index As Long) As Variant
Call VerifyVersion
If Index < 0 Or Index >= mCount Then _
Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_Index), "index", Index)
Helper.MoveVariant ArrayList_Item, mList(mIndex + Index)
End Property
Private Function ArrayList_LastIndexOf(Value As Variant, Optional ByRef StartIndex As Variant, Optional ByRef Count As Variant, Optional ByVal Comparer As IComparer) As Long
Call VerifyVersion
Dim ElemIndex As Long
Dim ElemCount As Long
If GetOptionalLongPair(StartIndex, mCount - 1, ElemIndex, Count, mCount, ElemCount) = Argument_ParamRequired Then _
Throw Cor.NewArgumentException(Environment.GetResourceString(Argument_ParamRequired), IIf(IsMissing(StartIndex), "StartIndex", "Count"))
If ElemIndex >= mCount Then _
Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_UBound), "StartIndex", ElemIndex)
If ElemCount < 0 Then _
Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_NeedNonNegNum), "Count", ElemCount)
If ElemIndex - ElemCount + 1 < 0 Then _
Throw Cor.NewArgumentException(Environment.GetResourceString(Argument_InvalidCountOffset), "Count")
Dim Index As Long
Index = mList.LastIndexOf(Value, mIndex + ElemIndex, ElemCount, Comparer)
If Index >= 0 Then Index = Index - mIndex
ArrayList_LastIndexOf = Index
End Function
Private Function ArrayList_NewEnum() As stdole.IUnknown
Call VerifyVersion
Set ArrayList_NewEnum = CreateEnumerator(ArrayList_GetEnumerator)
End Function
Private Sub ArrayList_Remove(Value As Variant, Optional ByVal Comparer As IComparer)
Call VerifyVersion
Dim Index As Long
Index = mList.IndexOf(Value, mIndex, mCount, Comparer)
If Index >= 0 Then
Call mList.RemoveAt(Index)
mCount = mCount - 1
mVersion = mVersion + 1
End If
End Sub
Private Sub ArrayList_RemoveAt(ByVal Index As Long)
Call VerifyVersion
If Index < 0 Or Index >= mCount Then _
Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_Index), "index", Index)
Call mList.RemoveAt(mIndex + Index)
mCount = mCount - 1
mVersion = mVersion + 1
End Sub
Private Sub ArrayList_RemoveRange(ByVal Index As Long, ByVal Count As Long)
Call VerifyVersion
If Index < 0 Or Count < 0 Then _
Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_NeedNonNegNum), IIf(Index < 0, "index", "count"), IIf(Index < 0, Index, Count))
If Index + Count > mCount Then _
Throw Cor.NewArgumentException(Environment.GetResourceString(Argument_InvalidCountOffset), "count")
Call mList.RemoveRange(mIndex + Index, Count)
mCount = mCount - Count
mVersion = mVersion + 1
End Sub
Private Sub ArrayList_Reverse(Optional ByRef Index As Variant, Optional ByRef Count As Variant)
Call VerifyVersion
Dim ElemCount As Long
Dim ElemIndex As Long
Dim Result As Long
Result = GetOptionalListRange(mCount, Index, ElemIndex, Count, ElemCount)
If Result <> NO_ERROR Then Call ThrowListRangeException(Result, ElemIndex, "Index", ElemCount, "Count", IsMissing(Index))
Call mList.Reverse(mIndex + ElemIndex, ElemCount)
mVersion = mVersion + 1
End Sub
Private Sub ArrayList_SetRange(ByVal Index As Long, c As Variant)
Call VerifyVersion
If Index < 0 Then _
Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_NeedNonNegNum), "Iindex", Index)
Dim TotalElements As Long
TotalElements = GetCollectionSize(c)
If Index + TotalElements > mCount Then _
Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_LargerThanCollection), "index", Index)
Call mList.SetRange(mIndex + Index, c)
mVersion = mVersion + 1
End Sub
Private Sub ArrayList_Sort(Optional ByRef StartIndex As Variant, Optional ByRef Count As Variant, Optional ByVal Comparer As IComparer)
Call VerifyVersion
Dim ElemCount As Long
Dim ElemIndex As Long
Dim Result As Long
Result = GetOptionalListRange(mCount, StartIndex, ElemIndex, Count, ElemCount)
If Result <> NO_ERROR Then Call ThrowListRangeException(Result, ElemIndex, "StartIndex", ElemCount, "Count", IsMissing(StartIndex))
Call mList.Sort(mIndex + ElemIndex, ElemCount, Comparer)
End Sub
Private Function ArrayList_ToArray(Optional ByVal ArrayType As ciArrayTypes = 12&) As Variant
Call VerifyVersion
Dim Ret As Variant
Ret = cArray.CreateInstance(ArrayType, mCount)
If mCount > 0 Then Call mList.CopyToEx(mIndex, Ret, 0, mCount)
ArrayList_ToArray = Ret
End Function
Private Function ArrayList_ToString() As String
ArrayList_ToString = IObject_ToString
End Function
Private Sub ArrayList_TrimToSize()
Call VerifyVersion
mList.TrimToSize
mVersion = mVersion + 1
End Sub
Private Property Get ArrayList_Version() As Long
ArrayList_Version = mVersion
End Property
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ICloneable Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function ICloneable_Clone() As Object
Set ICloneable_Clone = ArrayList_Clone
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' IObject Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function IObject_Equals(Value As Variant) As Boolean
IObject_Equals = Object.Equals(Me, Value)
End Function
Private Function IObject_GetHashcode() As Long
IObject_GetHashcode = ObjPtr(CUnk(Me))
End Function
Private Function IObject_ToString() As String
IObject_ToString = Object.ToString(Me, App)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ICollection Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub ICollection_CopyTo(Arr As Variant, ByVal Index As Long)
Call ArrayList_CopyTo(Arr, Index)
End Sub
Private Property Get ICollection_Count() As Long
ICollection_Count = ArrayList_Count
End Property
Private Function ICollection_GetEnumerator() As IEnumerator
Set ICollection_GetEnumerator = ArrayList_GetEnumerator
End Function
Private Function ICollection_NewEnum() As stdole.IUnknown
Set ICollection_NewEnum = ArrayList_NewEnum
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' IEnumerable Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function IEnumerable_GetEnumerator() As IEnumerator
Set IEnumerable_GetEnumerator = ArrayList_GetEnumerator
End Function
Private Function IEnumerable_NewEnum() As stdole.IUnknown
Set IEnumerable_NewEnum = ArrayList_NewEnum
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' IList Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function IList_Add(Value As Variant) As Long
IList_Add = ArrayList_Add(Value)
End Function
Private Sub IList_Clear()
ArrayList_Clear
End Sub
Private Function IList_Contains(Value As Variant, Optional ByVal Comparer As IComparer) As Boolean
IList_Contains = ArrayList_Contains(Value, Comparer)
End Function
Private Sub IList_CopyTo(Arr As Variant, ByVal Index As Long)
Call ArrayList_CopyTo(Arr, Index)
End Sub
Private Property Get IList_Count() As Long
IList_Count = ArrayList_Count
End Property
Private Function IList_GetEnumerator() As IEnumerator
Set IList_GetEnumerator = ArrayList_GetEnumerator
End Function
Private Function IList_IndexOf(Value As Variant, Optional ByVal Comparer As IComparer) As Long
IList_IndexOf = ArrayList_IndexOf(Value, , , Comparer)
End Function
Private Sub IList_Insert(ByVal Index As Long, Value As Variant)
Call ArrayList_Insert(Index, Value)
End Sub
Private Property Get IList_IsFixedSize() As Boolean
IList_IsFixedSize = ArrayList_IsFixedSize
End Property
Private Property Get IList_IsReadOnly() As Boolean
IList_IsReadOnly = ArrayList_IsReadOnly
End Property
Private Property Set IList_Item(ByVal Index As Long, RHS As Variant)
Set ArrayList_Item(Index) = RHS
End Property
Private Property Let IList_Item(ByVal Index As Long, RHS As Variant)
ArrayList_Item(Index) = RHS
End Property
Private Property Get IList_Item(ByVal Index As Long) As Variant
Call Helper.MoveVariant(IList_Item, ArrayList_Item(Index))
End Property
Private Function IList_NewEnum() As stdole.IUnknown
Set IList_NewEnum = ArrayList_NewEnum
End Function
Private Sub IList_Remove(Value As Variant, Optional ByVal Comparer As IComparer)
Call ArrayList_Remove(Value, Comparer)
End Sub
Private Sub IList_RemoveAt(ByVal Index As Long)
Call ArrayList_RemoveAt(Index)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -