samples/delegatingwriter/src/org/apidesign/delegatingwriter/AltBufferedWriter.java
1.1 --- a/samples/delegatingwriter/src/org/apidesign/delegatingwriter/AltBufferedWriter.java Sat Jun 14 09:56:12 2008 +0200
1.2 +++ b/samples/delegatingwriter/src/org/apidesign/delegatingwriter/AltBufferedWriter.java Sat Jun 14 09:58:08 2008 +0200
1.3 @@ -1,3 +1,8 @@
1.4 +/*
1.5 + * To change this template, choose Tools | Templates
1.6 + * and open the template in the editor.
1.7 + */
1.8 +
1.9 package org.apidesign.delegatingwriter;
1.10
1.11 import java.io.BufferedWriter;
1.12 @@ -28,25 +33,18 @@
1.13 @Override
1.14 public Writer append(CharSequence csq) throws IOException {
1.15 switch (behaviour) {
1.16 - case THROW_EXCEPTION:
1.17 - return appendThrowException(csq);
1.18 - case DELEGATE_TO_SUPER:
1.19 - return appendDelegateToSuper(csq);
1.20 - case DELEGATE_TO_OUT:
1.21 - return appendDelegateToUnderlaying(csq);
1.22 - case DELEGATE_CONDITIONALLY:
1.23 - return appendDelegateConditionally(csq);
1.24 - default:
1.25 - throw new IllegalStateException("Unknown" + behaviour);
1.26 + case THROW_EXCEPTION: return appendThrowException(csq);
1.27 + case DELEGATE_TO_SUPER: return appendDelegateToSuper(csq);
1.28 + case DELEGATE_TO_OUT: return appendDelegateToUnderlaying(csq);
1.29 + case DELEGATE_CONDITIONALLY: return appendDelegateConditionally(csq);
1.30 + default: throw new IllegalStateException("Unknown" + behaviour);
1.31 }
1.32 }
1.33
1.34 public Writer appendThrowException(CharSequence csq) throws IOException {
1.35 - /* in case of real code, this would be part of
1.36 - the regular append method. BEGIN: writer.throw
1.37 + /* in case of real code, this would be part of the regular append method BEGIN: writer.throw
1.38 public Writer append(CharSequence csq) throws IOException {
1.39 - /* thrown an exception as this method is new and
1.40 - subclasses need to override it */
1.41 + /* thrown an exception as this method is new and subclasses need to override it */
1.42 throw new UnsupportedOperationException();
1.43 }
1.44 // END: writer.throw
1.45 @@ -78,27 +76,14 @@
1.46 // END: writer.delegateout
1.47 }
1.48
1.49 - private Writer appendDelegateConditionally(CharSequence csq)
1.50 - throws IOException {
1.51 + private Writer appendDelegateConditionally(CharSequence csq) throws IOException {
1.52 // BEGIN: writer.conditionally
1.53 boolean isOverriden = false;
1.54 try {
1.55 isOverriden =
1.56 - (
1.57 - getClass().getMethod(
1.58 - "write", String.class
1.59 - ).getDeclaringClass() != Writer.class
1.60 - ) ||
1.61 - (
1.62 - getClass().getMethod(
1.63 - "write", Integer.TYPE
1.64 - ).getDeclaringClass() != BufferedWriter.class
1.65 - ) ||
1.66 - (
1.67 - getClass().getMethod(
1.68 - "write", String.class, Integer.TYPE, Integer.TYPE
1.69 - ).getDeclaringClass() != BufferedWriter.class
1.70 - );
1.71 + (getClass().getMethod("write", String.class).getDeclaringClass() != Writer.class) ||
1.72 + (getClass().getMethod("write", Integer.TYPE).getDeclaringClass() != BufferedWriter.class) ||
1.73 + (getClass().getMethod("write", String.class, Integer.TYPE, Integer.TYPE).getDeclaringClass() != BufferedWriter.class);
1.74 } catch (Exception ex) {
1.75 throw new IOException(ex);
1.76 }
1.77 @@ -114,9 +99,6 @@
1.78 }
1.79
1.80 public enum Behaviour {
1.81 - THROW_EXCEPTION,
1.82 - DELEGATE_TO_SUPER,
1.83 - DELEGATE_TO_OUT,
1.84 - DELEGATE_CONDITIONALLY
1.85 + THROW_EXCEPTION, DELEGATE_TO_SUPER, DELEGATE_TO_OUT, DELEGATE_CONDITIONALLY
1.86 }
1.87 }