33ae5afbf0cea2c92ff2f1920c5e69f5b993331c
[platform/framework/native/appfw.git] / src / base / collection / FBaseColArrayList.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                FBaseColArrayList.cpp
19  * @brief               This is the implementation for ArrayList class.
20  */
21
22 #include <new>
23 #include <unique_ptr.h>
24
25 #include <FBaseColArrayList.h>
26 #include <FBaseResult.h>
27 #include <FBaseSysLog.h>
28
29
30 namespace Tizen { namespace Base { namespace Collection
31 {
32
33 /**
34  * @class       _ArrayListEnumerator
35  * @brief       This is an implementation of IEnumerator for ArrayList.
36  */
37 class _ArrayListEnumerator
38         : public IBidirectionalEnumerator
39         , public Object
40 {
41 public:
42         _ArrayListEnumerator(const ArrayList& list, int modCount);
43         virtual ~_ArrayListEnumerator(void);
44
45         virtual Object* GetCurrent(void) const;
46         virtual result MoveNext(void);
47         virtual result Reset(void);
48
49         virtual result MovePrevious();
50         virtual result ResetLast();
51
52 private:
53         const ArrayList& __list;
54         int __modCount;
55         int __position;
56 };
57
58 _ArrayListEnumerator::_ArrayListEnumerator(const ArrayList& list, int modCount)
59         : __list(list)
60         , __modCount(modCount)
61         , __position(-1)
62 {
63 }
64
65 _ArrayListEnumerator::~_ArrayListEnumerator(void)
66 {
67 }
68
69 Object*
70 _ArrayListEnumerator::GetCurrent(void) const
71 {
72         SysTryReturn(NID_BASE_COL, (__modCount == __list.__modCount), null, E_INVALID_OPERATION, "[%s] The source collection was modified after the creation of this enumerator.", GetErrorMessage(E_INVALID_OPERATION));
73         SysTryReturn(NID_BASE_COL, ((__position >= 0) && (__position < __list.__count)), null, E_INVALID_OPERATION, "[%s] Current position(%d) is before the first element or past the last element.", GetErrorMessage(E_INVALID_OPERATION), __position);
74
75         SetLastResult(E_SUCCESS);
76
77         return __list.__pObjArray[__position];
78 }
79
80 result
81 _ArrayListEnumerator::MoveNext(void)
82 {
83         SysTryReturnResult(NID_BASE_COL, (__modCount == __list.__modCount), E_INVALID_OPERATION, "The source collection was modified after the creation of this enumerator.");
84
85         if ((__position + 1) >= static_cast< int >(__list.__count))
86         {
87                 return E_OUT_OF_RANGE;
88         }
89         else
90         {
91                 __position++;
92         }
93
94         return E_SUCCESS;
95 }
96
97 result
98 _ArrayListEnumerator::Reset(void)
99 {
100         SysTryReturnResult(NID_BASE_COL, (__modCount == __list.__modCount), E_INVALID_OPERATION, "The source collection was modified after the creation of this enumerator.");
101
102         __position = -1;
103         return E_SUCCESS;
104 }
105
106
107 result
108 _ArrayListEnumerator::MovePrevious(void)
109 {
110         SysTryReturnResult(NID_BASE_COL, (__modCount == __list.__modCount), E_INVALID_OPERATION, "The source collection was modified after the creation of this enumerator.");
111         SysTryReturnResult(NID_BASE_COL, __position > 0, E_OUT_OF_RANGE, "Reached start of the list, no previous element.");
112
113         __position--;
114
115         return E_SUCCESS;
116 }
117
118 result
119 _ArrayListEnumerator::ResetLast(void)
120 {
121         SysTryReturnResult(NID_BASE_COL, (__modCount == __list.__modCount), E_INVALID_OPERATION, "The source collection was modified after the creation of this enumerator.");
122
123         __position = __list.__count;
124         return E_SUCCESS;
125 }
126
127 ArrayList::ArrayList(DeleterFunctionType deleter)
128         : __capacity(0)
129         , __count(0)
130         , __pObjArray(null)
131         , __modCount(0)
132         , __pComparer(null)
133         , __deleter(deleter)
134         , __pArrayListImpl(null)
135 {
136 }
137
138 result
139 ArrayList::Construct(int capacity)
140 {
141         SysTryReturnResult(NID_BASE_COL, capacity >= 0, E_INVALID_ARG, "The capacity(%d) MUST be greater than or equal to 0.", capacity);
142
143         result r = SetCapacity(capacity);
144         SysTryReturnResult(NID_BASE_COL, r == E_SUCCESS, r, "Propagating.");
145
146         return E_SUCCESS;
147 }
148
149 result
150 ArrayList::Construct(const ICollection& collection)
151 {
152         result r = AddItems(collection);
153         SysTryCatch(NID_BASE_COL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
154
155         return r;
156
157 CATCH:
158         delete[] __pObjArray;
159         __pObjArray = null;
160
161         return r;
162 }
163
164 ArrayList::~ArrayList(void)
165 {
166         RemoveAll();
167         delete[] __pObjArray;
168 }
169
170 result
171 ArrayList::Add(Object* pObj)
172 {
173         SysTryReturnResult(NID_BASE_COL, pObj != null, E_INVALID_ARG, "Invalid argument used. The pObj is null");
174
175         if (__count >= __capacity)
176         {
177                 result r = SetCapacity(__capacity + DEFAULT_CAPACITY);
178                 SysTryReturnResult(NID_BASE_COL, r == E_SUCCESS, r, "Propagating.");
179         }
180
181         __pObjArray[__count++] = pObj;
182
183         __modCount++;
184
185         return E_SUCCESS;
186 }
187
188 result
189 ArrayList::AddItems(const ICollection& collection)
190 {
191         result r = E_SUCCESS;
192
193         int insertingCount = collection.GetCount();
194         if (insertingCount <= 0)
195         {
196                 return E_SUCCESS;
197         }
198
199         if (insertingCount > (__capacity - __count))
200         {
201                 r = SetCapacity(__count + insertingCount);
202                 SysTryReturnResult(NID_BASE_COL, r == E_SUCCESS, r, "Propagating.");
203         }
204
205         std::unique_ptr< IEnumerator > pEnum(collection.GetEnumeratorN());
206         SysTryReturnResult(NID_BASE_COL, pEnum != null, GetLastResult(), "Propagating.");
207         __modCount++;
208
209         while ((r = pEnum->MoveNext()) != E_OUT_OF_RANGE)
210         {
211                 SysTryReturnResult(NID_BASE_COL, r == E_SUCCESS, r, "Propagating.");
212
213                 Object* pItem = pEnum->GetCurrent();
214                 SysTryReturnResult(NID_BASE_COL, pItem != null, GetLastResult(), "Propagating.");
215
216                 __pObjArray[__count++] = pItem;
217         }
218
219         return E_SUCCESS;
220 }
221
222 IEnumerator*
223 ArrayList::GetEnumeratorN(void) const
224 {
225         return GetBidirectionalEnumeratorN();
226 }
227
228 IBidirectionalEnumerator*
229 ArrayList::GetBidirectionalEnumeratorN(void) const
230 {
231         std::unique_ptr< _ArrayListEnumerator > pEnum(new (std::nothrow) _ArrayListEnumerator(*this, __modCount));
232         SysTryReturn(NID_BASE_COL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
233
234         SetLastResult(E_SUCCESS);
235         return pEnum.release();
236 }
237
238 const Object*
239 ArrayList::GetAt(int index) const
240 {
241         SysTryReturn(NID_BASE_COL, index >= 0 && index < __count, null, E_OUT_OF_RANGE, "[%s] The index(%d) MUST be greater than or equal to 0 and less than the number of elements(%d).", GetErrorMessage(E_OUT_OF_RANGE), index, __count);
242
243         SetLastResult(E_SUCCESS);
244         return __pObjArray[index];
245 }
246
247 Object*
248 ArrayList::GetAt(int index)
249 {
250         const Object* pObj = (static_cast< const ArrayList* >(this))->GetAt(index);
251         return const_cast< Object* >(pObj);
252 }
253
254 IList*
255 ArrayList::GetItemsN(int startIndex, int count) const
256 {
257         result r = E_SUCCESS;
258         SysTryReturn(NID_BASE_COL, startIndex >= 0 && count >= 0, null, E_OUT_OF_RANGE, "[%s] Both of the startIndex(%d) and count(%d) MUST be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE), startIndex, count);
259         SysTryReturn(NID_BASE_COL, startIndex < __count, null, E_OUT_OF_RANGE,
260                 "[%s] The startIndex(%d) MUST be less than the number of elements(%d).", GetErrorMessage(E_OUT_OF_RANGE), startIndex, __count);
261         SysTryReturn(NID_BASE_COL, count <= __count && (startIndex + count <= __count), null, E_OUT_OF_RANGE,
262                 "[%s] The startIndex(%d) + count(%d) MUST be less than or equal to the number of elements(%d).", GetErrorMessage(E_OUT_OF_RANGE), startIndex, count, __count);
263
264         std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList());
265         SysTryReturn(NID_BASE_COL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
266
267         r = pList->Construct(count);
268         SysTryReturn(NID_BASE_COL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
269
270         memcpy(pList->__pObjArray, __pObjArray + startIndex, sizeof(Object*) * count);
271         pList->__count = count;
272
273         SetLastResult(E_SUCCESS);
274         return pList.release();
275 }
276
277 result
278 ArrayList::IndexOf(const Object& obj, int& index) const
279 {
280         return IndexOf(obj, 0, __count, index);
281 }
282
283 result
284 ArrayList::IndexOf(const Object& obj, int startIndex, int& index) const
285 {
286         SysTryReturnResult(NID_BASE_COL, startIndex >= 0 && startIndex < __count, E_OUT_OF_RANGE, "The startIndex(%d) MUST be greater than or equal to 0, and less than the number of elements(%d).", startIndex, __count);
287         return IndexOf(obj, startIndex, (__count - startIndex), index);
288 }
289
290 result
291 ArrayList::IndexOf(const Object& obj, int startIndex, int count, int& index) const
292 {
293         SysTryReturnResult(NID_BASE_COL, __count != 0, E_OBJ_NOT_FOUND, "The arraylist is empty.");
294         SysTryReturnResult(NID_BASE_COL, startIndex >= 0 && count >= 0, E_OUT_OF_RANGE, "Both of the startIndex(%d) and count(%d) MUST be greater than or equal to 0.", startIndex, count);
295         SysTryReturnResult(NID_BASE_COL, startIndex < __count, E_OUT_OF_RANGE,
296                 "The startIndex(%d) MUST be less than the number of elements(%d).", startIndex, __count);
297         SysTryReturnResult(NID_BASE_COL, count <= __count && (startIndex + count <= __count), E_OUT_OF_RANGE,
298                 "The startIndex(%d) + count(%d) MUST be less than or equal to the number of elements(%d).", startIndex, count, __count);
299
300         int arrayListCount = startIndex + count;
301         for (int i = startIndex; i < arrayListCount; i++)
302         {
303                 if (__pObjArray[i]->Equals(obj))
304                 {
305                         index = i;
306                         return E_SUCCESS;
307                 }
308         }
309
310         return E_OBJ_NOT_FOUND;
311 }
312
313 result
314 ArrayList::LastIndexOf(const Object& obj, int& index) const
315 {
316         for (int i = (__count - 1); i >= 0; i--)
317         {
318                 if (__pObjArray[i]->Equals(obj))
319                 {
320                         index = i;
321                         return E_SUCCESS;
322                 }
323         }
324
325         SysLogException(NID_BASE_COL, E_OBJ_NOT_FOUND, "The object is not in the list.");
326         return E_OBJ_NOT_FOUND;
327 }
328
329 result
330 ArrayList::InsertAt(Object* pObj, int index)
331 {
332         SysTryReturnResult(NID_BASE_COL, pObj != null, E_INVALID_ARG, "Invalid argument used. The pObj is null");
333         SysTryReturnResult(NID_BASE_COL, index >= 0 && index <= __count, E_OUT_OF_RANGE, "The index(%d) MUST be greater than or equal to 0, and less than or equal to the number of elements(%d).", index, __count);
334
335         if (__count >= __capacity)
336         {
337                 result r = SetCapacity(__capacity + DEFAULT_CAPACITY);
338                 SysTryReturnResult(NID_BASE_COL, r == E_SUCCESS, r, "Propagating.");
339         }
340
341         memmove(__pObjArray + index + 1, __pObjArray + index, sizeof(Object*) * (__count - index));
342
343         __count++;
344         __modCount++;
345         __pObjArray[index] = pObj;
346
347         return E_SUCCESS;
348 }
349
350 result
351 ArrayList::InsertItemsFrom(const ICollection& collection, int startIndex)
352 {
353         SysTryReturnResult(NID_BASE_COL, startIndex >= 0 && startIndex <= __count, E_OUT_OF_RANGE, "The startIndex(%d) MUST be greater than or equal to 0, and less than or equal to the number of elements(%d).", startIndex, __count);
354
355         result r = E_SUCCESS;
356         int insertingCount = collection.GetCount();
357
358         if (insertingCount <= 0)
359         {
360                 return E_SUCCESS;
361         }
362
363         if (insertingCount > (__capacity - __count))
364         {
365                 r = SetCapacity(__count + insertingCount);
366                 SysTryReturnResult(NID_BASE_COL, r == E_SUCCESS, r, "Propagating.");
367         }
368
369         memmove(__pObjArray + startIndex + insertingCount, __pObjArray + startIndex, sizeof(Object*) * (__count - startIndex));
370         __count += insertingCount;
371
372         std::unique_ptr< IEnumerator > pEnum(collection.GetEnumeratorN());
373         SysTryReturnResult(NID_BASE_COL, pEnum != null, GetLastResult(), "Propagating.");
374
375         __modCount++;
376
377         Object* pItem = null;
378         while ((r = pEnum->MoveNext()) != E_OUT_OF_RANGE)
379         {
380                 SysTryReturnResult(NID_BASE_COL, r == E_SUCCESS, r, "Propagating.");
381
382                 pItem = pEnum->GetCurrent();
383                 SysTryReturnResult(NID_BASE_COL, pItem != null, GetLastResult(), "Propagating.");
384
385                 __pObjArray[startIndex++] = pItem;
386         }
387
388         return E_SUCCESS;
389 }
390
391 result
392 ArrayList::Remove(const Object& obj)
393 {
394         int index = 0;
395         result r = IndexOf(obj, index);
396         SysTryReturnResult(NID_BASE_COL, r == E_SUCCESS, r, "Propagating.");
397         r = RemoveAt(index);
398         SysTryReturnResult(NID_BASE_COL, r == E_SUCCESS, r, "Propagating.")
399         return r;
400 }
401
402 result
403 ArrayList::RemoveAt(int index)
404 {
405         SysTryReturnResult(NID_BASE_COL, index < __count && index >= 0, E_OUT_OF_RANGE, "The index MUST be greater than or equal to 0, and less than the number of elements(%d).", index, __count);
406
407         __modCount++;
408         __count--;
409
410         __deleter(__pObjArray[index]);
411
412         memmove(__pObjArray + index, __pObjArray + index + 1, sizeof(Object*) * (__count - index));
413
414         return E_SUCCESS;
415 }
416
417 result
418 ArrayList::RemoveItems(int startIndex, int count)
419 {
420         SysTryReturnResult(NID_BASE_COL, startIndex >= 0 && count >= 0, E_OUT_OF_RANGE, "Both of the startIndex(%d) and count(%d) MUST be greater than or equal to 0.", startIndex, count);
421         SysTryReturnResult(NID_BASE_COL, startIndex < __count, E_OUT_OF_RANGE,
422                            "The startIndex(%d) MUST be less than the number of elements(%d).", startIndex, __count);
423         SysTryReturnResult(NID_BASE_COL, count <= __count && (startIndex + count <= __count), E_OUT_OF_RANGE,
424                            "The startIndex(%d) + count(%d) MUST be less than or equal to the number of elements(%d).", startIndex, count, __count);
425
426         if (count > 0)
427         {
428                 __modCount++;
429                 __count -= count;
430
431                 int i = 0;
432
433                 int arrayListCount = startIndex + count;
434                 for (i = startIndex; i < arrayListCount; i++)
435                 {
436                         __deleter(__pObjArray[i]);
437                 }
438
439                 memmove(__pObjArray + startIndex, __pObjArray + arrayListCount, sizeof(Object*) * (__count - startIndex));
440         }
441
442         return E_SUCCESS;
443 }
444
445 result
446 ArrayList::RemoveItems(const ICollection& collection)
447 {
448         result r = E_SUCCESS;
449
450         std::unique_ptr< IEnumerator > pEnum(collection.GetEnumeratorN());
451         SysTryReturnResult(NID_BASE_COL, pEnum != null, GetLastResult(), "Propagating.");
452
453         while ((r = pEnum->MoveNext()) != E_OUT_OF_RANGE)
454         {
455                 SysTryReturnResult(NID_BASE_COL, r == E_SUCCESS, r, "Propagating.");
456
457                 Object* pItem = pEnum->GetCurrent();
458                 SysTryReturnResult(NID_BASE_COL, pItem != null, GetLastResult(), "Propagating.");
459
460                 r = Remove(*pItem);
461                 SysTryLog(NID_BASE_COL, !IsFailed(r), "[%s] Propagating.", GetErrorMessage(r));
462         }
463         return E_SUCCESS;
464 }
465
466 void
467 ArrayList::RemoveAll()
468 {
469         for (int i = 0; i < __count; i++)
470         {
471                 __deleter(__pObjArray[i]);
472                 __pObjArray[i] = null;
473         }
474
475         __count = 0;
476         __modCount++;
477 }
478
479 result
480 ArrayList::SetAt(Object* pObj, int index)
481 {
482         SysTryReturnResult(NID_BASE_COL, pObj != null, E_INVALID_ARG, "Invalid argument used. The pObj is null");
483         SysTryReturnResult(NID_BASE_COL, index >= 0 && index < __count, E_OUT_OF_RANGE, "The index(%d) MUST be greater than or equal to 0, less than the number of elements(%d).", index, __count);
484
485         __modCount++;
486
487         __deleter(__pObjArray[index]);
488
489         __pObjArray[index] = pObj;
490
491         return E_SUCCESS;
492 }
493
494 result
495 ArrayList::SetCapacity(int newCapacity)
496 {
497         SysTryReturnResult(NID_BASE_COL, (newCapacity >= 0), E_INVALID_ARG, "The newCapacity(%d) MUST be greater than or equal to 0.", newCapacity);
498
499         if (__capacity == newCapacity)
500         {
501                 return E_SUCCESS;
502         }
503
504         Object** pNewArray = null;
505         if (newCapacity > 0)
506         {
507                 pNewArray = new (std::nothrow) Object*[newCapacity];
508                 SysTryReturn(NID_BASE_COL, pNewArray != null, E_OUT_OF_MEMORY, E_OUT_OF_RANGE, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
509
510                 if (__pObjArray != null)
511                 {
512                         int count = __count < newCapacity ? __count : newCapacity;
513                         memcpy(pNewArray, __pObjArray, sizeof(Object*) * count);
514                 }
515         }
516         if (__pObjArray != null)
517         {
518                 delete[] __pObjArray;
519         }
520
521         if (__count > newCapacity)
522         {
523                 __count = newCapacity;
524                 __modCount++;
525         }
526         __pObjArray = pNewArray;
527         __capacity = newCapacity;
528
529         return E_SUCCESS;
530 }
531
532 result
533 ArrayList::Sort(const IComparer& comparer)
534 {
535         if (__count == 0)
536         {
537                 return E_SUCCESS;
538         }
539
540         __pComparer = const_cast< IComparer* >(&comparer);
541         result r = QuickSort(0, (__count - 1));
542         if (IsFailed(r))
543         {
544                 SysLogException(NID_BASE_COL, r, "[%s] Propagating.", GetErrorMessage(r));
545                 __pComparer = null;
546
547                 return r;
548         }
549
550         return E_SUCCESS;
551 }
552
553 void
554 ArrayList::Trim(void)
555 {
556         result r = E_SUCCESS;
557         r = SetCapacity(__count);
558         if (IsFailed(r) == true)
559         {
560                 SetLastResult(r);
561         }
562 }
563
564 int
565 ArrayList::GetCapacity(void) const
566 {
567         return __capacity;
568 }
569
570 int
571 ArrayList::GetCount(void) const
572 {
573         return __count;
574 }
575
576 bool
577 ArrayList::Contains(const Object& obj) const
578 {
579         for (int i = 0; i < __count; i++)
580         {
581                 if (__pObjArray[i]->Equals(obj))
582                 {
583                         return true;
584                 }
585         }
586
587         return false;
588 }
589
590 bool
591 ArrayList::ContainsAll(const ICollection& collection) const
592 {
593         result r = E_SUCCESS;
594         SetLastResult(r);
595
596         if (collection.GetCount() == 0)
597         {
598                 return true;
599         }
600
601         std::unique_ptr< IEnumerator > pEnum(collection.GetEnumeratorN());
602         SysTryReturn(NID_BASE_COL, pEnum != null, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
603
604         while ((r = pEnum->MoveNext()) != E_OUT_OF_RANGE)
605         {
606                 SysTryReturn(NID_BASE_COL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
607
608                 Object* pItem = pEnum->GetCurrent();
609                 SysTryReturn(NID_BASE_COL, pItem != null, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
610
611                 if (!Contains(*pItem))
612                 {
613                         return false;
614                 }
615         }
616
617         return true;
618 }
619
620 bool
621 ArrayList::Equals(const Object& obj) const
622 {
623         if (&obj == this)
624         {
625                 return true;
626         }
627
628         const ArrayList* pOther = dynamic_cast< const ArrayList* >(&obj);
629         if (pOther == null)
630         {
631                 return false;
632         }
633         else if (__count != pOther->__count)
634         {
635                 return false;
636         }
637         else
638         {
639                 for (int i = 0; i < __count; i++)
640                 {
641                         if (!(__pObjArray[i]->Equals(*(pOther->__pObjArray[i]))))
642                         {
643                                 return false;
644                         }
645                 }
646         }
647
648         return true;
649 }
650
651 int
652 ArrayList::GetHashCode(void) const
653 {
654         int hash = 0;
655         for (int i = 0; i < __count; i++)
656         {
657                 hash += __pObjArray[i]->GetHashCode();
658         }
659
660         return hash;
661 }
662
663 DeleterFunctionType
664 ArrayList::GetDeleter(void) const
665 {
666         return __deleter;
667 }
668
669 result
670 ArrayList::QuickSort(int startIndex, int endIndex)
671 {
672         result r = E_SUCCESS;
673
674         if (startIndex < endIndex)
675         {
676                 int middleIndex = 0;
677                 int i = startIndex - 1;
678                 int j = endIndex + 1;
679
680                 while (true)
681                 {
682                         int compareResult = 1;
683
684                         while ((compareResult > 0) && (j > static_cast< int >(startIndex)))
685                         {
686                                 j--;
687                                 r = __pComparer->Compare(*(__pObjArray[j]), *(__pObjArray[startIndex]), compareResult);
688                                 SysTryReturnResult(NID_BASE_COL, r == E_SUCCESS, r, "Propagating.");
689                         }
690
691                         compareResult = -1;
692                         while ((compareResult < 0) && (i < endIndex))
693                         {
694                                 i++;
695                                 r = __pComparer->Compare(*(__pObjArray[i]), *(__pObjArray[startIndex]), compareResult);
696                                 SysTryReturnResult(NID_BASE_COL, r == E_SUCCESS, r, "Propagating.");
697                         }
698
699                         if (i < j)
700                         {
701                                 Object* pTemp = __pObjArray[j];
702                                 __pObjArray[j] = __pObjArray[i];
703                                 __pObjArray[i] = pTemp;
704                         }
705                         else
706                         {
707                                 middleIndex = j;
708                                 break;
709                         }
710                 }
711
712                 r = QuickSort(startIndex, middleIndex);
713                 SysTryReturnResult(NID_BASE_COL, r == E_SUCCESS, r, "Propagating.");
714
715                 r = QuickSort(middleIndex + 1, endIndex);
716                 SysTryReturnResult(NID_BASE_COL, r == E_SUCCESS, r, "Propagating.");
717         }
718
719         return r;
720 }
721
722 void
723 ArrayList::SetDeleter(DeleterFunctionType deleter)
724 {
725         __deleter = deleter;
726 }
727
728 }}}  // Tizen::Base::Collection