Clover coverage report - PLT Utilities Test Coverage (plt-20120304-r5436)
Coverage timestamp: Sat Mar 3 2012 22:01:56 CST
file stats: LOC: 122   Methods: 15
NCLOC: 61   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SplitLogSink.java 0% 17.1% 20% 17.3%
coverage coverage
 1    /*BEGIN_COPYRIGHT_BLOCK*
 2   
 3    PLT Utilities BSD License
 4   
 5    Copyright (c) 2007-2010 JavaPLT group at Rice University
 6    All rights reserved.
 7   
 8    Developed by: Java Programming Languages Team
 9    Rice University
 10    http://www.cs.rice.edu/~javaplt/
 11   
 12    Redistribution and use in source and binary forms, with or without modification, are permitted
 13    provided that the following conditions are met:
 14   
 15    - Redistributions of source code must retain the above copyright notice, this list of conditions
 16    and the following disclaimer.
 17    - Redistributions in binary form must reproduce the above copyright notice, this list of
 18    conditions and the following disclaimer in the documentation and/or other materials provided
 19    with the distribution.
 20    - Neither the name of the JavaPLT group, Rice University, nor the names of the library's
 21    contributors may be used to endorse or promote products derived from this software without
 22    specific prior written permission.
 23   
 24    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 25    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 26    FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND
 27    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 28    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 29    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 30    IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 31    OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 32   
 33    *END_COPYRIGHT_BLOCK*/
 34   
 35    package edu.rice.cs.plt.debug;
 36   
 37    import java.io.IOException;
 38    import java.util.Set;
 39    import java.util.HashSet;
 40   
 41    import edu.rice.cs.plt.iter.IterUtil;
 42    import edu.rice.cs.plt.object.Composite;
 43    import edu.rice.cs.plt.object.ObjectUtil;
 44    import edu.rice.cs.plt.tuple.IdentityWrapper;
 45   
 46    /**
 47    * A log sink that sends messages to all the sinks it contains. This allows, for example, logging to be
 48    * viewed at runtime while, at the same time, being recorded to a file. The set of sinks can be
 49    * modified at any time. (Concurrent logging is supported, but concurrent {@code add} or {@code remove}
 50    * invocations are not: only one thread should manage the set of sinks at a time.)
 51    */
 52    public class SplitLogSink implements LogSink, Composite {
 53   
 54    private final Set<IdentityWrapper<LogSink>> _sinkSet;
 55    // a snapshot of _sinkSet that doesn't require synchronized access (direct iteration, in contrast, would)
 56    private volatile Iterable<LogSink> _sinks;
 57   
 58    /** Create a log that will send its messages to each of {@code logs} */
 59  0 public SplitLogSink(LogSink... sinks) { this(IterUtil.asIterable(sinks)); }
 60   
 61  5 public SplitLogSink(Iterable<? extends LogSink> sinks) {
 62  5 _sinkSet = new HashSet<IdentityWrapper<LogSink>>();
 63  5 add(sinks);
 64    }
 65   
 66  0 public void add(LogSink... toAdd) {
 67  0 for (LogSink s : toAdd) { _sinkSet.add(IdentityWrapper.make(s)); }
 68  0 refreshSinks();
 69    }
 70   
 71  5 public void add(Iterable<? extends LogSink> toAdd) {
 72  10 for (LogSink s : toAdd) { _sinkSet.add(IdentityWrapper.make(s)); }
 73  5 refreshSinks();
 74    }
 75   
 76  0 public void remove(LogSink... toRemove) {
 77  0 for (LogSink s : toRemove) { _sinkSet.remove(IdentityWrapper.make(s)); }
 78  0 refreshSinks();
 79    }
 80   
 81  0 public void remove(Iterable<? extends LogSink> toRemove) {
 82  0 for (LogSink s : toRemove) { _sinkSet.remove(IdentityWrapper.make(s)); }
 83  0 refreshSinks();
 84    }
 85   
 86  5 private void refreshSinks() {
 87  5 _sinks = IterUtil.snapshot(IterUtil.valuesOf(_sinkSet));
 88    }
 89   
 90  0 public int compositeHeight() { return ObjectUtil.compositeHeight(_sinks) + 1; }
 91  0 public int compositeSize() { return ObjectUtil.compositeSize(_sinks) + 1; }
 92   
 93  0 public void close() throws IOException {
 94  0 IOException exception = null;
 95  0 for (LogSink s : _sinks) {
 96  0 try { s.close(); }
 97  0 catch (IOException e) { exception = e; }
 98    }
 99  0 if (exception != null) { throw exception; }
 100    }
 101   
 102  0 public void log(StandardMessage m) {
 103  0 for (LogSink s : _sinks) { s.log(m); }
 104    }
 105   
 106  0 public void logStart(StartMessage m) {
 107  0 for (LogSink s : _sinks) { s.logStart(m); }
 108    }
 109   
 110  0 public void logEnd(EndMessage m) {
 111  0 for (LogSink s : _sinks) { s.logEnd(m); }
 112    }
 113   
 114  0 public void logError(ErrorMessage m) {
 115  0 for (LogSink s : _sinks) { s.logError(m); }
 116    }
 117   
 118  0 public void logStack(StackMessage m) {
 119  0 for (LogSink s : _sinks) { s.logStack(m); }
 120    }
 121   
 122    }