2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
6 package org.apidesign.codeinjection;
8 import java.util.Iterator;
9 import java.util.ServiceLoader;
10 import org.apidesign.codeinjection.spi.CountDownExtender;
12 /** Second version to {@link CountDownImplV1} - imagine someone wants to
13 * reimplement {@link #down()} method to decrement by two not just by one.
14 * You do not like that idea at all, but you do not want to prevent such
15 * behaviour. You just do not want to maintain such bloody code. What can
16 * you do? You need to allow <b>code injection</b> via the
17 * {@link CountDownExtender} class!
19 * @author Jaroslav Tulach <jtulach@netbeans.org>
21 final class CountDownImplV2 extends CountDown {
24 CountDownImplV2(int initial) {
28 // BEGIN: codeinjection.v2
30 Iterator<CountDownExtender> it =
31 ServiceLoader.load(CountDownExtender.class).iterator();
34 cnt = it.next().decrement(cnt);
36 // common behaviour of 1.0 version
41 public boolean isDown() {
44 // END: codeinjection.v2