| author | Jaroslav Tulach <jtulach@netbeans.org> |
| Sat Feb 20 18:20:10 2010 +0100 | |
| changeset 347 | 481fbbbcc7b7 |
| parent 99 | 4bf599099de7 |
| permissions | -rw-r--r-- |
| jtulach@99 | 1 |
package org.apidesign.sidemeanings; |
| jtulach@99 | 2 |
|
| jtulach@324 | 3 |
public abstract class Protected {
|
| jtulach@324 | 4 |
int counter; |
| jtulach@324 | 5 |
|
| jtulach@324 | 6 |
Protected() {}
|
| jtulach@324 | 7 |
|
| jtulach@324 | 8 |
protected void increment() {
|
| jtulach@324 | 9 |
counter++; |
| jtulach@324 | 10 |
} |
| jtulach@324 | 11 |
|
| jtulach@324 | 12 |
public final void incrementTenTimes() {
|
| jtulach@324 | 13 |
for (int i = 0; i < 10; i++) {
|
| jtulach@324 | 14 |
increment(); |
| jtulach@324 | 15 |
} |
| jtulach@324 | 16 |
} |
| jtulach@324 | 17 |
|
| jtulach@324 | 18 |
public final void assertCounter(int expected) {
|
| jtulach@324 | 19 |
assert expected == counter : "Expected " + expected + " but was " + counter; |
| jtulach@324 | 20 |
} |
| jtulach@99 | 21 |
|
| jtulach@99 | 22 |
|
| jtulach@324 | 23 |
public static class Dirty extends Protected {
|
| jtulach@99 | 24 |
// BEGIN: sidemeanings.Protected.Dirty |
| jtulach@324 | 25 |
protected void increment() {
|
| jtulach@324 | 26 |
// implementation: |
| jtulach@324 | 27 |
counter++; |
| jtulach@99 | 28 |
} |
| jtulach@99 | 29 |
// END: sidemeanings.Protected.Dirty |
| jtulach@99 | 30 |
} |
| jtulach@99 | 31 |
|
| jtulach@99 | 32 |
|
| jtulach@324 | 33 |
public static abstract class Clean extends Protected {
|
| jtulach@99 | 34 |
// BEGIN: sidemeanings.Protected.Clean |
| jtulach@324 | 35 |
protected abstract void increment(); |
| jtulach@324 | 36 |
protected final void defaultIncrement() {
|
| jtulach@324 | 37 |
counter++; |
| jtulach@99 | 38 |
} |
| jtulach@99 | 39 |
// END: sidemeanings.Protected.Clean |
| jtulach@99 | 40 |
} |
| jtulach@99 | 41 |
} |