//# 0 errors, 75 messages
//#
/*
    //#TimerCommand.java:1:1: class: com.dmdirc.addons.time.TimerCommand
    //#TimerCommand.java:1:1: method: com.dmdirc.addons.time.TimerCommand.com.dmdirc.addons.time.TimerCommand__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.commandparser.CommandArguments;
import com.dmdirc.commandparser.CommandManager;
import com.dmdirc.commandparser.commands.GlobalCommand;
import com.dmdirc.commandparser.commands.IntelligentCommand;
import com.dmdirc.ui.input.AdditionalTabTargets;
import com.dmdirc.ui.input.TabCompleter;
import com.dmdirc.ui.interfaces.InputWindow;
import java.util.List;

/**
 * The timer command allows users to schedule commands to occur after a certain
 * interval, or to repeatedly occur with a specified delay.
 * @author chris
 */
public final class TimerCommand extends GlobalCommand implements IntelligentCommand {
    
    /**
     * Creates a new instance of TimerCommand.
     */
    public TimerCommand() {
    //#TimerCommand.java:44: method: void com.dmdirc.addons.time.TimerCommand.com.dmdirc.addons.time.TimerCommand()
    //#TimerCommand.java:44: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.commandparser.commands.GlobalCommand()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimerCommand
    //#    method: void com.dmdirc.addons.time.TimerCommand()
    //#    unanalyzed callee: void com.dmdirc.commandparser.commands.GlobalCommand()
    //#input(void com.dmdirc.addons.time.TimerCommand()): this
        CommandManager.registerCommand(this);
    //#TimerCommand.java:45: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.commandparser.CommandManager:registerCommand(Command)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimerCommand
    //#    method: void com.dmdirc.addons.time.TimerCommand()
    //#    unanalyzed callee: void com.dmdirc.commandparser.CommandManager:registerCommand(Command)
    }
    //#TimerCommand.java:46: end of method: void com.dmdirc.addons.time.TimerCommand.com.dmdirc.addons.time.TimerCommand()
    
    /** {@inheritDoc} */
    @Override
    public void execute(final InputWindow origin, final boolean isSilent, 
            final CommandArguments args) {
        if (args.getArguments().length < 3) {
    //#TimerCommand.java:52: method: void com.dmdirc.addons.time.TimerCommand.execute(InputWindow, bool, CommandArguments)
    //#TimerCommand.java:52: Warning: method not available - call not analyzed
    //#    call on String[] com.dmdirc.commandparser.CommandArguments:getArguments()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimerCommand
    //#    method: void execute(InputWindow, bool, CommandArguments)
    //#    unanalyzed callee: String[] com.dmdirc.commandparser.CommandArguments:getArguments()
    //#input(void execute(InputWindow, bool, CommandArguments)): args
    //#input(void execute(InputWindow, bool, CommandArguments)): isSilent
    //#input(void execute(InputWindow, bool, CommandArguments)): origin
    //#input(void execute(InputWindow, bool, CommandArguments)): this
    //#pre[1] (void execute(InputWindow, bool, CommandArguments)): args != null
    //#presumption(void execute(InputWindow, bool, CommandArguments)): com.dmdirc.commandparser.CommandArguments:getArguments(...).length@60 >= 1
    //#presumption(void execute(InputWindow, bool, CommandArguments)): com.dmdirc.commandparser.CommandArguments:getArguments(...).length@61 >= 2
    //#presumption(void execute(InputWindow, bool, CommandArguments)): com.dmdirc.commandparser.CommandArguments:getArguments(...)@52 != null
    //#presumption(void execute(InputWindow, bool, CommandArguments)): com.dmdirc.commandparser.CommandArguments:getArguments(...)@60 != null
    //#presumption(void execute(InputWindow, bool, CommandArguments)): com.dmdirc.commandparser.CommandArguments:getArguments(...)@61 != null
    //#unanalyzed(void execute(InputWindow, bool, CommandArguments)): Effects-of-calling:com.dmdirc.addons.time.TimerCommand:showUsage
    //#unanalyzed(void execute(InputWindow, bool, CommandArguments)): Effects-of-calling:java.util.TimerTask
    //#unanalyzed(void execute(InputWindow, bool, CommandArguments)): Effects-of-calling:java.util.Timer
    //#unanalyzed(void execute(InputWindow, bool, CommandArguments)): Effects-of-calling:java.util.Timer:schedule
    //#test_vector(void execute(InputWindow, bool, CommandArguments)): com.dmdirc.commandparser.CommandArguments:getArguments(...).length@52: {3..+Inf}, {0..2}
            doUsage(origin, isSilent);
        } else {
            int repetitions = 0;
    //#TimerCommand.java:55: Warning: unused assignment
    //#    Unused assignment into repetitions
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.addons.time.TimerCommand
    //#    method: void execute(InputWindow, bool, CommandArguments)
    //#    Attribs:  Uncertain
            int interval = 0;
    //#TimerCommand.java:56: Warning: unused assignment
    //#    Unused assignment into interval
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.addons.time.TimerCommand
    //#    method: void execute(InputWindow, bool, CommandArguments)
    //#    Attribs:  Uncertain
            final String command = args.getArgumentsAsString(2);
    //#TimerCommand.java:57: Warning: method not available - call not analyzed
    //#    call on String com.dmdirc.commandparser.CommandArguments:getArgumentsAsString(int)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimerCommand
    //#    method: void execute(InputWindow, bool, CommandArguments)
    //#    unanalyzed callee: String com.dmdirc.commandparser.CommandArguments:getArgumentsAsString(int)
            
            try {
                repetitions = Integer.parseInt(args.getArguments()[0]);
    //#TimerCommand.java:60: Warning: method not available - call not analyzed
    //#    call on String[] com.dmdirc.commandparser.CommandArguments:getArguments()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimerCommand
    //#    method: void execute(InputWindow, bool, CommandArguments)
    //#    unanalyzed callee: String[] com.dmdirc.commandparser.CommandArguments:getArguments()
                interval = Integer.parseInt(args.getArguments()[1]);
    //#TimerCommand.java:61: Warning: method not available - call not analyzed
    //#    call on String[] com.dmdirc.commandparser.CommandArguments:getArguments()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimerCommand
    //#    method: void execute(InputWindow, bool, CommandArguments)
    //#    unanalyzed callee: String[] com.dmdirc.commandparser.CommandArguments:getArguments()
            } catch (NumberFormatException ex) {
                doUsage(origin, isSilent);
                return;
            }
            
            new TimedCommand(repetitions, interval, command, origin);
            sendLine(origin, isSilent, FORMAT_OUTPUT, "Command scheduled.");
    //#TimerCommand.java:68: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.addons.time.TimerCommand:sendLine(InputWindow, bool, String, Object[])
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimerCommand
    //#    method: void execute(InputWindow, bool, CommandArguments)
    //#    unanalyzed callee: void com.dmdirc.addons.time.TimerCommand:sendLine(InputWindow, bool, String, Object[])
        }
    }
    //#TimerCommand.java:70: end of method: void com.dmdirc.addons.time.TimerCommand.execute(InputWindow, bool, CommandArguments)
    
