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