Clover coverage report - gsbase - 2.0.1
Coverage timestamp: Sat Jan 1 2005 12:30:02 EST
file stats: LOC: 267   Methods: 24
NCLOC: 122   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TraceItem.java 25% 48% 70.8% 53.8%
coverage coverage
 1    /*
 2    * Copyright (c) 1998, 2005 Gargoyle Software Inc. All rights reserved.
 3    *
 4    * Redistribution and use in source and binary forms, with or without
 5    * modification, are permitted provided that the following conditions are met:
 6    *
 7    * 1. Redistributions of source code must retain the above copyright notice,
 8    * this list of conditions and the following disclaimer.
 9    * 2. Redistributions in binary form must reproduce the above copyright notice,
 10    * this list of conditions and the following disclaimer in the documentation
 11    * and/or other materials provided with the distribution.
 12    * 3. The end-user documentation included with the redistribution, if any, must
 13    * include the following acknowledgment:
 14    *
 15    * "This product includes software developed by Gargoyle Software Inc.
 16    * (http://www.GargoyleSoftware.com/)."
 17    *
 18    * Alternately, this acknowledgment may appear in the software itself, if
 19    * and wherever such third-party acknowledgments normally appear.
 20    * 4. The name "Gargoyle Software" must not be used to endorse or promote
 21    * products derived from this software without prior written permission.
 22    * For written permission, please contact info@GargoyleSoftware.com.
 23    * 5. Products derived from this software may not be called "GSBase", nor may
 24    * "GSBase" appear in their name, without prior written permission of
 25    * Gargoyle Software Inc.
 26    *
 27    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
 28    * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 29    * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE
 30    * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 31    * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 32    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 33    * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 34    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 35    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 36    * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 37    */
 38    package com.gargoylesoftware.base.trace;
 39   
 40    import com.gargoylesoftware.base.util.DetailedNullPointerException;
 41    import java.util.Date;
 42   
 43    /**
 44    * An item of data to be written.
 45    *
 46    * @version $Revision: 1.5 $
 47    * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
 48    */
 49    public class TraceItem implements Cloneable {
 50   
 51    private TraceItem prevItem_;
 52    private TraceItem nextItem_;
 53   
 54    private TraceChannel channel_;
 55   
 56    private String message_;
 57    private Throwable throwable_;
 58    private Date time_;
 59    private Thread thread_;
 60    private Object lock_;
 61   
 62    /**
 63    * Create a new item.
 64    */
 65  2 public TraceItem() {
 66    }
 67   
 68    /**
 69    * Reset all the values to null
 70    */
 71  3 /*package*/void clear() {
 72  3 message_ = null;
 73  3 throwable_ = null;
 74  3 time_ = null;
 75  3 thread_ = null;
 76  3 lock_ = null;
 77  3 channel_ = null;
 78    }
 79   
 80    /** @return true if the message has no content */
 81  0 boolean isClear() {
 82  0 return message_ == null
 83    && throwable_ == null
 84    && time_ == null
 85    && thread_ == null
 86    && lock_ == null
 87    && channel_ == null;
 88    }
 89   
 90    /**
 91    * Return a string representation of this object for testing purposes.
 92    * @return The string representation
 93    */
 94  0 public String toString() {
 95  0 final StringBuffer buffer = new StringBuffer(200);
 96  0 buffer.append("TraceItem[message=[");
 97  0 buffer.append(message_);
 98  0 buffer.append("] throwable=[");
 99  0 buffer.append(throwable_);
 100  0 buffer.append("] time=[");
 101  0 buffer.append(time_);
 102  0 buffer.append("] thread=[");
 103  0 buffer.append(thread_);
 104  0 buffer.append("] lock=[");
 105  0 buffer.append(lock_);
 106  0 buffer.append("] channel=[");
 107  0 buffer.append(channel_);
 108  0 buffer.append("]]");
 109  0 return buffer.toString();
 110    }
 111    /**
 112    * Return true if this item contains any text.
 113    * @return true if this item contains any text.
 114    */
 115  3 public boolean containsText() {
 116  3 return message_ != null | throwable_ != null;
 117    }
 118   
 119    /**
 120    * Return the message.
 121    * @return the message.
 122    */
 123  3 public String getMessage() {
 124  3 return message_;
 125    }
 126   
 127    /** @param string The message */
 128  3 void setMessage( final String string ) {
 129  3 message_ = string;
 130    }
 131   
 132    /**
 133    * Return the throwable.
 134    * @return the throwable.
 135    */
 136  0 public Throwable getThrowable() {
 137  0 return throwable_;
 138    }
 139   
 140    /** @param t The throwable */
 141  0 void setThrowable( final Throwable t ) {
 142  0 throwable_ = t;
 143    }
 144   
 145    /**
 146    * Return the time that the item was written to Trace
 147    * @return the time.
 148    */
 149  0 public Date getTime() {
 150  0 return time_;
 151    }
 152   
 153    /** @param time The time */
 154  4 void setTime( final Date time ) {
 155  4 assertNotNull("time", time);
 156  4 time_ = time;
 157    }
 158   
 159    /** @return The thread */
 160  0 Thread getThread() {
 161  0 return thread_;
 162    }
 163   
 164    /** @param thread The thread */
 165  4 void setThread( final Thread thread ) {
 166  4 assertNotNull("thread", thread);
 167  4 thread_ = thread;
 168    }
 169    /**
 170    * Return the name of the thread that called Trace.
 171    * @return the name of the thread.
 172    */
 173  0 public String getThreadName() {
 174   
 175  0 if( thread_ == null ) {
 176  0 return null;
 177    }
 178   
 179  0 try {
 180  0 return thread_.getName();
 181    }
 182    catch( final NullPointerException e ) {
 183    // Workaround for bug in JDK1.2.2 where getName() will throw
 184    // a NullPointerException in some cases.
 185  0 return "Unknown thread[hash=" + thread_.hashCode() + "]";
 186    }
 187    }
 188   
 189    /**
 190    * Return the lock.
 191    * @return the lock.
 192    */
 193  4 public Object getLock() {
 194  4 return lock_;
 195    }
 196   
 197    /** @param lock The lock */
 198  1 void setLock( final Object lock ) {
 199  1 lock_ = lock;
 200    }
 201   
 202    /**
 203    * Return the previous item.
 204    * @return the previous item.
 205    */
 206  11 public TraceItem getPrevItem() {
 207  11 return prevItem_;
 208    }
 209   
 210    /** @param item The previous item */
 211  6 void setPrevItem( final TraceItem item ) {
 212  6 prevItem_ = item;
 213    }
 214   
 215    /**
 216    * Return the next item.
 217    * @return the next item.
 218    */
 219  6 public TraceItem getNextItem() {
 220  6 return nextItem_;
 221    }
 222   
 223    /** @param item The next item */
 224  12 void setNextItem( final TraceItem item ) {
 225  12 nextItem_ = item;
 226    }
 227   
 228    /**
 229    * Return the channel.
 230    * @return the channel.
 231    */
 232  4 public TraceChannel getChannel() {
 233  4 return channel_;
 234    }
 235   
 236    /** @param channel The channel */
 237  3 void setChannel( final TraceChannel channel ) {
 238  3 assertNotNull("channel", channel);
 239  3 channel_ = channel;
 240    }
 241   
 242    /**
 243    * Return a copy of this object.
 244    * @return A copy.
 245    * @throws CloneNotSupportedException If this object is not cloneable.
 246    */
 247  3 public Object clone() throws CloneNotSupportedException {
 248  3 return super.clone();
 249    }
 250   
 251   
 252    /**
 253    * Verify that the specified value is not null. If it is then throw an exception
 254    *
 255    * @param fieldName The name of the field to check
 256    * @param fieldValue The value of the field to check
 257    * @exception DetailedNullPointerException If fieldValue is null
 258    */
 259  11 protected final void assertNotNull( final String fieldName, final Object fieldValue )
 260    throws DetailedNullPointerException {
 261   
 262  11 if( fieldValue == null ) {
 263  0 throw new DetailedNullPointerException(fieldName);
 264    }
 265    }
 266    }
 267