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.ros.message.MessageDefinition.java

public static MessageDefinition newFromHeader(Map<String, String> header) {
    Preconditions.checkArgument(header.containsKey(ConnectionHeaderFields.TYPE));
    Preconditions.checkArgument(header.containsKey(ConnectionHeaderFields.MD5_CHECKSUM));
    return new MessageDefinition(header.get(ConnectionHeaderFields.TYPE), null,
            header.get(ConnectionHeaderFields.MD5_CHECKSUM));
}

From source file:net.sourceforge.cilib.functions.continuous.moo.wfg.Misc.java

public static double correct_to_01(double a, double epsilon) {
    Preconditions.checkArgument(epsilon >= 0.0);

    double min = 0.0;
    double max = 1.0;

    double min_epsilon = min - epsilon;
    double max_epsilon = max + epsilon;

    if (a <= min && a >= min_epsilon) {
        return min;
    } else if (a >= max && a <= max_epsilon) {
        return max;
    } else {//from   w  w w  .  ja v  a2 s  . com
        return a;
    }
}

From source file:org.projectbuendia.client.utils.LexicographicVersion.java

/** Returns an instance of {@link LexicographicVersion} parsed from the specified string. */
public static LexicographicVersion parse(String raw) {
    Preconditions.checkNotNull(raw);//from   w w  w  . j  a v a2  s  .  com
    Preconditions.checkArgument(!raw.equals(""));

    String[] stringParts = raw.split("\\.");
    int[] parts = new int[stringParts.length];
    for (int i = 0; i < stringParts.length; i++) {
        try {
            parts[i] = Integer.parseInt(stringParts[i]);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("'" + raw + "' is not a valid version string.", e);
        }
    }

    return new LexicographicVersion(raw, parts);
}

From source file:qa.qcri.nadeef.core.datamodel.MemoryTable.java

public static MemoryTable of(List<Tuple> tuples) {
    Preconditions.checkArgument(tuples != null && tuples.size() > 0);
    return new MemoryTable(tuples);
}

From source file:com.aerofs.baseline.config.Intervals.java

static long parseFrom(String interval) {
    Preconditions.checkArgument(!interval.isEmpty());

    if (!Pattern.matches("[0-9]+[smhd]?", interval)) {
        throw new ValidationException("bad interval:" + interval);
    }//from ww  w . j av  a  2s. com

    long numericInterval;

    char lastChar = interval.charAt(interval.length() - 1);
    if (Character.isDigit(lastChar)) {
        numericInterval = Long.parseLong(interval);
    } else {
        numericInterval = Long.parseLong(interval.substring(0, interval.length() - 1));
    }

    long intervalInMillis;

    switch (lastChar) {
    case 's':
        intervalInMillis = MILLISECONDS.convert(numericInterval, SECONDS);
        break;
    case 'm':
        intervalInMillis = MILLISECONDS.convert(numericInterval, MINUTES);
        break;
    case 'h':
        intervalInMillis = MILLISECONDS.convert(numericInterval, HOURS);
        break;
    case 'd':
        intervalInMillis = MILLISECONDS.convert(numericInterval, DAYS);
        break;
    default:
        intervalInMillis = Long.parseLong(interval);
        break;
    }

    return intervalInMillis;
}

From source file:com.textocat.textokit.commons.util.UimaResourceUtils.java

public static File resolveFile(String path, ResourceManager resMgr)
        throws URISyntaxException, MalformedURLException {
    Preconditions.checkArgument(path != null);
    if (resMgr == null) {
        resMgr = UIMAFramework.newDefaultResourceManager();
    }/*from   w  w w.  j av  a 2s.c  o  m*/
    URL modelBaseURL = resMgr.resolveRelativePath(path);
    if (modelBaseURL == null)
        throw new IllegalStateException(
                format("Can't resolve path %s using an UIMA relative path resolver", path));
    return new File(modelBaseURL.toURI());
}

From source file:org.sonar.flex.checks.utils.Clazz.java

public static List<AstNode> getDirectives(AstNode classDefNode) {
    Preconditions.checkArgument(classDefNode.is(FlexGrammar.CLASS_DEF));
    return classDefNode.getFirstChild(FlexGrammar.BLOCK).getFirstChild(FlexGrammar.DIRECTIVES)
            .getChildren(FlexGrammar.DIRECTIVE);
}

From source file:org.janusgraph.util.encoding.StringEncoding.java

public static int writeAsciiString(byte[] array, int startPos, String attribute) {
    Preconditions.checkArgument(isAsciiString(attribute));
    if (attribute.length() == 0) {
        array[startPos++] = (byte) 0x80;
    } else {//w  w w  . j a  v a 2 s .  c o  m
        for (int i = 0; i < attribute.length(); i++) {
            int c = attribute.charAt(i);
            assert c <= 127;
            byte b = (byte) c;
            if (i + 1 == attribute.length())
                b |= 0x80; //End marker
            array[startPos++] = b;
        }
    }
    return startPos;
}

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

/**
 * @param min//  w  w w .  j  a  v a  2s.com
 * @param value
 * @param max
 * @return
 */
public static double bounded(double min, double value, double max) {
    Preconditions.checkArgument(max >= min);
    return Math.max(min, Math.min(value, max));
}

From source file:com.cloudera.nav.sdk.model.custom.MetaClassPackage.java

public static MetaClassPackage newPackage(String name) {
    Preconditions.checkArgument(StringUtils.isNotEmpty(name));
    MetaClassPackage pkg = new MetaClassPackage();
    pkg.setName(name);/* ww  w  .j a  v a2  s  . c o  m*/
    return pkg;
}