SAFE Logo
CodeMatch Detailed Report
Version: 5.6.0 | Date: 06/18/12 | Time: 19:09:04

SCORE

SETTINGS
Compare file 1: C:\Users\Evan\Desktop\Java2SE5.0\src\java\util\concurrent\ArrayBlockingQueue.java
To file 2: C:\Users\Evan\Desktop\Android2.2Froyo\java\util\concurrent\ArrayBlockingQueue.java
Links to results: Matching Statements
Matching Comments and Strings
Matching Instruction Sequences
Matching Identifiers
Partially Matching Identifiers
Score
RESULTS
Matching Statements
File1 Line# File2 Line# Statement
87package java.util.concurrent
98import java.util.concurrent.locks.*
109import java.util.*
4746public class ArrayBlockingQueue<E> extends AbstractQueue<E>
4847implements BlockingQueue<E>, java.io.Serializable {
5655private static final long serialVersionUID = -817911632652898426L
5958private final E[] items
6564private int count
7372private final ReentrantLock lock
7574private final Condition notEmpty
7776private final Condition notFull
8483final int inc(int i) {
8584return (++i == items.length)? 0 : i
9291private void insert(E x) {
9392items[putIndex] = x
9493putIndex = inc(putIndex)
9594++count
96
288
343
95
318
343
notEmpty.signal()
103102private E extract() {
104
118
304
362
422
440
458
498
522
555
103
117
245
416
447
478
532
571
601
639
final E[] items = this.items
105104E x = items[takeIndex]
106
121
105
120
items[takeIndex] = null
107
122
106
121
takeIndex = inc(takeIndex)
108
137
107
136
--count
109
138
250
370
108
137
253
288
notFull.signal()
110
267
281
347
669
109
304
322
336
753
return x
117116void removeAt(int i) {
120119if (i == takeIndex) {
126125int nexti = inc(i)
127126if (nexti != putIndex) {
128127items[i] = items[nexti]
129128i = nexti
131
505
531
565
130
578
610
649
items[i] = null
132131putIndex = i
147147public ArrayBlockingQueue(int capacity) {
148148this(capacity, false)
160161public ArrayBlockingQueue(int capacity, boolean fair) {
161162if (capacity <= 0)
162
188
521
552
163
190
600
636
throw new IllegalArgumentException()
163164this.items = (E[]) new Object[capacity]
164165lock = new ReentrantLock(fair)
165166notEmpty = lock.newCondition()
166167notFull = lock.newCondition()
184186public ArrayBlockingQueue(int capacity, boolean fair,
185187Collection<? extends E> c) {
186188this(capacity, fair)
187189if (capacity < c.size())
190192for (Iterator<? extends E> it = c.iterator()
190192it.hasNext()
191193add(it.next())
205
236
261
274
305
326
336
363
387
410
423
441
459
483
499
523
556
592
222
246
275
298
311
330
354
371
394
417
448
479
533
557
572
602
640
676
final ReentrantLock lock = this.lock
206
262
306
327
388
411
424
442
460
484
500
524
557
593
661
677
223
299
355
372
395
418
449
480
534
558
573
603
641
677
745
761
lock.lock()
208225if (count == items.length)
215
255
269
294
321
331
349
375
392
415
435
453
478
488
513
543
576
597
671
690
232
258
293
306
324
349
359
376
399
433
460
491
552
562
586
622
660
681
755
774
lock.unlock()
233271throws InterruptedException {
237
275
337
364
247
276
312
331
lock.lockInterruptibly()
239
277
274
329
long nanos = unit.toNanos(timeout)
241279if (count != items.length) {
245
283
283
338
if (nanos <= 0)
248286nanos = notFull.awaitNanos(nanos)
249
287
342
369
252
287
317
342
} catch (InterruptedException ie) {
251
289
344
371
254
289
319
344
throw ie
260297public E poll() {
264
627
301
711
if (count == 0)
266
280
346
303
321
335
E x = extract()
273328public E poll(long timeout, TimeUnit unit) throws InterruptedException {
279334if (count != 0) {
286341nanos = notEmpty.awaitNanos(nanos)
302414public boolean remove(Object o) {
303
421
415
446
if (o == null) return false
308
426
446
469
502
526
559
420
451
484
543
575
605
643
int i = takeIndex
309
427
445
468
421
452
483
542
int k = 0
311423if (k++ >= count)
313425if (o.equals(items[i])) {
314
685
426
769
removeAt(i)
317
431
449
472
506
532
566
429
456
487
546
579
611
650
i = inc(i)
325353public E peek() {
329357return (count == 0) ? null : items[takeIndex]
335310public E take() throws InterruptedException {
340315while (count == 0)
341316notEmpty.await()
367250while (count == items.length)
368251notFull.await()
386370public int size() {
390374return count
409393public int remainingCapacity() {
413397return items.length - count
420445public boolean contains(Object o) {
428453while (k++ < count) {
429454if (o.equals(items[i]))
439477public Object[] toArray() {
444482Object[] a = new Object[count]
447
470
485
544
while (k < count) {
448486a[k++] = items[i]
451
476
489
550
return a
457531public <T> T[] toArray(T[] a) {
462536if (a.length < count)
463537a = (T[])java.lang.reflect.Array.newInstance(
464538a.getClass().getComponentType(),
465539count
471545a[k++] = (T)items[i]
474548if (a.length > count)
475549a[count] = null
482556public String toString() {
486560return super.toString()
497570public void clear() {
503576int k = count
504577while (k-- > 0) {
508
536
581
615
count = 0
509
537
582
616
putIndex = 0
510
538
583
617
takeIndex = 0
511
539
572
584
618
656
notFull.signalAll()
517596public int drainTo(Collection<? super E> c) {
518
549
597
633
if (c == null)
519
550
598
634
throw new NullPointerException()
520
551
599
635
if (c == this)
527
560
606
644
int n = 0
528607int max = count
529
563
608
647
while (n < max) {
530
564
609
648
c.add(items[i])
533
567
612
651
++n
535
569
614
653
if (n > 0) {
541
574
620
658
return n
548632public int drainTo(Collection<? super E> c, int maxElements) {
553637if (maxElements <= 0)
554638return 0
561645int sz = count
562646int max = (maxElements < count)? maxElements : count
570654count -= n
571655takeIndex = i
591675public Iterator<E> iterator() {
595679return new Itr()
604688private class Itr implements Iterator<E> {
609693private int nextIndex
617701private E nextItem
623707private int lastRet
625709Itr() {
626
682
710
766
lastRet = -1
628
650
655
712
734
739
nextIndex = -1
630714nextIndex = takeIndex
631715nextItem = items[takeIndex]
635719public boolean hasNext() {
641725return nextIndex >= 0
648732private void checkNext() {
649733if (nextIndex == putIndex) {
651735nextItem = null
653737nextItem = items[nextIndex]
654738if (nextItem == null)
659743public E next() {
660
676
744
760
final ReentrantLock lock = ArrayBlockingQueue.this.lock
663747if (nextIndex < 0)
664748throw new NoSuchElementException()
665749lastRet = nextIndex
666750E x = nextItem
667751nextIndex = inc(nextIndex)
668
688
752
772
checkNext()
675759public void remove() {
679763int i = lastRet
680764if (i == -1)
681765throw new IllegalStateException()
684768int ti = takeIndex
687771nextIndex = (i == ti) ? takeIndex : i

to top

Matching Comments and Strings
File1 Line# File2 Line# Comment/String
1316* A bounded {@linkplain BlockingQueue blocking queue} backed by an
1417* array. This queue orders elements FIFO (first-in-first-out). The
1518* <em>head</em> of the queue is that element that has been on the
1619* queue the longest time. The <em>tail</em> of the queue is that
1720* element that has been on the queue the shortest time. New elements
1821* are inserted at the tail of the queue, and the queue retrieval
1922* operations obtain elements at the head of the queue.
2124* <p>This is a classic &quot;bounded buffer&quot;, in which a
2225* fixed-sized array holds elements inserted by producers and
2326* extracted by consumers. Once created, the capacity cannot be
2629* element from an empty queue will similarly block.
2831* <p> This class supports an optional fairness policy for ordering
2932* waiting producer and consumer threads. By default, this ordering
3033* is not guaranteed. However, a queue constructed with fairness set
3134* to <tt>true</tt> grants threads access in FIFO order. Fairness
3235* generally decreases throughput but reduces variability and avoids
3336* starvation.
3538* <p>This class and its iterator implement all of the
3639* <em>optional</em> methods of the {@link Collection} and {@link
3740* Iterator} interfaces.
4342* @since 1.5
4443* @author Doug Lea
4544* @param <E> the type of elements held in this collection
5150* Serialization ID. This class relies on default serialization
5251* even for the items array, which is default-serialized, even if
5352* it is empty. Otherwise it could not be declared final, which is
5453* necessary here.
5857* The queued items
6059* items index for next take, poll or remove
6261* items index for next put, offer, or add.
6463* Number of items in the queue
6867* Concurrency control uses the classic two-condition algorithm
6968* found in any textbook.
7271* Main lock guarding all access
7473* Condition for waiting takes
7675* Condition for waiting puts
7978Internal helper methods
8281* Circularly increment i.
90
101
115
89
100
114
* Call only when holding lock.
114113* Utility for remove and iterator.remove: Delete item at position i.
119118if removing front item, just advance
124123slide over all others up through putIndex.
142
152
170
141
152
171
* Creates an <tt>ArrayBlockingQueue</tt> with the given (fixed)
143142* capacity and default access policy.
144
154
174
144
155
176
* @param capacity the capacity of this queue
145
158
145
159
* @throws IllegalArgumentException if <tt>capacity</tt> is less than 1
153153* capacity and the specified access policy.
155
175
156
177
* @param fair if <tt>true</tt> then queue accesses for threads blocked
171172* capacity, the specified access policy and initially containing the
172173* elements of the given collection,
173174* added in traversal order of the collection's iterator.
178180* @param c the collection of elements to initially contain
179181* @throws IllegalArgumentException if <tt>capacity</tt> is less than
180182* <tt>c.size()</tt>, or less than 1.
250
288
343
370
253
288
318
343
propagate to non-interrupted thread
379363this doc comment is overridden to remove the reference to collections
380364greater in size than Integer.MAX_VALUE
382366* Returns the number of elements in this queue.
396380this doc comment is a modified copy of the inherited doc comment,
397381without the reference to unlimited queues.
401385* blocking. This is always equal to the initial capacity of this queue
402386* less the current <tt>size</tt> of this queue.
494567* Atomically removes all of the elements from this queue.
495568* The queue will be empty after this call returns.
582666* Returns an iterator over the elements in this queue in proper sequence.
583667* The returned <tt>Iterator</tt> is a "weakly consistent" iterator that
585669* and guarantees to traverse elements as they existed upon
586670* construction of the iterator, and may (but is not guaranteed to)
587671* reflect any modifications subsequent to construction.
602686* Iterator for ArrayBlockingQueue
606690* Index of element to be returned by next,
607691* or a negative number if no such.
612696* nextItem holds on to item fields because once we claim
613697* that an element exists in hasNext(), we must return it in
614698* the following next() call even if it was in the process of
615699* being removed when hasNext() was called.
620704* Index of element returned by most recent call to next.
621705* Reset to -1 if this element is deleted by a call to remove.
637721* No sync. We can return true by mistake here
638722* only if this iterator passed across threads,
639723* which we don't support anyway.
646730* Stops iterator when either hits putIndex or sees null item.
686770back up cursor (reset to front if was first element)

to top

Matching Instruction Sequences
File1 Line# File2 Line# Number of matching instructions
8 7 63
203 220 13
240 278 27
278 333 14
293 398 20
293 432 10
320 348 13
320 358 13
320 375 10
320 551 11
329 304 18
347 229 19
374 348 17
374 358 24
374 375 10
374 551 11
390 550 11
390 658 10
391 348 10
414 432 180
476 357 12
476 374 11
476 658 10
477 348 11
526 644 10
560 605 10
574 357 10
574 374 10
574 550 10

to top

Matching Identifiers
817911632652898426L AbstractQueue add Array ArrayBlockingQueue await awaitNanos BlockingQueue
capacity checkNext clear Collection concurrent Condition contains count
drainTo equals extract fair getClass getComponentType hasNext ie
IllegalArgumentException IllegalStateException inc insert InterruptedException io it items
Iterator Itr java lang lastRet length lock lockInterruptibly
locks max maxElements nanos newCondition newInstance next nexti
nextIndex nextItem NoSuchElementException notEmpty notFull NullPointerException Object offer
peek poll put putIndex ReentrantLock reflect remainingCapacity remove
removeAt Serializable serialVersionUID signal signalAll size sz take
takeIndex ti timeout TimeUnit toArray toNanos toString unit
unlock util

to top

Partially Matching Identifiers
*** NONE ***
to the top
SCORE 79

CodeSuite copyright 2003-2012 by Software Analysis and Forensic Engineering Corporation