Example usage for com.google.common.base Preconditions checkArgument

List of usage examples for com.google.common.base Preconditions checkArgument

Introduction

In this page you can find the example usage for com.google.common.base Preconditions checkArgument.

Prototype

public static void checkArgument(boolean expression) 

Source Link

Document

Ensures the truth of an expression involving one or more parameters to the calling method.

Usage

From source file:org.mule.tools.module.helper.Strings.java

public static String capitalize(final String string) {
    Preconditions.checkArgument(!com.google.common.base.Strings.isNullOrEmpty(string));

    return new StringBuilder(string.length()).append(Character.toTitleCase(string.charAt(0)))
            .append(string.substring(1)).toString();
}

From source file:org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction.java

public static CanCommitTransaction fromSerializable(Object serializable) {
    Preconditions.checkArgument(serializable instanceof CanCommitTransaction);
    return (CanCommitTransaction) serializable;
}

From source file:org.obiba.opal.web.gwt.app.client.support.BookmarkHelper.java

public static PlaceRequest createPlaceRequest(@NotNull LinkDto linkDto) {
    Preconditions.checkArgument(linkDto != null);
    return createPlaceRequest(linkDto.getRel());
}

From source file:edu.byu.nlp.util.ColumnMajorMatrices.java

public static void normalizeRows(double[] weights, int numRows) {
    Preconditions.checkNotNull(weights);
    Preconditions.checkArgument(weights.length % numRows == 0);

    int rowLength = weights.length / numRows;
    double[] rowSums = new double[numRows];
    int index = 0;
    for (int col = 0; col < rowLength; col++) {
        for (int row = 0; row < numRows; row++) {
            rowSums[row] += weights[index++];
        }// ww  w .  ja v  a 2 s.  co m
    }

    index = 0;
    for (int col = 0; col < rowLength; col++) {
        for (int row = 0; row < rowSums.length; row++) {
            weights[index++] /= rowSums[row];
        }
    }
}

From source file:com.github.fommil.ff.Utils.java

/**
 * @param min//w w  w.j  a  v a2s. c  o m
 * @param value
 * @param max
 * @return
 */
public static int bounded(int min, int value, int max) {
    Preconditions.checkArgument(max >= min);
    return Math.max(min, Math.min(value, max));
}

From source file:org.trancecode.base.TcPreconditions.java

public static void checkNotEmpty(final String string) {
    Preconditions.checkArgument(!Preconditions.checkNotNull(string).isEmpty());
}

From source file:com.facebook.buck.model.BuildTargetFactory.java

public static BuildTarget newInstance(String fullyQualifiedName) {
    String[] parts = fullyQualifiedName.split(":");
    Preconditions.checkArgument(parts.length == 2);
    String[] nameAndFlavor = parts[1].split("#");
    if (nameAndFlavor.length != 2) {
        return new BuildTarget(parts[0], parts[1]);
    }/*from ww w. java2s  . com*/
    return new BuildTarget(parts[0], nameAndFlavor[0], nameAndFlavor[1]);
}

From source file:org.ros.math.CollectionMath.java

public static <T extends Comparable<? super T>> T median(Collection<T> collection) {
    Preconditions.checkArgument(collection.size() > 0);
    List<T> list = Lists.newArrayList(collection);
    Collections.sort(list);/*from  w  w  w .j a v a  2 s.c om*/
    return list.get(list.size() / 2);
}

From source file:org.apache.druid.collections.spatial.RTreeUtils.java

public static double getEnclosingArea(Node a, Node b) {
    Preconditions.checkArgument(a.getNumDims() == b.getNumDims());

    double[] minCoords = new double[a.getNumDims()];
    double[] maxCoords = new double[a.getNumDims()];

    for (int i = 0; i < minCoords.length; i++) {
        minCoords[i] = Math.min(a.getMinCoordinates()[i], b.getMinCoordinates()[i]);
        maxCoords[i] = Math.max(a.getMaxCoordinates()[i], b.getMaxCoordinates()[i]);
    }//from   ww w.j  a  v  a  2 s. c om

    double area = 1.0;
    for (int i = 0; i < minCoords.length; i++) {
        area *= (maxCoords[i] - minCoords[i]);
    }

    return area;
}

From source file:edu.umd.cs.psl.optimizer.NumericUtilities.java

public static boolean equals(double[] val1, double[] val2) {
    Preconditions.checkArgument(val1.length == val2.length);
    for (int i = 0; i < val1.length; i++) {
        if (!equals(val1[i], val2[i]))
            return false;
    }/*from  w ww.  j av  a2s.  c  o m*/
    return true;
}