[927] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
| 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
| 14 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.commands.misc;
|
---|
[235] | 16 |
|
---|
| 17 | import java.util.List;
|
---|
[639] | 18 | import java.util.logging.Level;
|
---|
[235] | 19 |
|
---|
[922] | 20 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
[235] | 21 | import de.ugoe.cs.util.console.Command;
|
---|
| 22 | import de.ugoe.cs.util.console.Console;
|
---|
[667] | 23 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
[235] | 24 |
|
---|
| 25 | /**
|
---|
| 26 | * <p>
|
---|
| 27 | * Command to show the time elapsed since a timer has been started.
|
---|
| 28 | * </p>
|
---|
| 29 | *
|
---|
| 30 | * @author Steffen Herbold
|
---|
| 31 | * @version 1.0
|
---|
| 32 | */
|
---|
| 33 | public class CMDshowTimer implements Command {
|
---|
| 34 |
|
---|
| 35 | /*
|
---|
| 36 | * (non-Javadoc)
|
---|
| 37 | *
|
---|
| 38 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 39 | */
|
---|
| 40 | @Override
|
---|
| 41 | public void run(List<Object> parameters) {
|
---|
| 42 | String timerName;
|
---|
| 43 | try {
|
---|
| 44 | timerName = (String) parameters.get(0);
|
---|
| 45 | } catch (Exception e) {
|
---|
[766] | 46 | throw new IllegalArgumentException();
|
---|
[235] | 47 | }
|
---|
| 48 |
|
---|
[284] | 49 | Object dataObject = GlobalDataContainer.getInstance().getData(timerName);
|
---|
[235] | 50 | if (dataObject == null) {
|
---|
[240] | 51 | CommandHelpers.objectNotFoundMessage(timerName);
|
---|
[235] | 52 | return;
|
---|
| 53 | }
|
---|
| 54 | if (!(dataObject instanceof Long)) {
|
---|
[240] | 55 | CommandHelpers.objectNotType(timerName, "Long");
|
---|
[235] | 56 | return;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | long startTime = (Long) dataObject;
|
---|
| 60 | long currentTime = System.currentTimeMillis();
|
---|
[639] | 61 | Console.traceln(Level.INFO, "" + (currentTime - startTime) + " milliseconds");
|
---|
[235] | 62 | }
|
---|
| 63 |
|
---|
| 64 | /*
|
---|
| 65 | * (non-Javadoc)
|
---|
| 66 | *
|
---|
| 67 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 68 | */
|
---|
| 69 | @Override
|
---|
[664] | 70 | public String help() {
|
---|
| 71 | return "showTimer <timerName>";
|
---|
[235] | 72 | }
|
---|
| 73 |
|
---|
| 74 | }
|
---|