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