com.foxsmart.csu.config
Class Command

java.lang.Object
  extended by com.foxsmart.csu.config.Command

public class Command
extends java.lang.Object

The Command class represents a single command that can be sent to the router. The command may contain 1 line or multiple lines. If multiple lines are sent, the first line is considered the main command while the remaining lines (if any) are considered follow-up lines that are necessary to complete the command.

Empty or null lines are filtered out.

A Command may be deferred when the deferred flag is set to true. Deferred commands will be issued after all other non-deferred commands have been sent.


Constructor Summary
Command(java.lang.String command)
          Creates a command from a string.
 
Method Summary
 void add(int index, java.lang.String line)
          Adds a line at a specified position
 void add(java.lang.String line)
          Adds a line to the command.
 void addAll(java.util.ArrayList lines)
          Appends all the passed in lines to the end of the list.
 void addAll(int index, java.util.ArrayList lines)
          Inserts all the lines at the specified offset.
 void clear()
          Clears out all the lines.
 boolean equals(java.lang.Object command)
          Determines if two commands are equal (i.e.
 java.lang.String get(int index)
          Gets the line at the specified position.
 boolean getDeferredFlag()
          Gets the deferred flag.
 java.lang.String getFullCommand()
          Returns the full command.
 java.util.List getFullCommandAsList()
          Returns the full command and trims each line to remove leading and trailing spaces.
 java.lang.String getFullTrimmedCommand()
          Returns the full command and trims each line to remove leading and trailing spaces.
 java.util.List getFullTrimmedCommandAsList()
          Returns the full command and trims each line to remove leading and trailing spaces.
 java.lang.String getMainCommand()
          Gets the main command for this multi-line command.
 java.lang.String getMainTrimmedCommand()
          Gets the main command for this multi-line command and trims the command to ensure no leading and trailing spaces are present.
 boolean isEmpty()
          Returns if the command is empty or not.
 java.util.Iterator iterator()
          Returns an iterator to iterate through each of the lines.
 java.lang.String remove(int index)
          Removes the line at the specified position.
 java.lang.String set(int index, java.lang.String line)
          Sets the line at the specified offset.
 void setDeferredFlag(boolean deferredFlag)
          Sets the deferred flag.
 int size()
          Returns the number of lines.
 java.lang.String toString()
          Returns a string representation of this command.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Command

public Command(java.lang.String command)
Creates a command from a string. The string will be parsed and each line separated by a carriage return will be stored as individual elements in the ArrayList.

Parameters:
command - The command stored as a string.
Method Detail

getMainCommand

public java.lang.String getMainCommand()
Gets the main command for this multi-line command. If no main command is found, the empty string is returned.

Returns:
the main command.

getMainTrimmedCommand

public java.lang.String getMainTrimmedCommand()
Gets the main command for this multi-line command and trims the command to ensure no leading and trailing spaces are present. If no main command is found, the empty string is returned.

Returns:
the main command.

getFullCommand

public java.lang.String getFullCommand()
Returns the full command. If the command contains multiple lines, appropriate carriage return characters will be added to the end of each line with the exception of the final line. Empty lines are filtered out.

Returns:
the full command.

getFullTrimmedCommand

public java.lang.String getFullTrimmedCommand()
Returns the full command and trims each line to remove leading and trailing spaces. If the command contains multiple lines, appropriate carriage return characters will be added to the end of each line with the exception of the final line. Empty lines are filtered out.

Returns:
the full trimmed command.

getFullCommandAsList

public java.util.List getFullCommandAsList()
Returns the full command and trims each line to remove leading and trailing spaces. If the command contains multiple lines, each line will be returned in a separate element of the list. Empty lines are filtered out.

Returns:
the full trimmed command.

getFullTrimmedCommandAsList

public java.util.List getFullTrimmedCommandAsList()
Returns the full command and trims each line to remove leading and trailing spaces. If the command contains multiple lines, each line will be returned in a separate element of the list. Empty lines are filtered out.

Returns:
the full trimmed command.

toString

public java.lang.String toString()
Returns a string representation of this command. This is the same as calling getFullTrimmedCommand().

Overrides:
toString in class java.lang.Object
Returns:
The command as a string.

add

public void add(java.lang.String line)
Adds a line to the command.

Parameters:
line - The line to add.

add

public void add(int index,
                java.lang.String line)
Adds a line at a specified position

Parameters:
index - The index where the line will be added
line - The line to add.

addAll

public void addAll(java.util.ArrayList lines)
Appends all the passed in lines to the end of the list.

Parameters:
lines - The list of lines to add

addAll

public void addAll(int index,
                   java.util.ArrayList lines)
Inserts all the lines at the specified offset.

Parameters:
index - The index where the lines will be added
lines - The list of lines to add

clear

public void clear()
Clears out all the lines.


get

public java.lang.String get(int index)
Gets the line at the specified position.

Parameters:
index - The index for the line to get.
Returns:
The line at the specified position.
Throws:
java.lang.IndexOutOfBoundsException - if the offset doesn't exist.

remove

public java.lang.String remove(int index)
Removes the line at the specified position.

Parameters:
index - The index for the line to remove.
Returns:
The line at the position where the line was deleted.
Throws:
java.lang.IndexOutOfBoundsException - if the offset doesn't exist.

set

public java.lang.String set(int index,
                            java.lang.String line)
Sets the line at the specified offset.

Parameters:
index - The index where the line will be added
line - The line to set.
Returns:
The line that used to be at the offset specified.
Throws:
java.lang.IndexOutOfBoundsException - if the offset doesn't exist.

iterator

public java.util.Iterator iterator()
Returns an iterator to iterate through each of the lines.

Returns:
The iterator.

size

public int size()
Returns the number of lines.

Returns:
the number of lines.

isEmpty

public boolean isEmpty()
Returns if the command is empty or not.

Returns:
True if the command is empty or false if not.

equals

public boolean equals(java.lang.Object command)
Determines if two commands are equal (i.e. their generated IOS statements are the same).

Overrides:
equals in class java.lang.Object
Parameters:
command - The command to compare to.
Returns:
True if the commands are equal or false if not.

getDeferredFlag

public boolean getDeferredFlag()
Gets the deferred flag. The default is "false".

Returns:
the deferred flag.

setDeferredFlag

public void setDeferredFlag(boolean deferredFlag)
Sets the deferred flag. The deferred flag is used to signify that this Command's processing should be deferred until the end (i.e. after all other non-deferred Commands have been executed.

Parameters:
deferredFlag - True to defer the command or false to process it normally.


Copyright © 2005-2008 Fox Smart, Inc. All Rights Reserved.