//# 0 errors, 94 messages
//#
/*
    //#TimePlugin.java:1:1: class: com.dmdirc.addons.time.TimePlugin$1
    //#TimePlugin.java:1:1: method: com.dmdirc.addons.time.TimePlugin$1.com.dmdirc.addons.time.TimePlugin$1__static_init
    //#TimePlugin.java:1:1: class: com.dmdirc.addons.time.TimePlugin
    //#TimePlugin.java:1:1: method: com.dmdirc.addons.time.TimePlugin.com.dmdirc.addons.time.TimePlugin__static_init
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.addons.time;

import com.dmdirc.actions.ActionManager;
import com.dmdirc.commandparser.CommandManager;
import com.dmdirc.plugins.Plugin;

import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Provides various time-related features.
 * @author chris
 */
public final class TimePlugin  extends Plugin {
    
    /** Have we registered our types already? */
    private static boolean registered;
    
    /** The timer to use for scheduling. */
    private Timer timer;
    
    /** The TimerCommand we've registered. */
    private TimerCommand command;
    
    /** Creates a new instance of TimePlugin. */
    public TimePlugin() {
        super();
    //#TimePlugin.java:50: method: void com.dmdirc.addons.time.TimePlugin.com.dmdirc.addons.time.TimePlugin()
    //#TimePlugin.java:50: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.plugins.Plugin()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimePlugin
    //#    method: void com.dmdirc.addons.time.TimePlugin()
    //#    unanalyzed callee: void com.dmdirc.plugins.Plugin()
    //#input(void com.dmdirc.addons.time.TimePlugin()): this
    }
    //#TimePlugin.java:51: end of method: void com.dmdirc.addons.time.TimePlugin.com.dmdirc.addons.time.TimePlugin()
    