    /**
     * Displays usage information for this command.
     * @param origin The window that the command was entered in
     * @param isSilent Whether this command is being silenced or not
     */
    private void doUsage(final InputWindow origin, final boolean isSilent) {
        showUsage(origin, isSilent, "timer", "<repetitions> <interval> <command>");
    //#TimerCommand.java:78: method: void com.dmdirc.addons.time.TimerCommand.doUsage(InputWindow, bool)
    //#TimerCommand.java:78: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.addons.time.TimerCommand:showUsage(InputWindow, bool, String, String)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimerCommand
    //#    method: void doUsage(InputWindow, bool)
    //#    unanalyzed callee: void com.dmdirc.addons.time.TimerCommand:showUsage(InputWindow, bool, String, String)
    //#input(void doUsage(InputWindow, bool)): isSilent
    //#input(void doUsage(InputWindow, bool)): origin
    //#input(void doUsage(InputWindow, bool)): this
    }
    //#TimerCommand.java:79: end of method: void com.dmdirc.addons.time.TimerCommand.doUsage(InputWindow, bool)
    
    /** {@inheritDoc} */
    @Override
    public String getName() {
        return "timer";
    //#TimerCommand.java:84: method: String com.dmdirc.addons.time.TimerCommand.getName()
    //#output(String getName()): return_value
    //#post(String getName()): return_value == &"timer"
    //#TimerCommand.java:84: end of method: String com.dmdirc.addons.time.TimerCommand.getName()
    }
    
    /** {@inheritDoc} */
    @Override
    public boolean showInHelp() {
        return true;
    //#TimerCommand.java:90: method: bool com.dmdirc.addons.time.TimerCommand.showInHelp()
    //#output(bool showInHelp()): return_value
    //#post(bool showInHelp()): return_value == 1
    //#TimerCommand.java:90: end of method: bool com.dmdirc.addons.time.TimerCommand.showInHelp()
    }
    
    /** {@inheritDoc} */
    @Override
    public String getHelp() {
        return "timer <repetitions> <interval> <command> " +
    //#TimerCommand.java:96: method: String com.dmdirc.addons.time.TimerCommand.getHelp()
    //#output(String getHelp()): return_value
    //#post(String getHelp()): return_value == &"timer <repetitions> <interval> <command> - schedules a command to be executed after a certain time"
    //#TimerCommand.java:96: end of method: String com.dmdirc.addons.time.TimerCommand.getHelp()
                "- schedules a command to be executed after a certain time";
    }

    /** {@inheritDoc} */
    @Override
    public AdditionalTabTargets getSuggestions(final int arg, final List<String> previousArgs) {
        AdditionalTabTargets res;
        
        if (arg <= 1) {
    //#TimerCommand.java:105: method: AdditionalTabTargets com.dmdirc.addons.time.TimerCommand.getSuggestions(int, List)
    //#input(AdditionalTabTargets getSuggestions(int, List)): arg
    //#input(AdditionalTabTargets getSuggestions(int, List)): previousArgs
    //#output(AdditionalTabTargets getSuggestions(int, List)): return_value
    //#post(AdditionalTabTargets getSuggestions(int, List)): init'ed(return_value)
    //#test_vector(AdditionalTabTargets getSuggestions(int, List)): arg: {2..4_294_967_295}, {-2_147_483_648..1}
            res = new AdditionalTabTargets().excludeAll();
    //#TimerCommand.java:106: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.ui.input.AdditionalTabTargets()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimerCommand
    //#    method: AdditionalTabTargets getSuggestions(int, List)
    //#    unanalyzed callee: void com.dmdirc.ui.input.AdditionalTabTargets()
    //#TimerCommand.java:106: Warning: method not available - call not analyzed
    //#    call on AdditionalTabTargets com.dmdirc.ui.input.AdditionalTabTargets:excludeAll()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimerCommand
    //#    method: AdditionalTabTargets getSuggestions(int, List)
    //#    unanalyzed callee: AdditionalTabTargets com.dmdirc.ui.input.AdditionalTabTargets:excludeAll()
        } else {
            res = TabCompleter.getIntelligentResults(arg, previousArgs, 2);
    //#TimerCommand.java:108: Warning: method not available - call not analyzed
    //#    call on AdditionalTabTargets com.dmdirc.ui.input.TabCompleter:getIntelligentResults(int, List, int)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.time.TimerCommand
    //#    method: AdditionalTabTargets getSuggestions(int, List)
    //#    unanalyzed callee: AdditionalTabTargets com.dmdirc.ui.input.TabCompleter:getIntelligentResults(int, List, int)
        }
        
        return res;
    //#TimerCommand.java:111: end of method: AdditionalTabTargets com.dmdirc.addons.time.TimerCommand.getSuggestions(int, List)
    } 
    
}
    //#output(com.dmdirc.addons.time.TimerCommand__static_init): __Descendant_Table[com/dmdirc/addons/time/TimerCommand]
    //#output(com.dmdirc.addons.time.TimerCommand__static_init): __Dispatch_Table.doUsage(Lcom/dmdirc/ui/interfaces/InputWindow;Z)V
    //#output(com.dmdirc.addons.time.TimerCommand__static_init): __Dispatch_Table.execute(Lcom/dmdirc/ui/interfaces/InputWindow;ZLcom/dmdirc/commandparser/CommandArguments;)V
    //#output(com.dmdirc.addons.time.TimerCommand__static_init): __Dispatch_Table.getHelp()Ljava/lang/String;
    //#output(com.dmdirc.addons.time.TimerCommand__static_init): __Dispatch_Table.getName()Ljava/lang/String;
    //#output(com.dmdirc.addons.time.TimerCommand__static_init): __Dispatch_Table.getSuggestions(ILjava/util/List;)Lcom/dmdirc/ui/input/AdditionalTabTargets;
    //#output(com.dmdirc.addons.time.TimerCommand__static_init): __Dispatch_Table.showInHelp()Z
    //#post(com.dmdirc.addons.time.TimerCommand__static_init): __Descendant_Table[com/dmdirc/addons/time/TimerCommand] == &__Dispatch_Table
    //#post(com.dmdirc.addons.time.TimerCommand__static_init): __Dispatch_Table.doUsage(Lcom/dmdirc/ui/interfaces/InputWindow;Z)V == &doUsage
    //#post(com.dmdirc.addons.time.TimerCommand__static_init): __Dispatch_Table.execute(Lcom/dmdirc/ui/interfaces/InputWindow;ZLcom/dmdirc/commandparser/CommandArguments;)V == &execute
    //#post(com.dmdirc.addons.time.TimerCommand__static_init): __Dispatch_Table.getHelp()Ljava/lang/String; == &getHelp
    //#post(com.dmdirc.addons.time.TimerCommand__static_init): __Dispatch_Table.getName()Ljava/lang/String; == &getName
    //#post(com.dmdirc.addons.time.TimerCommand__static_init): __Dispatch_Table.getSuggestions(ILjava/util/List;)Lcom/dmdirc/ui/input/AdditionalTabTargets; == &getSuggestions
    //#post(com.dmdirc.addons.time.TimerCommand__static_init): __Dispatch_Table.showInHelp()Z == &showInHelp
    //#TimerCommand.java:: end of method: com.dmdirc.addons.time.TimerCommand.com.dmdirc.addons.time.TimerCommand__static_init
    //#TimerCommand.java:: end of class: com.dmdirc.addons.time.TimerCommand
