All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.topologi.diffx.util.CommandLine Maven / Gradle / Ivy

There is a newer version: 11.5.0
Show newest version
/*
 * 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 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. * * @param name The name of the command line switch * @param args The command line arguments * * @return The value of the parameter or null. */ public static String getParameter(String name, String[] args) { if (args == null || args.length < 2 || name == null) return null; // find the argument for (int i = 0; i < args.length; i++) { 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. * * @param name The name of the command line switch. * @param args The command line arguments. * * @return true if the switch if available; false otherwise. */ public static boolean hasSwitch(String name, String[] args) { if (args == null || name == null) return false; for (String arg : args) { if (name.equals(arg)) return true; } return false; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy