author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Thu, 30 Oct 2014 21:30:10 +0100 | |
changeset 409 | 40cabcdcd2be |
permissions | -rw-r--r-- |
1 package org.apidesign.reentrant;
3 import java.util.Collection;
5 public class CriticalSectionSynchronized<T extends Comparable<T>> implements CriticalSection<T> {
6 private T pilot;
7 private int cnt;
9 public synchronized void assignPilot(T pilot) {
10 this.pilot = pilot;
11 }
13 public int sumBigger(Collection<T> args) {
14 for (T cmp : args) {
15 if (pilot.compareTo(cmp) < 0) {
16 cnt++;
17 }
18 }
19 return cnt;
20 }
22 public int getCount() {
23 return cnt;
24 }
25 }