blob: ad852accaa8398f03f5c7766f4de6b48c6c64766 [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
193 IHashSet<TValue> = interface(IThriftContainer)
194 ['{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 Geyer8f7487e2019-05-09 22:21:32 +0200207 THashSetImpl<TValue> = class( TInterfacedObject, IHashSet<TValue>, IThriftContainer, ISupportsToString)
Jens Geyerfad7fd32019-11-09 23:24:52 +0100208 strict private
Jens Geyerd5436f52014-10-03 19:50:38 +0200209 FDictionary : IThriftDictionary<TValue,Integer>;
210 FIsReadOnly: Boolean;
Jens Geyerfad7fd32019-11-09 23:24:52 +0100211 strict protected
Jens Geyerd5436f52014-10-03 19:50:38 +0200212 function GetEnumerator: TEnumerator<TValue>;
213 function GetIsReadOnly: Boolean;
214 function GetCount: Integer;
215 property Count: Integer read GetCount;
216 property IsReadOnly: Boolean read FIsReadOnly;
217 procedure Add( const item: TValue);
218 procedure Clear;
219 function Contains( const item: TValue): Boolean;
220 procedure CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
221 function Remove( const item: TValue ): Boolean;
222 public
223 constructor Create;
Jens Geyer8f7487e2019-05-09 22:21:32 +0200224 function ToString : string; override;
Jens Geyerd5436f52014-10-03 19:50:38 +0200225 end;
226
227implementation
228
229{ THashSetImpl<TValue> }
230
231procedure THashSetImpl<TValue>.Add( const item: TValue);
232begin
233 if not FDictionary.ContainsKey(item) then
234 begin
235 FDictionary.Add( item, 0);
236 end;
237end;
238
239procedure THashSetImpl<TValue>.Clear;
240begin
241 FDictionary.Clear;
242end;
243
244function THashSetImpl<TValue>.Contains( const item: TValue): Boolean;
245begin
246 Result := FDictionary.ContainsKey(item);
247end;
248
249procedure THashSetImpl<TValue>.CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
250var
251 i : Integer;
252 Enumlator : TEnumerator<TValue>;
253begin
254 Enumlator := GetEnumerator;
255 while Enumlator.MoveNext do
256 begin
257 A[arrayIndex] := Enumlator.Current;
258 Inc(arrayIndex);
259 end;
260end;
261
262constructor THashSetImpl<TValue>.Create;
263begin
264 inherited;
265 FDictionary := TThriftDictionaryImpl<TValue,Integer>.Create;
266end;
267
268function THashSetImpl<TValue>.GetCount: Integer;
269begin
270 Result := FDictionary.Count;
271end;
272
273function THashSetImpl<TValue>.GetEnumerator: TEnumerator<TValue>;
274begin
275 Result := FDictionary.Keys.GetEnumerator;
276end;
277
278function THashSetImpl<TValue>.GetIsReadOnly: Boolean;
279begin
280 Result := FIsReadOnly;
281end;
282
283function THashSetImpl<TValue>.Remove( const item: TValue): Boolean;
284begin
285 Result := False;
286 if FDictionary.ContainsKey( item ) then
287 begin
288 FDictionary.Remove( item );
289 Result := not FDictionary.ContainsKey( item );
290 end;
291end;
292
Jens Geyer8f7487e2019-05-09 22:21:32 +0200293function THashSetImpl<TValue>.ToString : string;
294var elm : TValue;
295 sb : TThriftStringBuilder;
296 first : Boolean;
297begin
298 sb := TThriftStringBuilder.Create('{');
299 try
300 first := TRUE;
301 for elm in FDictionary.Keys do begin
302 if first
303 then first := FALSE
304 else sb.Append(', ');
305
306 sb.Append( StringUtils<TValue>.ToString(elm));
307 end;
308 sb.Append('}');
309 Result := sb.ToString;
310 finally
311 sb.Free;
312 end;
313end;
314
Jens Geyerd5436f52014-10-03 19:50:38 +0200315{ TThriftDictionaryImpl<TKey, TValue> }
316
317procedure TThriftDictionaryImpl<TKey, TValue>.Add(const Key: TKey;
318 const Value: TValue);
319begin
320 FDictionaly.Add( Key, Value);
321end;
322
323procedure TThriftDictionaryImpl<TKey, TValue>.AddOrSetValue(const Key: TKey;
324 const Value: TValue);
325begin
326 FDictionaly.AddOrSetValue( Key, Value);
327end;
328
329procedure TThriftDictionaryImpl<TKey, TValue>.Clear;
330begin
331 FDictionaly.Clear;
332end;
333
334function TThriftDictionaryImpl<TKey, TValue>.ContainsKey(
335 const Key: TKey): Boolean;
336begin
337 Result := FDictionaly.ContainsKey( Key );
338end;
339
340function TThriftDictionaryImpl<TKey, TValue>.ContainsValue(
341 const Value: TValue): Boolean;
342begin
343 Result := FDictionaly.ContainsValue( Value );
344end;
345
346constructor TThriftDictionaryImpl<TKey, TValue>.Create(ACapacity: Integer);
347begin
348 inherited Create;
349 FDictionaly := TDictionary<TKey,TValue>.Create( ACapacity );
350end;
351
352destructor TThriftDictionaryImpl<TKey, TValue>.Destroy;
353begin
354 FDictionaly.Free;
355 inherited;
356end;
357
358{$IF CompilerVersion >= 21.0}
359function TThriftDictionaryImpl<TKey, TValue>.ExtractPair( const Key: TKey): TPair<TKey, TValue>;
360begin
361 Result := FDictionaly.ExtractPair( Key);
362end;
363{$IFEND}
364
365function TThriftDictionaryImpl<TKey, TValue>.GetCount: Integer;
366begin
367 Result := FDictionaly.Count;
368end;
369
370function TThriftDictionaryImpl<TKey, TValue>.GetEnumerator: TEnumerator<TPair<TKey, TValue>>;
371begin
372 Result := FDictionaly.GetEnumerator;
373end;
374
375function TThriftDictionaryImpl<TKey, TValue>.GetItem(const Key: TKey): TValue;
376begin
377 Result := FDictionaly.Items[Key];
378end;
379
380function TThriftDictionaryImpl<TKey, TValue>.GetKeys: TDictionary<TKey, TValue>.TKeyCollection;
381begin
382 Result := FDictionaly.Keys;
383end;
384
385function TThriftDictionaryImpl<TKey, TValue>.GetValues: TDictionary<TKey, TValue>.TValueCollection;
386begin
387 Result := FDictionaly.Values;
388end;
389
390procedure TThriftDictionaryImpl<TKey, TValue>.Remove(const Key: TKey);
391begin
392 FDictionaly.Remove( Key );
393end;
394
395procedure TThriftDictionaryImpl<TKey, TValue>.SetItem(const Key: TKey;
396 const Value: TValue);
397begin
398 FDictionaly.AddOrSetValue( Key, Value);
399end;
400
401function TThriftDictionaryImpl<TKey, TValue>.ToArray: TArray<TPair<TKey, TValue>>;
402{$IF CompilerVersion < 22.0}
403var
404 x : TPair<TKey, TValue>;
405 i : Integer;
406{$IFEND}
407begin
408{$IF CompilerVersion < 22.0}
409 SetLength(Result, Count);
410 i := 0;
411 for x in FDictionaly do
412 begin
413 Result[i] := x;
414 Inc( i );
415 end;
416{$ELSE}
417 Result := FDictionaly.ToArray;
418{$IFEND}
419end;
420
Jens Geyer8f7487e2019-05-09 22:21:32 +0200421function TThriftDictionaryImpl<TKey, TValue>.ToString : string;
422var pair : TPair<TKey, TValue>;
423 sb : TThriftStringBuilder;
424 first : Boolean;
425begin
426 sb := TThriftStringBuilder.Create('{');
427 try
428 first := TRUE;
429 for pair in FDictionaly do begin
430 if first
431 then first := FALSE
432 else sb.Append(', ');
433
434 sb.Append( '(');
435 sb.Append( StringUtils<TKey>.ToString(pair.Key));
436 sb.Append(' => ');
437 sb.Append( StringUtils<TValue>.ToString(pair.Value));
438 sb.Append(')');
439 end;
440 sb.Append('}');
441 Result := sb.ToString;
442 finally
443 sb.Free;
444 end;
445end;
446
Jens Geyerd5436f52014-10-03 19:50:38 +0200447procedure TThriftDictionaryImpl<TKey, TValue>.TrimExcess;
448begin
449 FDictionaly.TrimExcess;
450end;
451
452function TThriftDictionaryImpl<TKey, TValue>.TryGetValue(const Key: TKey;
453 out Value: TValue): Boolean;
454begin
455 Result := FDictionaly.TryGetValue( Key, Value);
456end;
457
458{ TThriftListImpl<T> }
459
460function TThriftListImpl<T>.Add(const Value: T): Integer;
461begin
462 Result := FList.Add( Value );
463end;
464
465procedure TThriftListImpl<T>.AddRange(Collection: TEnumerable<T>);
466begin
467 FList.AddRange( Collection );
468end;
469
470procedure TThriftListImpl<T>.AddRange(const Collection: IEnumerable<T>);
471begin
472 FList.AddRange( Collection );
473end;
474
475procedure TThriftListImpl<T>.AddRange(const Values: array of T);
476begin
477 FList.AddRange( Values );
478end;
479
480function TThriftListImpl<T>.BinarySearch(const Item: T;
481 out Index: Integer): Boolean;
482begin
483 Result := FList.BinarySearch( Item, Index);
484end;
485
486function TThriftListImpl<T>.BinarySearch(const Item: T; out Index: Integer;
487 const AComparer: IComparer<T>): Boolean;
488begin
489 Result := FList.BinarySearch( Item, Index, AComparer);
490end;
491
492procedure TThriftListImpl<T>.Clear;
493begin
494 FList.Clear;
495end;
496
497function TThriftListImpl<T>.Contains(const Value: T): Boolean;
498begin
499 Result := FList.Contains( Value );
500end;
501
502constructor TThriftListImpl<T>.Create;
503begin
504 inherited;
505 FList := TList<T>.Create;
506end;
507
508procedure TThriftListImpl<T>.Delete(Index: Integer);
509begin
510 FList.Delete( Index )
511end;
512
513procedure TThriftListImpl<T>.DeleteRange(AIndex, ACount: Integer);
514begin
515 FList.DeleteRange( AIndex, ACount)
516end;
517
518destructor TThriftListImpl<T>.Destroy;
519begin
520 FList.Free;
521 inherited;
522end;
523
524{$IF CompilerVersion >= 21.0}
525procedure TThriftListImpl<T>.Exchange(Index1, Index2: Integer);
526begin
527 FList.Exchange( Index1, Index2 )
528end;
529{$IFEND}
530
531function TThriftListImpl<T>.Extract(const Value: T): T;
532begin
533 Result := FList.Extract( Value )
534end;
535
536{$IF CompilerVersion >= 21.0}
537function TThriftListImpl<T>.First: T;
538begin
539 Result := FList.First;
540end;
541{$IFEND}
542
543function TThriftListImpl<T>.GetCapacity: Integer;
544begin
545 Result := FList.Capacity;
546end;
547
548function TThriftListImpl<T>.GetCount: Integer;
549begin
550 Result := FList.Count;
551end;
552
553function TThriftListImpl<T>.GetEnumerator: TEnumerator<T>;
554begin
555 Result := FList.GetEnumerator;
556end;
557
558function TThriftListImpl<T>.GetItem(Index: Integer): T;
559begin
560 Result := FList[Index];
561end;
562
563function TThriftListImpl<T>.IndexOf(const Value: T): Integer;
564begin
565 Result := FList.IndexOf( Value );
566end;
567
568procedure TThriftListImpl<T>.Insert(Index: Integer; const Value: T);
569begin
570 FList.Insert( Index, Value);
571end;
572
573procedure TThriftListImpl<T>.InsertRange(Index: Integer;
574 const Collection: TEnumerable<T>);
575begin
576 FList.InsertRange( Index, Collection );
577end;
578
579procedure TThriftListImpl<T>.InsertRange(Index: Integer;
580 const Values: array of T);
581begin
582 FList.InsertRange( Index, Values);
583end;
584
585procedure TThriftListImpl<T>.InsertRange(Index: Integer;
586 const Collection: IEnumerable<T>);
587begin
588 FList.InsertRange( Index, Collection );
589end;
590
591{$IF CompilerVersion >= 21.0}
592function TThriftListImpl<T>.Last: T;
593begin
594 Result := FList.Last;
595end;
596{$IFEND}
597
598function TThriftListImpl<T>.LastIndexOf(const Value: T): Integer;
599begin
600 Result := FList.LastIndexOf( Value );
601end;
602
603{$IF CompilerVersion >= 21.0}
604procedure TThriftListImpl<T>.Move(CurIndex, NewIndex: Integer);
605begin
606 FList.Move( CurIndex, NewIndex);
607end;
608{$IFEND}
609
610function TThriftListImpl<T>.Remove(const Value: T): Integer;
611begin
612 Result := FList.Remove( Value );
613end;
614
615procedure TThriftListImpl<T>.Reverse;
616begin
617 FList.Reverse;
618end;
619
620procedure TThriftListImpl<T>.SetCapacity(Value: Integer);
621begin
622 FList.Capacity := Value;
623end;
624
625procedure TThriftListImpl<T>.SetCount(Value: Integer);
626begin
627 FList.Count := Value;
628end;
629
630procedure TThriftListImpl<T>.SetItem(Index: Integer; const Value: T);
631begin
632 FList[Index] := Value;
633end;
634
635procedure TThriftListImpl<T>.Sort;
636begin
637 FList.Sort;
638end;
639
640procedure TThriftListImpl<T>.Sort(const AComparer: IComparer<T>);
641begin
Alex-Rud693e19c2019-07-30 14:51:56 +0300642 FList.Sort(AComparer);
Jens Geyerd5436f52014-10-03 19:50:38 +0200643end;
644
645function TThriftListImpl<T>.ToArray: TArray<T>;
646{$IF CompilerVersion < 22.0}
647var
648 x : T;
649 i : Integer;
650{$IFEND}
651begin
652{$IF CompilerVersion < 22.0}
653 SetLength(Result, Count);
654 i := 0;
655 for x in FList do
656 begin
657 Result[i] := x;
658 Inc( i );
659 end;
660{$ELSE}
661 Result := FList.ToArray;
662{$IFEND}
663end;
664
Jens Geyer8f7487e2019-05-09 22:21:32 +0200665function TThriftListImpl<T>.ToString : string;
666var elm : T;
667 sb : TThriftStringBuilder;
668 first : Boolean;
669begin
670 sb := TThriftStringBuilder.Create('{');
671 try
672 first := TRUE;
673 for elm in FList do begin
674 if first
675 then first := FALSE
676 else sb.Append(', ');
677
678 sb.Append( StringUtils<T>.ToString(elm));
679 end;
680 sb.Append('}');
681 Result := sb.ToString;
682 finally
683 sb.Free;
684 end;
685end;
686
Jens Geyerd5436f52014-10-03 19:50:38 +0200687procedure TThriftListImpl<T>.TrimExcess;
688begin
689 FList.TrimExcess;
690end;
691
692end.