Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/* Copyright (c) 2016, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the license found in the LICENSE file in
 * the root directory of this source tree.
 */

import java.util.Locale;

public class Main {
    /**
     * Checks the validity of an argument, given a condition.  If the condition passes, the argument
     * is returned.  If not, an IllegalArgumentException is thrown.
     * @param arg The argument
     * @param condition The evaluated condition
     * @param argName The name of the argument field for use in the exception, if needed.
     * @return The argument, if condition is valid.
     * @throws IllegalArgumentException if the condition is invalid
     */
    public static <T> T checkArg(T arg, boolean condition, String argName) {
        if (condition) {
            return arg;
        }
        throw new IllegalArgumentException(String.format(Locale.US, "Illegal argument for %s.", argName));
    }
}