Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * This file is part of the DiffX library.
  *
  * For licensing information please see the file license.txt included in the release.
  * A copy of this licence can also be found at
  *   http://www.opensource.org/licenses/artistic-license-2.0.php
  */
 package com.topologi.diffx.util;

A set of utility methods to help with command-line interface.

The methods in this class would typically be used in the main(String[]) method of a class.

Author(s):
Christophe Lauret
Version:
17 May 2005
public final class CommandLine {

  
Prevents creation of instances.
  private CommandLine() {
  }

  
Returns the value corresponding to the given switch.

Returns null if any of the parameters is null.

Parameters:
name The name of the command line switch
args The command line arguments
Returns:
The value of the parameter or null.
  public static String getParameter(String nameString[] args) {
    if (args == null || args.length < 2 || name == nullreturn null;
    // find the argument
    for (int i = 0; i < args.lengthi++) {
      if (name.equals(args[i]) && i+1 < args.length)
        return args[i+1];
    }
    return null;
  }

  
Return true if the specified switch exists in the arguments.

This method will go through every argument to check whether the switch exists or not.

Returns false if any of the parameters is null.

Parameters:
name The name of the command line switch.
args The command line arguments.
Returns:
true if the switch if available; false otherwise.
  public static boolean hasSwitch(String nameString[] args) {
    if (args == null || name == nullreturn false;
    for (String arg : args) {
      if (name.equals(arg)) return true;
    }
    return false;
  }
New to GrepCode? Check out our FAQ X