samples/reentrant/src/org/apidesign/reentrant/CriticalSectionSynchronized.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 30 Oct 2014 21:30:10 +0100
changeset 409 40cabcdcd2be
permissions -rw-r--r--
Updating to NBMs from NetBeans 8.0.1 as some of them are required to run on JDK8
     1 package org.apidesign.reentrant;
     2 
     3 import java.util.Collection;
     4 
     5 public class CriticalSectionSynchronized<T extends Comparable<T>> implements CriticalSection<T> {
     6     private T pilot;
     7     private int cnt;
     8     
     9     public synchronized void assignPilot(T pilot) {
    10         this.pilot = pilot;
    11     }
    12 
    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     }
    21 
    22     public int getCount() {
    23         return cnt;
    24     }
    25 }