Example usage for org.apache.commons.lang3 Validate isTrue

List of usage examples for org.apache.commons.lang3 Validate isTrue

Introduction

In this page you can find the example usage for org.apache.commons.lang3 Validate isTrue.

Prototype

public static void isTrue(final boolean expression, final String message, final Object... values) 

Source Link

Document

Validate that the argument condition is true ; otherwise throwing an exception with the specified message.

Usage

From source file:co.runrightfast.commons.utils.ValidationUtils.java

static void greaterThanOrEqualZero(final int n, final String argName) {
    Validate.isTrue(n >= 0, "%s must be >= 0", argName);
}

From source file:co.runrightfast.commons.utils.ValidationUtils.java

static void greaterThanZero(final int n, final String argName) {
    Validate.isTrue(n > 0, "%s must be > 0", argName);
}

From source file:com.yilang.commons.utils.util.Digests.java

public static byte[] generateSalt(int numBytes) {
    Validate.isTrue(numBytes > 0, "numBytes argument must be a positive integer (1 or larger)", numBytes);

    byte[] bytes = new byte[numBytes];
    random.nextBytes(bytes);/*from   w w w  .j a v a 2 s.c  o m*/
    return bytes;
}

From source file:de.shadowhunt.subversion.Revision.java

/**
 * Create a new {@link Revision} instance for the given value.
 *
 * @param revision value of the {@link Revision} must be greater or equal than {@code 1}
 *
 * @return the new {@link Revision} instance with the given value
 *
 * @throws IllegalArgumentException if revision is smaller than {@code 1}
 *///w  ww. j a  v a2s  .co  m
public static Revision create(final int revision) {
    Validate.isTrue((revision >= 0), "Value must be greater or equal than 0, was {0}", revision);

    switch (revision) {
    case 0:
        return EMPTY;
    case 1:
        return INITIAL;
    default:
        return new Revision(revision);
    }
}

From source file:com.quartercode.femtoweb.impl.ActionUriResolver.java

/**
 * Returns the URI of the given {@link Action} which must be located in the given package.
 * See {@link Context#getUri(Class)} for more information.
 *
 * @param actionBasePackage The package name which will be removed from the start of the action class name.
 *        Thereby, package names like {@code com.quartercode.femtowebtest.actions} are not included in URIs.
 * @param action The action class whose URI should be returned.
 * @return The URI the given action class is mapped to.
 *///from   w w  w  .jav a2  s .c  om
public static String getUri(String actionBasePackage, Class<? extends Action> action) {

    String actionFQCN = action.getName();

    // Verify that the action class is
    // - not an inner class
    // - not called "Action"
    // - ends with action
    Validate.isTrue(!StringUtils.contains(actionFQCN, '$'),
            "Action classes are not allowed to be inner classes; '%s' is therefore invalid", actionFQCN);
    Validate.isTrue(!actionFQCN.endsWith(".Action"),
            "Actions classes which are just called 'Action' are disallowed");
    Validate.isTrue(actionFQCN.endsWith("Action"),
            "Actions classes must end with 'Action'; '%s' is therefore invalid", actionFQCN);

    // Verify that the action class is inside the base package
    Validate.isTrue(actionFQCN.startsWith(actionBasePackage),
            "Cannot retrieve URI of action class '%s' because it doesn't start with the set action base package '%s'",
            actionFQCN, actionBasePackage);

    // Retrieve the name of the action class without the base package
    String actionName = actionFQCN.substring(actionBasePackage.length() + 1);

    // Replace all "." with "/", add an "/" to the front, uncapitalize the last URI part, remove "Action" from the last URI part
    // Example: "path.to.SomeTestAction" -> "/path/to/someTest")
    String[] actionNameComponents = splitAtLastSeparator(actionName, ".");
    String uriDir = actionNameComponents[0].replace('.', '/');
    String uriName = StringUtils.uncapitalize(StringUtils.removeEnd(actionNameComponents[1], "Action"));

    return "/" + joinNonBlankItems("/", uriDir, uriName);
}

From source file:cc.sion.core.utils.Digests.java

/**
 * ??Byte[]salt.//w ww. ja  v  a  2 s .  com
 *
 * @param numBytes byte?
 */
public static byte[] generateSalt(int numBytes) {
    Validate.isTrue(numBytes > 0, "numBytes argument must be a positive integer (1 or larger)", numBytes);

    byte[] bytes = new byte[numBytes];
    random.nextBytes(bytes);
    return bytes;
}

From source file:$.Digests.java

/**
     * ??Byte[]salt./*from   w  ww  .  j  a v a 2s  .  co  m*/
     *
     * @param numBytes byte?
     */
    public static byte[] generateSalt(int numBytes) {
        Validate.isTrue(numBytes > 0, "numBytes argument must be a positive integer (1 or larger)", numBytes);

        byte[] bytes = new byte[numBytes];
        random.nextBytes(bytes);
        return bytes;
    }

From source file:at.pcgamingfreaks.Bukkit.Particles.ParticleSpawnerBukkit_1_7.java

public void spawnParticle(Location location, Particle type, double visibleRange, int count, float offsetX,
        float offsetY, float offsetZ, float speed) {
    Validate.isTrue(type.getMinVersion().olderOrEqualThan(MCVersion.MC_1_7_10),
            "The %s particle is not available in your minecraft version!", type.getName());
    try {//from  w ww . ja  va 2s. c o  m
        //noinspection ConstantConditions
        spawnParticle(location, visibleRange,
                PACKET_CONSTRUCTOR.newInstance(type.getOldName(), (float) location.getX(),
                        (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed,
                        count));
    } catch (Exception e) {
        System.out.println("Unable to spawn particle " + type.getOldName() + ". (Version 1.7)");
        e.printStackTrace();
    }
}

From source file:de.weltraumschaf.groundzero.model.CheckstyleViolation.java

/**
 * Set the line./*from   www .j  a  va  2  s .c o m*/
 *
 * @param line must not be less than 1
 */
public void setLine(final int line) {
    Validate.isTrue(line > 0, "Line must not be less than 1! Was %d.", line);
    this.line = line;
}

From source file:de.neofonie.aiko.RetryStrategy.java

/**
 * Creates an instance with the given arguments.
 *
 * @param retryCount Retry count.//from   w  w w.j  a  v a2 s .c o  m
 * @param retryDelay Retry delay in milliseconds.
 */
public RetryStrategy(final int retryCount, final int retryDelay) {
    Validate.isTrue(retryCount > -1, "Retry count has to be a positive number - given value %d.", retryCount);
    Validate.isTrue(retryDelay > -1, "Retry delay has to be a positive number - given value %d.", retryDelay);
    this.retryCount = retryCount;
    this.retryDelay = retryDelay;
    this.currentRetryCount = 0;
}