Coverage report

  %line %branch
nl.toolforge.karma.core.cmd.event.CommandFinishedEvent
0% 
0% 

 1  
 /*
 2  
 Karma core - Core of the Karma application
 3  
 Copyright (C) 2004  Toolforge <www.toolforge.nl>
 4  
 
 5  
 This library is free software; you can redistribute it and/or
 6  
 modify it under the terms of the GNU Lesser General Public
 7  
 License as published by the Free Software Foundation; either
 8  
 version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
 This library is distributed in the hope that it will be useful,
 11  
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 Lesser General Public License for more details.
 14  
 
 15  
 You should have received a copy of the GNU Lesser General Public
 16  
 License along with this library; if not, write to the Free Software
 17  
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  
 */
 19  
 package nl.toolforge.karma.core.cmd.event;
 20  
 
 21  
 import nl.toolforge.karma.core.cmd.Command;
 22  
 
 23  
 /**
 24  
  * Generated when a command was finished (without an exception).
 25  
  *
 26  
  * @author D.A. Smedes
 27  
  * @version $Id: CommandFinishedEvent.java,v 1.2 2004/10/26 22:47:58 hippe Exp $
 28  
  */
 29  
 public final class CommandFinishedEvent extends CommandResponseEvent {
 30  
 
 31  0
   private long start = 0L;
 32  0
   private long duration = 0L;
 33  
 
 34  
   /**
 35  
    * Creates the event for <code>command</code>.
 36  
    *
 37  
    * @param command The command that has started.
 38  
    */
 39  
   public CommandFinishedEvent(Command command, long startTime) {
 40  
 
 41  0
     super(command);
 42  
 
 43  0
     start = startTime;
 44  0
     duration = System.currentTimeMillis() - start;
 45  0
   }
 46  
 
 47  
   /**
 48  
    * Returns the time this event was generated, effectively, the time the command was finished.
 49  
    *
 50  
    * @return Finish time of the command.
 51  
    */
 52  
   public long getTime() {
 53  0
     return duration;
 54  
   }
 55  
 
 56  
   /**
 57  
    * Returns a SimpleMessage formatted as <code>[ &lt;command-name&gt; ] Started.</code>.
 58  
    */
 59  
   public Message getEventMessage() {
 60  
 
 61  0
     if (duration < 1000) {
 62  0
       return new SimpleMessage(MessageHelper.format(getCommand().getName(), "Finished in " + duration + " milliseconds."));
 63  
     } else {
 64  0
       if (duration/1000 <= 1) {
 65  0
         return new SimpleMessage(MessageHelper.format(getCommand().getName(), "Finished in " + duration/1000 + " second."));
 66  
       } else {
 67  0
         return new SimpleMessage(MessageHelper.format(getCommand().getName(), "Finished in " + duration/1000 + " seconds."));
 68  
       }
 69  
     }
 70  
   }
 71  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.