    /** {@inheritDoc} */
    @Override
    public void onLoad() {
        if (!registered) {
    //#TimePlugin.java:56: method: void com.dmdirc.addons.time.TimePlugin.onLoad()
    //#input(void onLoad()): com.dmdirc.addons.time.TimeActionType__static_init.new TimeActionType[](TimeActionType__static_init#4).length
    //#input(void onLoad()): com.dmdirc.addons.time.TimeActionType__static_init.new TimeActionType[](TimeActionType__static_init#4)[0..3]
    //#input(void onLoad()): com/dmdirc/addons/time/TimeActionType.$VALUES
    //#input(void onLoad()): registered
    //#input(void onLoad()): this
    //#output(void onLoad()): new Timer(onLoad#1) num objects
    //#output(void onLoad()): new TimerCommand(onLoad#3) num objects
    //#output(void onLoad()): this.command.__Tag
    //#output(void onLoad()): registered
    //#output(void onLoad()): this.command
    //#output(void onLoad()): this.timer
    //#new obj(void onLoad()): new Timer(onLoad#1)
    //#new obj(void onLoad()): new TimerCommand(onLoad#3)
    //#pre[2] (void onLoad()): init'ed(registered)
    //#pre[1] (void onLoad()): (soft) init'ed(com.dmdirc.addons.time.TimeActionType__static_init.new TimeActionType[](TimeActionType__static_init#4)[0..3])
    //#presumption(void onLoad()): java.util.Calendar:get(...)@61 <= 2_147_483_708
    //#presumption(void onLoad()): java.util.Calendar:getInstance(...)@61 != null
    //#post(void onLoad()): registered == 1
    //#post(void onLoad()): this.command == &new TimerCommand(onLoad#3)
    //#post(void onLoad()): this.timer == &new Timer(onLoad#1)
    //#post(void onLoad()): new Timer(onLoad#1) num objects == 1
    //#post(void onLoad()): new TimerCommand(onLoad#3) num objects == 1
    //#post(void onLoad()): this.command.__Tag == com/dmdirc/addons/time/TimerCommand
    //#unanalyzed(void onLoad()): Effects-of-calling:java.util.TimerTask
    //#unanalyzed(void onLoad()): Effects-of-calling:com.dmdirc.commandparser.commands.GlobalCommand
    //#unanalyzed(void onLoad()): Effects-of-calling:com.dmdirc.commandparser.CommandManager:registerCommand
    //#test_vector(void onLoad()): registered: {1}, {0}
            ActionManager.registerActionTypes(TimeActionType.values());
    //#TimePlugin.java:57: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.actions.ActionManager:registerActionTypes(ActionType[])
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimePlugin
    //#    method: void onLoad()
    //#    unanalyzed callee: void com.dmdirc.actions.ActionManager:registerActionTypes(ActionType[])
            registered = true;
        }

        final int offset = 60 - Calendar.getInstance().get(Calendar.SECOND);
        
        timer = new Timer("Time plugin timer");
        
        timer.schedule(new TimerTask() {
    //#TimePlugin.java:65: method: void com.dmdirc.addons.time.TimePlugin$1.com.dmdirc.addons.time.TimePlugin$1(TimePlugin)
    //#input(void com.dmdirc.addons.time.TimePlugin$1(TimePlugin)): Param_1
    //#input(void com.dmdirc.addons.time.TimePlugin$1(TimePlugin)): this
    //#output(void com.dmdirc.addons.time.TimePlugin$1(TimePlugin)): this.this$0
    //#post(void com.dmdirc.addons.time.TimePlugin$1(TimePlugin)): this.this$0 == Param_1
    //#post(void com.dmdirc.addons.time.TimePlugin$1(TimePlugin)): init'ed(this.this$0)
    //#TimePlugin.java:65: end of method: void com.dmdirc.addons.time.TimePlugin$1.com.dmdirc.addons.time.TimePlugin$1(TimePlugin)
            /** {@inheritDoc} */
            @Override
            public void run() {
                runTimer();
    //#TimePlugin.java:69: method: void com.dmdirc.addons.time.TimePlugin$1.run()
    //#input(void run()): com/dmdirc/addons/time/TimeActionType.TIME_DAY
    //#input(void run()): com/dmdirc/addons/time/TimeActionType.TIME_HOUR
    //#input(void run()): com/dmdirc/addons/time/TimeActionType.TIME_MINUTE
    //#input(void run()): this
    //#input(void run()): this.this$0
    //#pre[2] (void run()): this.this$0 != null
    //#unanalyzed(void run()): Effects-of-calling:java.util.Calendar:getInstance
    //#unanalyzed(void run()): Effects-of-calling:java.util.Calendar:get
    //#unanalyzed(void run()): Effects-of-calling:com.dmdirc.actions.ActionManager:processEvent
            }
    //#TimePlugin.java:70: end of method: void com.dmdirc.addons.time.TimePlugin$1.run()
        }, 1000 * offset, 1000 * 60);
        
        command = new TimerCommand();
    }
    //#TimePlugin.java:74: end of method: void com.dmdirc.addons.time.TimePlugin.onLoad()
    
    /** Handles a timer event that occurs every minute. */
    public void runTimer() {
        final Calendar cal = Calendar.getInstance();
    //#TimePlugin.java:78: method: void com.dmdirc.addons.time.TimePlugin.runTimer()
    //#input(void runTimer()): com/dmdirc/addons/time/TimeActionType.TIME_DAY
    //#input(void runTimer()): com/dmdirc/addons/time/TimeActionType.TIME_HOUR
    //#input(void runTimer()): com/dmdirc/addons/time/TimeActionType.TIME_MINUTE
    //#presumption(void runTimer()): java.util.Calendar:getInstance(...)@78 != null
    //#test_vector(void runTimer()): java.util.Calendar:get(...)@82: {-2_147_483_648..-1, 1..4_294_967_295}, {0}
    //#test_vector(void runTimer()): java.util.Calendar:get(...)@85: {-2_147_483_648..-1, 1..4_294_967_295}, {0}
        
        ActionManager.processEvent(TimeActionType.TIME_MINUTE, null, cal);
    //#TimePlugin.java:80: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.actions.ActionManager:processEvent(ActionType, StringBuffer, Object[])
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimePlugin
    //#    method: void runTimer()
    //#    unanalyzed callee: void com.dmdirc.actions.ActionManager:processEvent(ActionType, StringBuffer, Object[])
        
        if (cal.get(Calendar.MINUTE) == 0) {
            ActionManager.processEvent(TimeActionType.TIME_HOUR, null, cal);
    //#TimePlugin.java:83: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.actions.ActionManager:processEvent(ActionType, StringBuffer, Object[])
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimePlugin
    //#    method: void runTimer()
    //#    unanalyzed callee: void com.dmdirc.actions.ActionManager:processEvent(ActionType, StringBuffer, Object[])
            
            if (cal.get(Calendar.HOUR_OF_DAY) == 0) {
                ActionManager.processEvent(TimeActionType.TIME_DAY, null, cal);
    //#TimePlugin.java:86: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.actions.ActionManager:processEvent(ActionType, StringBuffer, Object[])
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimePlugin
    //#    method: void runTimer()
    //#    unanalyzed callee: void com.dmdirc.actions.ActionManager:processEvent(ActionType, StringBuffer, Object[])
            }
        }
    }
    //#TimePlugin.java:89: end of method: void com.dmdirc.addons.time.TimePlugin.runTimer()
    
