File Source: TimePlugin.java
/*
P/P * Method: com.dmdirc.addons.time.TimePlugin__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.addons.time;
24
25 import com.dmdirc.actions.ActionManager;
26 import com.dmdirc.commandparser.CommandManager;
27 import com.dmdirc.plugins.Plugin;
28
29 import java.util.Calendar;
30 import java.util.Timer;
31 import java.util.TimerTask;
32
33 /**
34 * Provides various time-related features.
35 * @author chris
36 */
37 public final class TimePlugin extends Plugin {
38
39 /** Have we registered our types already? */
40 private static boolean registered;
41
42 /** The timer to use for scheduling. */
43 private Timer timer;
44
45 /** The TimerCommand we've registered. */
46 private TimerCommand command;
47
48 /** Creates a new instance of TimePlugin. */
49 public TimePlugin() {
/*
P/P * Method: void com.dmdirc.addons.time.TimePlugin()
*/
50 super();
51 }
52
53 /** {@inheritDoc} */
54 @Override
55 public void onLoad() {
/*
P/P * Method: void onLoad()
*
* Preconditions:
* init'ed(registered)
* (soft) init'ed(com.dmdirc.addons.time.TimeActionType__static_init.new TimeActionType[](TimeActionType__static_init#4)[...])
*
* Presumptions:
* java.util.Calendar:get(...)@61 <= 2_147_483_708
* java.util.Calendar:getInstance(...)@61 != null
*
* Postconditions:
* registered == 1
* this.command == &new TimerCommand(onLoad#3)
* this.timer == &new Timer(onLoad#1)
* new Timer(onLoad#1) num objects == 1
* new TimerCommand(onLoad#3) num objects == 1
*
* Test Vectors:
* registered: {1}, {0}
*/
56 if (!registered) {
57 ActionManager.registerActionTypes(TimeActionType.values());
58 registered = true;
59 }
60
61 final int offset = 60 - Calendar.getInstance().get(Calendar.SECOND);
62
63 timer = new Timer("Time plugin timer");
64
/*
P/P * Method: void com.dmdirc.addons.time.TimePlugin$1(TimePlugin)
*/
65 timer.schedule(new TimerTask() {
66 /** {@inheritDoc} */
67 @Override
68 public void run() {
/*
P/P * Method: void run()
*/
69 runTimer();
70 }
71 }, 1000 * offset, 1000 * 60);
72
73 command = new TimerCommand();
74 }
75
76 /** Handles a timer event that occurs every minute. */
77 public void runTimer() {
/*
P/P * Method: void runTimer()
*
* Presumptions:
* java.util.Calendar:getInstance(...)@78 != null
*
* Test Vectors:
* java.util.Calendar:get(...)@82: {-231..-1, 1..232-1}, {0}
* java.util.Calendar:get(...)@85: {-231..-1, 1..232-1}, {0}
*/
78 final Calendar cal = Calendar.getInstance();
79
80 ActionManager.processEvent(TimeActionType.TIME_MINUTE, null, cal);
81
82 if (cal.get(Calendar.MINUTE) == 0) {
83 ActionManager.processEvent(TimeActionType.TIME_HOUR, null, cal);
84
85 if (cal.get(Calendar.HOUR_OF_DAY) == 0) {
86 ActionManager.processEvent(TimeActionType.TIME_DAY, null, cal);
87 }
88 }
89 }
90
91 /** {@inheritDoc} */
92 @Override
93 public void onUnload() {
/*
P/P * Method: void onUnload()
*
* Preconditions:
* init'ed(this.timer)
* init'ed(this.command)
*
* Postconditions:
* this.timer == null
*
* Test Vectors:
* this.timer: Addr_Set{null}, Inverse{null}
*/
94 if (timer != null) {
95 timer.cancel();
96 timer = null;
97 }
98
99 CommandManager.unregisterCommand(command);
100 }
101 }
SofCheck Inspector Build Version : 2.17854
| TimePlugin.java |
2009-Jun-25 01:54:24 |
| TimePlugin.class |
2009-Sep-02 17:04:15 |
| TimePlugin$1.class |
2009-Sep-02 17:04:15 |