blob: 36a8d969670f068fbc57a1803e0852b2cf391169 [file] [log] [blame]
Jens Geyerd5436f52014-10-03 19:50:38 +02001(*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *)
19
20unit Thrift.Collections;
21
22interface
23
24uses
Jens Geyer8f7487e2019-05-09 22:21:32 +020025 SysUtils, Generics.Collections, Generics.Defaults, Thrift.Utils;
Jens Geyerd5436f52014-10-03 19:50:38 +020026
27type
28
29{$IF CompilerVersion < 21.0}
30 TArray<T> = array of T;
31{$IFEND}
32
Jens Geyer8f7487e2019-05-09 22:21:32 +020033 IThriftContainer = interface( ISupportsToString)
34 ['{E05C0F9D-A4F5-491D-AADA-C926B4BDB6E4}']
Jens Geyerd5436f52014-10-03 19:50:38 +020035 end;
36
Jens Geyer8f7487e2019-05-09 22:21:32 +020037
Jens Geyerd5436f52014-10-03 19:50:38 +020038 IThriftDictionary<TKey,TValue> = interface(IThriftContainer)
39 ['{25EDD506-F9D1-4008-A40F-5940364B7E46}']
40 function GetEnumerator: TEnumerator<TPair<TKey,TValue>>;
41
42 function GetKeys: TDictionary<TKey,TValue>.TKeyCollection;
43 function GetValues: TDictionary<TKey,TValue>.TValueCollection;
44 function GetItem(const Key: TKey): TValue;
45 procedure SetItem(const Key: TKey; const Value: TValue);
46 function GetCount: Integer;
47
48 procedure Add(const Key: TKey; const Value: TValue);
49 procedure Remove(const Key: TKey);
50{$IF CompilerVersion >= 21.0}
51 function ExtractPair(const Key: TKey): TPair<TKey,TValue>;
52{$IFEND}
53 procedure Clear;
54 procedure TrimExcess;
55 function TryGetValue(const Key: TKey; out Value: TValue): Boolean;
56 procedure AddOrSetValue(const Key: TKey; const Value: TValue);
57 function ContainsKey(const Key: TKey): Boolean;
58 function ContainsValue(const Value: TValue): Boolean;
59 function ToArray: TArray<TPair<TKey,TValue>>;
60
61 property Items[const Key: TKey]: TValue read GetItem write SetItem; default;
62 property Count: Integer read GetCount;
63 property Keys: TDictionary<TKey,TValue>.TKeyCollection read GetKeys;
64 property Values: TDictionary<TKey,TValue>.TValueCollection read GetValues;
65 end;
66
Jens Geyer8f7487e2019-05-09 22:21:32 +020067 TThriftDictionaryImpl<TKey,TValue> = class( TInterfacedObject, IThriftDictionary<TKey,TValue>, IThriftContainer, ISupportsToString)
Jens Geyerfad7fd32019-11-09 23:24:52 +010068 strict private
Jens Geyerd5436f52014-10-03 19:50:38 +020069 FDictionaly : TDictionary<TKey,TValue>;
Jens Geyerfad7fd32019-11-09 23:24:52 +010070 strict protected
Jens Geyerd5436f52014-10-03 19:50:38 +020071 function GetEnumerator: TEnumerator<TPair<TKey,TValue>>;
72
73 function GetKeys: TDictionary<TKey,TValue>.TKeyCollection;
74 function GetValues: TDictionary<TKey,TValue>.TValueCollection;
75 function GetItem(const Key: TKey): TValue;
76 procedure SetItem(const Key: TKey; const Value: TValue);
77 function GetCount: Integer;
78
79 procedure Add(const Key: TKey; const Value: TValue);
80 procedure Remove(const Key: TKey);
81{$IF CompilerVersion >= 21.0}
82 function ExtractPair(const Key: TKey): TPair<TKey,TValue>;
83{$IFEND}
84 procedure Clear;
85 procedure TrimExcess;
86 function TryGetValue(const Key: TKey; out Value: TValue): Boolean;
87 procedure AddOrSetValue(const Key: TKey; const Value: TValue);
88 function ContainsKey(const Key: TKey): Boolean;
89 function ContainsValue(const Value: TValue): Boolean;
90 function ToArray: TArray<TPair<TKey,TValue>>;
91 property Items[const Key: TKey]: TValue read GetItem write SetItem; default;
92 property Count: Integer read GetCount;
93 property Keys: TDictionary<TKey,TValue>.TKeyCollection read GetKeys;
94 property Values: TDictionary<TKey,TValue>.TValueCollection read GetValues;
95 public
96 constructor Create(ACapacity: Integer = 0);
97 destructor Destroy; override;
Jens Geyer8f7487e2019-05-09 22:21:32 +020098 function ToString : string; override;
Jens Geyerd5436f52014-10-03 19:50:38 +020099 end;
100
101 IThriftList<T> = interface(IThriftContainer)
102 ['{29BEEE31-9CB4-401B-AA04-5148A75F473B}']
103 function GetEnumerator: TEnumerator<T>;
104 function GetCapacity: Integer;
105 procedure SetCapacity(Value: Integer);
106 function GetCount: Integer;
107 procedure SetCount(Value: Integer);
108 function GetItem(Index: Integer): T;
109 procedure SetItem(Index: Integer; const Value: T);
110 function Add(const Value: T): Integer;
111 procedure AddRange(const Values: array of T); overload;
112 procedure AddRange(const Collection: IEnumerable<T>); overload;
113 procedure AddRange(Collection: TEnumerable<T>); overload;
114 procedure Insert(Index: Integer; const Value: T);
115 procedure InsertRange(Index: Integer; const Values: array of T); overload;
116 procedure InsertRange(Index: Integer; const Collection: IEnumerable<T>); overload;
117 procedure InsertRange(Index: Integer; const Collection: TEnumerable<T>); overload;
118 function Remove(const Value: T): Integer;
119 procedure Delete(Index: Integer);
120 procedure DeleteRange(AIndex, ACount: Integer);
121 function Extract(const Value: T): T;
122{$IF CompilerVersion >= 21.0}
123 procedure Exchange(Index1, Index2: Integer);
124 procedure Move(CurIndex, NewIndex: Integer);
125 function First: T;
126 function Last: T;
127{$IFEND}
128 procedure Clear;
129 function Contains(const Value: T): Boolean;
130 function IndexOf(const Value: T): Integer;
131 function LastIndexOf(const Value: T): Integer;
132 procedure Reverse;
133 procedure Sort; overload;
134 procedure Sort(const AComparer: IComparer<T>); overload;
135 function BinarySearch(const Item: T; out Index: Integer): Boolean; overload;
136 function BinarySearch(const Item: T; out Index: Integer; const AComparer: IComparer<T>): Boolean; overload;
137 procedure TrimExcess;
138 function ToArray: TArray<T>;
139 property Capacity: Integer read GetCapacity write SetCapacity;
140 property Count: Integer read GetCount write SetCount;
141 property Items[Index: Integer]: T read GetItem write SetItem; default;
142 end;
143
Jens Geyer8f7487e2019-05-09 22:21:32 +0200144 TThriftListImpl<T> = class( TInterfacedObject, IThriftList<T>, IThriftContainer, ISupportsToString)
Jens Geyerfad7fd32019-11-09 23:24:52 +0100145 strict private
Jens Geyerd5436f52014-10-03 19:50:38 +0200146 FList : TList<T>;
Jens Geyerfad7fd32019-11-09 23:24:52 +0100147 strict protected
Jens Geyerd5436f52014-10-03 19:50:38 +0200148 function GetEnumerator: TEnumerator<T>;
149 function GetCapacity: Integer;
150 procedure SetCapacity(Value: Integer);
151 function GetCount: Integer;
152 procedure SetCount(Value: Integer);
153 function GetItem(Index: Integer): T;
154 procedure SetItem(Index: Integer; const Value: T);
155 function Add(const Value: T): Integer;
156 procedure AddRange(const Values: array of T); overload;
157 procedure AddRange(const Collection: IEnumerable<T>); overload;
158 procedure AddRange(Collection: TEnumerable<T>); overload;
159 procedure Insert(Index: Integer; const Value: T);
160 procedure InsertRange(Index: Integer; const Values: array of T); overload;
161 procedure InsertRange(Index: Integer; const Collection: IEnumerable<T>); overload;
162 procedure InsertRange(Index: Integer; const Collection: TEnumerable<T>); overload;
163 function Remove(const Value: T): Integer;
164 procedure Delete(Index: Integer);
165 procedure DeleteRange(AIndex, ACount: Integer);
166 function Extract(const Value: T): T;
167{$IF CompilerVersion >= 21.0}
168 procedure Exchange(Index1, Index2: Integer);
169 procedure Move(CurIndex, NewIndex: Integer);
170 function First: T;
171 function Last: T;
172{$IFEND}
173 procedure Clear;
174 function Contains(const Value: T): Boolean;
175 function IndexOf(const Value: T): Integer;
176 function LastIndexOf(const Value: T): Integer;
177 procedure Reverse;
178 procedure Sort; overload;
179 procedure Sort(const AComparer: IComparer<T>); overload;
180 function BinarySearch(const Item: T; out Index: Integer): Boolean; overload;
181 function BinarySearch(const Item: T; out Index: Integer; const AComparer: IComparer<T>): Boolean; overload;
182 procedure TrimExcess;
183 function ToArray: TArray<T>;
184 property Capacity: Integer read GetCapacity write SetCapacity;
185 property Count: Integer read GetCount write SetCount;
186 property Items[Index: Integer]: T read GetItem write SetItem; default;
187 public
188 constructor Create;
189 destructor Destroy; override;
Jens Geyer8f7487e2019-05-09 22:21:32 +0200190 function ToString : string; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200191 end;
192
Jens Geyer683263d2022-09-03 18:52:35 +0200193 IThriftHashSet<TValue> = interface(IThriftContainer)
Jens Geyerd5436f52014-10-03 19:50:38 +0200194 ['{0923A3B5-D4D4-48A8-91AD-40238E2EAD66}']
195 function GetEnumerator: TEnumerator<TValue>;
196 function GetIsReadOnly: Boolean;
197 function GetCount: Integer;
198 property Count: Integer read GetCount;
199 property IsReadOnly: Boolean read GetIsReadOnly;
200 procedure Add( const item: TValue);
201 procedure Clear;
202 function Contains( const item: TValue): Boolean;
203 procedure CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
204 function Remove( const item: TValue ): Boolean;
205 end;
206
Jens Geyer683263d2022-09-03 18:52:35 +0200207 // compatibility
208 IHashSet<TValue> = interface( IThriftHashSet<TValue>)
209 ['{C3CF557F-21D9-4524-B899-D3145B0389BB}']
210 end deprecated 'use IThriftHashSet<T>';
211
212
213 {$WARN SYMBOL_DEPRECATED OFF}
214 TThriftHashSetImpl<TValue> = class( TInterfacedObject, IHashSet<TValue>, IThriftHashSet<TValue>, IThriftContainer, ISupportsToString)
215 {$WARN SYMBOL_DEPRECATED DEFAULT}
Jens Geyerfad7fd32019-11-09 23:24:52 +0100216 strict private
Jens Geyerd5436f52014-10-03 19:50:38 +0200217 FDictionary : IThriftDictionary<TValue,Integer>;
218 FIsReadOnly: Boolean;
Jens Geyerfad7fd32019-11-09 23:24:52 +0100219 strict protected
Jens Geyerd5436f52014-10-03 19:50:38 +0200220 function GetEnumerator: TEnumerator<TValue>;
221 function GetIsReadOnly: Boolean;
222 function GetCount: Integer;
223 property Count: Integer read GetCount;
224 property IsReadOnly: Boolean read FIsReadOnly;
225 procedure Add( const item: TValue);
226 procedure Clear;
227 function Contains( const item: TValue): Boolean;
228 procedure CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
229 function Remove( const item: TValue ): Boolean;
230 public
231 constructor Create;
Jens Geyer8f7487e2019-05-09 22:21:32 +0200232 function ToString : string; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200233 end;
234
Jens Geyer683263d2022-09-03 18:52:35 +0200235 // compatibility
236 THashSetImpl<TValue> = class( TThriftHashSetImpl<TValue>)
237 end deprecated 'use TThriftHashSetImpl<T>';
238
Jens Geyerd5436f52014-10-03 19:50:38 +0200239implementation
240
Jens Geyer683263d2022-09-03 18:52:35 +0200241{ TThriftHashSetImpl<TValue>. }
Jens Geyerd5436f52014-10-03 19:50:38 +0200242
Jens Geyer683263d2022-09-03 18:52:35 +0200243procedure TThriftHashSetImpl<TValue>.Add( const item: TValue);
Jens Geyerd5436f52014-10-03 19:50:38 +0200244begin
245 if not FDictionary.ContainsKey(item) then
246 begin
247 FDictionary.Add( item, 0);
248 end;
249end;
250
Jens Geyer683263d2022-09-03 18:52:35 +0200251procedure TThriftHashSetImpl<TValue>.Clear;
Jens Geyerd5436f52014-10-03 19:50:38 +0200252begin
253 FDictionary.Clear;
254end;
255
Jens Geyer683263d2022-09-03 18:52:35 +0200256function TThriftHashSetImpl<TValue>.Contains( const item: TValue): Boolean;
Jens Geyerd5436f52014-10-03 19:50:38 +0200257begin
258 Result := FDictionary.ContainsKey(item);
259end;
260
Jens Geyer683263d2022-09-03 18:52:35 +0200261procedure TThriftHashSetImpl<TValue>.CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
Jens Geyerd5436f52014-10-03 19:50:38 +0200262var
263 i : Integer;
264 Enumlator : TEnumerator<TValue>;
265begin
266 Enumlator := GetEnumerator;
267 while Enumlator.MoveNext do
268 begin
269 A[arrayIndex] := Enumlator.Current;
270 Inc(arrayIndex);
271 end;
272end;
273
Jens Geyer683263d2022-09-03 18:52:35 +0200274constructor TThriftHashSetImpl<TValue>.Create;
Jens Geyerd5436f52014-10-03 19:50:38 +0200275begin
276 inherited;
277 FDictionary := TThriftDictionaryImpl<TValue,Integer>.Create;
278end;
279
Jens Geyer683263d2022-09-03 18:52:35 +0200280function TThriftHashSetImpl<TValue>.GetCount: Integer;
Jens Geyerd5436f52014-10-03 19:50:38 +0200281begin
282 Result := FDictionary.Count;
283end;
284
Jens Geyer683263d2022-09-03 18:52:35 +0200285function TThriftHashSetImpl<TValue>.GetEnumerator: TEnumerator<TValue>;
Jens Geyerd5436f52014-10-03 19:50:38 +0200286begin
287 Result := FDictionary.Keys.GetEnumerator;
288end;
289
Jens Geyer683263d2022-09-03 18:52:35 +0200290function TThriftHashSetImpl<TValue>.GetIsReadOnly: Boolean;
Jens Geyerd5436f52014-10-03 19:50:38 +0200291begin
292 Result := FIsReadOnly;
293end;
294
Jens Geyer683263d2022-09-03 18:52:35 +0200295function TThriftHashSetImpl<TValue>.Remove( const item: TValue): Boolean;
Jens Geyerd5436f52014-10-03 19:50:38 +0200296begin
297 Result := False;
298 if FDictionary.ContainsKey( item ) then
299 begin
300 FDictionary.Remove( item );
301 Result := not FDictionary.ContainsKey( item );
302 end;
303end;
304
Jens Geyer683263d2022-09-03 18:52:35 +0200305function TThriftHashSetImpl<TValue>.ToString : string;
Jens Geyer8f7487e2019-05-09 22:21:32 +0200306var elm : TValue;
307 sb : TThriftStringBuilder;
308 first : Boolean;
309begin
310 sb := TThriftStringBuilder.Create('{');
311 try
312 first := TRUE;
313 for elm in FDictionary.Keys do begin
314 if first
315 then first := FALSE
316 else sb.Append(', ');
317
318 sb.Append( StringUtils<TValue>.ToString(elm));
319 end;
320 sb.Append('}');
321 Result := sb.ToString;
322 finally
323 sb.Free;
324 end;
325end;
326
Jens Geyerd5436f52014-10-03 19:50:38 +0200327{ TThriftDictionaryImpl<TKey, TValue> }
328
329procedure TThriftDictionaryImpl<TKey, TValue>.Add(const Key: TKey;
330 const Value: TValue);
331begin
332 FDictionaly.Add( Key, Value);
333end;
334
335procedure TThriftDictionaryImpl<TKey, TValue>.AddOrSetValue(const Key: TKey;
336 const Value: TValue);
337begin
338 FDictionaly.AddOrSetValue( Key, Value);
339end;
340
341procedure TThriftDictionaryImpl<TKey, TValue>.Clear;
342begin
343 FDictionaly.Clear;
344end;
345
346function TThriftDictionaryImpl<TKey, TValue>.ContainsKey(
347 const Key: TKey): Boolean;
348begin
349 Result := FDictionaly.ContainsKey( Key );
350end;
351
352function TThriftDictionaryImpl<TKey, TValue>.ContainsValue(
353 const Value: TValue): Boolean;
354begin
355 Result := FDictionaly.ContainsValue( Value );
356end;
357
358constructor TThriftDictionaryImpl<TKey, TValue>.Create(ACapacity: Integer);
359begin
360 inherited Create;
361 FDictionaly := TDictionary<TKey,TValue>.Create( ACapacity );
362end;
363
364destructor TThriftDictionaryImpl<TKey, TValue>.Destroy;
365begin
366 FDictionaly.Free;
367 inherited;
368end;
369
370{$IF CompilerVersion >= 21.0}
371function TThriftDictionaryImpl<TKey, TValue>.ExtractPair( const Key: TKey): TPair<TKey, TValue>;
372begin
373 Result := FDictionaly.ExtractPair( Key);
374end;
375{$IFEND}
376
377function TThriftDictionaryImpl<TKey, TValue>.GetCount: Integer;
378begin
379 Result := FDictionaly.Count;
380end;
381
382function TThriftDictionaryImpl<TKey, TValue>.GetEnumerator: TEnumerator<TPair<TKey, TValue>>;
383begin
384 Result := FDictionaly.GetEnumerator;
385end;
386
387function TThriftDictionaryImpl<TKey, TValue>.GetItem(const Key: TKey): TValue;
388begin
389 Result := FDictionaly.Items[Key];
390end;
391
392function TThriftDictionaryImpl<TKey, TValue>.GetKeys: TDictionary<TKey, TValue>.TKeyCollection;
393begin
394 Result := FDictionaly.Keys;
395end;
396
397function TThriftDictionaryImpl<TKey, TValue>.GetValues: TDictionary<TKey, TValue>.TValueCollection;
398begin
399 Result := FDictionaly.Values;
400end;
401
402procedure TThriftDictionaryImpl<TKey, TValue>.Remove(const Key: TKey);
403begin
404 FDictionaly.Remove( Key );
405end;
406
407procedure TThriftDictionaryImpl<TKey, TValue>.SetItem(const Key: TKey;
408 const Value: TValue);
409begin
410 FDictionaly.AddOrSetValue( Key, Value);
411end;
412
413function TThriftDictionaryImpl<TKey, TValue>.ToArray: TArray<TPair<TKey, TValue>>;
414{$IF CompilerVersion < 22.0}
415var
416 x : TPair<TKey, TValue>;
417 i : Integer;
418{$IFEND}
419begin
420{$IF CompilerVersion < 22.0}
421 SetLength(Result, Count);
422 i := 0;
423 for x in FDictionaly do
424 begin
425 Result[i] := x;
426 Inc( i );
427 end;
428{$ELSE}
429 Result := FDictionaly.ToArray;
430{$IFEND}
431end;
432
Jens Geyer8f7487e2019-05-09 22:21:32 +0200433function TThriftDictionaryImpl<TKey, TValue>.ToString : string;
434var pair : TPair<TKey, TValue>;
435 sb : TThriftStringBuilder;
436 first : Boolean;
437begin
438 sb := TThriftStringBuilder.Create('{');
439 try
440 first := TRUE;
441 for pair in FDictionaly do begin
442 if first
443 then first := FALSE
444 else sb.Append(', ');
445
446 sb.Append( '(');
447 sb.Append( StringUtils<TKey>.ToString(pair.Key));
448 sb.Append(' => ');
449 sb.Append( StringUtils<TValue>.ToString(pair.Value));
450 sb.Append(')');
451 end;
452 sb.Append('}');
453 Result := sb.ToString;
454 finally
455 sb.Free;
456 end;
457end;
458
Jens Geyerd5436f52014-10-03 19:50:38 +0200459procedure TThriftDictionaryImpl<TKey, TValue>.TrimExcess;
460begin
461 FDictionaly.TrimExcess;
462end;
463
464function TThriftDictionaryImpl<TKey, TValue>.TryGetValue(const Key: TKey;
465 out Value: TValue): Boolean;
466begin
467 Result := FDictionaly.TryGetValue( Key, Value);
468end;
469
470{ TThriftListImpl<T> }
471
472function TThriftListImpl<T>.Add(const Value: T): Integer;
473begin
474 Result := FList.Add( Value );
475end;
476
477procedure TThriftListImpl<T>.AddRange(Collection: TEnumerable<T>);
478begin
479 FList.AddRange( Collection );
480end;
481
482procedure TThriftListImpl<T>.AddRange(const Collection: IEnumerable<T>);
483begin
484 FList.AddRange( Collection );
485end;
486
487procedure TThriftListImpl<T>.AddRange(const Values: array of T);
488begin
489 FList.AddRange( Values );
490end;
491
492function TThriftListImpl<T>.BinarySearch(const Item: T;
493 out Index: Integer): Boolean;
494begin
495 Result := FList.BinarySearch( Item, Index);
496end;
497
498function TThriftListImpl<T>.BinarySearch(const Item: T; out Index: Integer;
499 const AComparer: IComparer<T>): Boolean;
500begin
501 Result := FList.BinarySearch( Item, Index, AComparer);
502end;
503
504procedure TThriftListImpl<T>.Clear;
505begin
506 FList.Clear;
507end;
508
509function TThriftListImpl<T>.Contains(const Value: T): Boolean;
510begin
511 Result := FList.Contains( Value );
512end;
513
514constructor TThriftListImpl<T>.Create;
515begin
516 inherited;
517 FList := TList<T>.Create;
518end;
519
520procedure TThriftListImpl<T>.Delete(Index: Integer);
521begin
522 FList.Delete( Index )
523end;
524
525procedure TThriftListImpl<T>.DeleteRange(AIndex, ACount: Integer);
526begin
527 FList.DeleteRange( AIndex, ACount)
528end;
529
530destructor TThriftListImpl<T>.Destroy;
531begin
532 FList.Free;
533 inherited;
534end;
535
536{$IF CompilerVersion >= 21.0}
537procedure TThriftListImpl<T>.Exchange(Index1, Index2: Integer);
538begin
539 FList.Exchange( Index1, Index2 )
540end;
541{$IFEND}
542
543function TThriftListImpl<T>.Extract(const Value: T): T;
544begin
545 Result := FList.Extract( Value )
546end;
547
548{$IF CompilerVersion >= 21.0}
549function TThriftListImpl<T>.First: T;
550begin
551 Result := FList.First;
552end;
553{$IFEND}
554
555function TThriftListImpl<T>.GetCapacity: Integer;
556begin
557 Result := FList.Capacity;
558end;
559
560function TThriftListImpl<T>.GetCount: Integer;
561begin
562 Result := FList.Count;
563end;
564
565function TThriftListImpl<T>.GetEnumerator: TEnumerator<T>;
566begin
567 Result := FList.GetEnumerator;
568end;
569
570function TThriftListImpl<T>.GetItem(Index: Integer): T;
571begin
572 Result := FList[Index];
573end;
574
575function TThriftListImpl<T>.IndexOf(const Value: T): Integer;
576begin
577 Result := FList.IndexOf( Value );
578end;
579
580procedure TThriftListImpl<T>.Insert(Index: Integer; const Value: T);
581begin
582 FList.Insert( Index, Value);
583end;
584
585procedure TThriftListImpl<T>.InsertRange(Index: Integer;
586 const Collection: TEnumerable<T>);
587begin
588 FList.InsertRange( Index, Collection );
589end;
590
591procedure TThriftListImpl<T>.InsertRange(Index: Integer;
592 const Values: array of T);
593begin
594 FList.InsertRange( Index, Values);
595end;
596
597procedure TThriftListImpl<T>.InsertRange(Index: Integer;
598 const Collection: IEnumerable<T>);
599begin
600 FList.InsertRange( Index, Collection );
601end;
602
603{$IF CompilerVersion >= 21.0}
604function TThriftListImpl<T>.Last: T;
605begin
606 Result := FList.Last;
607end;
608{$IFEND}
609
610function TThriftListImpl<T>.LastIndexOf(const Value: T): Integer;
611begin
612 Result := FList.LastIndexOf( Value );
613end;
614
615{$IF CompilerVersion >= 21.0}
616procedure TThriftListImpl<T>.Move(CurIndex, NewIndex: Integer);
617begin
618 FList.Move( CurIndex, NewIndex);
619end;
620{$IFEND}
621
622function TThriftListImpl<T>.Remove(const Value: T): Integer;
623begin
624 Result := FList.Remove( Value );
625end;
626
627procedure TThriftListImpl<T>.Reverse;
628begin
629 FList.Reverse;
630end;
631
632procedure TThriftListImpl<T>.SetCapacity(Value: Integer);
633begin
634 FList.Capacity := Value;
635end;
636
637procedure TThriftListImpl<T>.SetCount(Value: Integer);
638begin
639 FList.Count := Value;
640end;
641
642procedure TThriftListImpl<T>.SetItem(Index: Integer; const Value: T);
643begin
644 FList[Index] := Value;
645end;
646
647procedure TThriftListImpl<T>.Sort;
648begin
649 FList.Sort;
650end;
651
652procedure TThriftListImpl<T>.Sort(const AComparer: IComparer<T>);
653begin
Alex-Rud693e19c2019-07-30 14:51:56 +0300654 FList.Sort(AComparer);
Jens Geyerd5436f52014-10-03 19:50:38 +0200655end;
656
657function TThriftListImpl<T>.ToArray: TArray<T>;
658{$IF CompilerVersion < 22.0}
659var
660 x : T;
661 i : Integer;
662{$IFEND}
663begin
664{$IF CompilerVersion < 22.0}
665 SetLength(Result, Count);
666 i := 0;
667 for x in FList do
668 begin
669 Result[i] := x;
670 Inc( i );
671 end;
672{$ELSE}
673 Result := FList.ToArray;
674{$IFEND}
675end;
676
Jens Geyer8f7487e2019-05-09 22:21:32 +0200677function TThriftListImpl<T>.ToString : string;
678var elm : T;
679 sb : TThriftStringBuilder;
680 first : Boolean;
681begin
682 sb := TThriftStringBuilder.Create('{');
683 try
684 first := TRUE;
685 for elm in FList do begin
686 if first
687 then first := FALSE
688 else sb.Append(', ');
689
690 sb.Append( StringUtils<T>.ToString(elm));
691 end;
692 sb.Append('}');
693 Result := sb.ToString;
694 finally
695 sb.Free;
696 end;
697end;
698
Jens Geyerd5436f52014-10-03 19:50:38 +0200699procedure TThriftListImpl<T>.TrimExcess;
700begin
701 FList.TrimExcess;
702end;
703
704end.