001 // Copyright 2009 Waterken Inc. under the terms of the MIT X license 002 // found at http://www.opensource.org/licenses/mit-license.html 003 package org.waterken.trace; 004 005 import java.io.PrintStream; 006 import java.io.Serializable; 007 008 import org.joe_e.Struct; 009 import org.ref_send.deserializer; 010 import org.ref_send.name; 011 import org.ref_send.log.Comment; 012 import org.ref_send.log.Event; 013 import org.ref_send.promise.Receiver; 014 015 /** 016 * Prints {@linkplain Comment comments} to an output stream. 017 */ 018 public final class 019 Verbose extends Struct implements Receiver<Event>, Serializable { 020 static private final long serialVersionUID = 1L; 021 022 private final PrintStream out; 023 private final Receiver<Event> next; 024 025 /** 026 * Constructs an instance. 027 * @param out output stream 028 * @param next next event receiver 029 */ 030 public @deserializer 031 Verbose(@name("out") final PrintStream out, 032 @name("next") final Receiver<Event> next) { 033 this.out = out; 034 this.next = next; 035 } 036 037 public void 038 apply(final Event value) { 039 if (value instanceof Comment) { 040 out.println(value.anchor.turn.loop + ": " + ((Comment)value).text); 041 } 042 if (null != next) { next.apply(value); } 043 } 044 }