source: trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/ui/commands/CMDshowTimer.java @ 667

Last change on this file since 667 was 667, checked in by sherbold, 12 years ago

*moved GlobalDataContainer? from quest-ui-core to java-utils

  • Property svn:mime-type set to text/plain
File size: 1.4 KB
Line 
1package de.ugoe.cs.quest.ui.commands;
2
3import java.security.InvalidParameterException;
4import java.util.List;
5import java.util.logging.Level;
6
7import de.ugoe.cs.quest.CommandHelpers;
8import de.ugoe.cs.util.console.Command;
9import de.ugoe.cs.util.console.Console;
10import de.ugoe.cs.util.console.GlobalDataContainer;
11
12/**
13 * <p>
14 * Command to show the time elapsed since a timer has been started.
15 * </p>
16 *
17 * @author Steffen Herbold
18 * @version 1.0
19 */
20public class CMDshowTimer implements Command {
21
22        /*
23         * (non-Javadoc)
24         *
25         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
26         */
27        @Override
28        public void run(List<Object> parameters) {
29                String timerName;
30                try {
31                        timerName = (String) parameters.get(0);
32                } catch (Exception e) {
33                        throw new InvalidParameterException();
34                }
35
36                Object dataObject = GlobalDataContainer.getInstance().getData(timerName);
37                if (dataObject == null) {
38                        CommandHelpers.objectNotFoundMessage(timerName);
39                        return;
40                }
41                if (!(dataObject instanceof Long)) {
42                        CommandHelpers.objectNotType(timerName, "Long");
43                        return;
44                }
45
46                long startTime = (Long) dataObject;
47                long currentTime = System.currentTimeMillis();
48                Console.traceln(Level.INFO, "" + (currentTime - startTime) + " milliseconds");
49        }
50
51        /*
52         * (non-Javadoc)
53         *
54         * @see de.ugoe.cs.util.console.Command#help()
55         */
56        @Override
57        public String help() {
58                return "showTimer <timerName>";
59        }
60
61}
Note: See TracBrowser for help on using the repository browser.