    /** {@inheritDoc} */
    @Override
    public void onUnload() {
        if (timer != null) {
    //#TimePlugin.java:94: method: void com.dmdirc.addons.time.TimePlugin.onUnload()
    //#input(void onUnload()): this
    //#input(void onUnload()): this.command
    //#input(void onUnload()): this.timer
    //#output(void onUnload()): this.timer
    //#pre[1] (void onUnload()): init'ed(this.timer)
    //#pre[3] (void onUnload()): init'ed(this.command)
    //#post(void onUnload()): this.timer == null
    //#test_vector(void onUnload()): this.timer: Addr_Set{null}, Inverse{null}
            timer.cancel();
            timer = null;
        }
        
        CommandManager.unregisterCommand(command);
    //#TimePlugin.java:99: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.commandparser.CommandManager:unregisterCommand(CommandInfo)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimePlugin
    //#    method: void onUnload()
    //#    unanalyzed callee: void com.dmdirc.commandparser.CommandManager:unregisterCommand(CommandInfo)
    }
    //#TimePlugin.java:100: end of method: void com.dmdirc.addons.time.TimePlugin.onUnload()
}
    //#output(com.dmdirc.addons.time.TimePlugin$1__static_init): __Descendant_Table[com/dmdirc/addons/time/TimePlugin$1]
    //#output(com.dmdirc.addons.time.TimePlugin$1__static_init): __Dispatch_Table.run()V
    //#post(com.dmdirc.addons.time.TimePlugin$1__static_init): __Descendant_Table[com/dmdirc/addons/time/TimePlugin$1] == &__Dispatch_Table
    //#post(com.dmdirc.addons.time.TimePlugin$1__static_init): __Dispatch_Table.run()V == &run
    //#TimePlugin.java:: end of method: com.dmdirc.addons.time.TimePlugin$1.com.dmdirc.addons.time.TimePlugin$1__static_init
    //#TimePlugin.java:: end of class: com.dmdirc.addons.time.TimePlugin$1
    //#output(com.dmdirc.addons.time.TimePlugin__static_init): __Descendant_Table[com/dmdirc/addons/time/TimePlugin]
    //#output(com.dmdirc.addons.time.TimePlugin__static_init): __Dispatch_Table.onLoad()V
    //#output(com.dmdirc.addons.time.TimePlugin__static_init): __Dispatch_Table.onUnload()V
    //#output(com.dmdirc.addons.time.TimePlugin__static_init): __Dispatch_Table.runTimer()V
    //#post(com.dmdirc.addons.time.TimePlugin__static_init): __Descendant_Table[com/dmdirc/addons/time/TimePlugin] == &__Dispatch_Table
    //#post(com.dmdirc.addons.time.TimePlugin__static_init): __Dispatch_Table.onLoad()V == &onLoad
    //#post(com.dmdirc.addons.time.TimePlugin__static_init): __Dispatch_Table.onUnload()V == &onUnload
    //#post(com.dmdirc.addons.time.TimePlugin__static_init): __Dispatch_Table.runTimer()V == &runTimer
    //#TimePlugin.java:: end of method: com.dmdirc.addons.time.TimePlugin.com.dmdirc.addons.time.TimePlugin__static_init
    //#TimePlugin.java:: end of class: com.dmdirc.addons.time.TimePlugin
