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:qa.qcri.nadeef.core.datamodel.TuplePair.java

/**
 * Factory method.//w  w  w  .ja  va2  s .c o  m
 * @param values values.
 * @return new TuplePair.
 */
public static TuplePair of(Tuple[] values) {
    Preconditions.checkArgument(values != null && values.length == 2);
    return new TuplePair(values[0], values[1]);
}

From source file:com.google.devtools.build.lib.skyframe.TransitiveTargetKey.java

public static SkyKey of(Label label) {
    Preconditions.checkArgument(!label.getPackageIdentifier().getRepository().isDefault());
    return new TransitiveTargetKey(label);
}

From source file:com.google.template.soy.jssrc.dsl.Conditional.java

static Conditional create(ImmutableList<IfThenPair> conditions, @Nullable CodeChunk trailingElse) {
    Preconditions.checkArgument(!conditions.isEmpty());
    return new AutoValue_Conditional(conditions, trailingElse);
}

From source file:com.cloudera.oryx.ml.param.RandomSearch.java

/**
 * @param ranges ranges of hyperparameters to try, one per hyperparameters
 * @param howMany how many combinations of hyperparameters to return
 * @return combinations of concrete hyperparameter values
 *///ww  w  . j av a2  s . co m
static List<List<?>> chooseHyperParameterCombos(Collection<? extends HyperParamValues<?>> ranges, int howMany) {
    Preconditions.checkArgument(howMany > 0);

    int numParams = ranges.size();
    if (numParams == 0) {
        return Collections.singletonList(Collections.emptyList());
    }

    RandomDataGenerator rdg = new RandomDataGenerator(RandomManager.getRandom());
    List<List<?>> allCombinations = new ArrayList<>(howMany);
    for (int i = 0; i < howMany; i++) {
        List<Object> combination = new ArrayList<>(numParams);
        for (HyperParamValues<?> range : ranges) {
            combination.add(range.getRandomValue(rdg));
        }
        allCombinations.add(combination);
    }

    return allCombinations;
}

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

public static MetaClass newClass(String packageName, String name) {
    Preconditions.checkArgument(StringUtils.isNotEmpty(packageName));
    Preconditions.checkArgument(StringUtils.isNotEmpty(name));
    MetaClass metaClass = new MetaClass();
    metaClass.setPackageName(packageName);
    metaClass.setName(name);//from   w w w. ja v  a2  s. c om
    return metaClass;
}

From source file:tech.tablesaw.util.DoubleArrays.java

public static double[][] to2dArray(NumericColumn<?>... columns) {
    Preconditions.checkArgument(columns.length >= 1);
    int obs = columns[0].size();
    double[][] allVals = new double[obs][columns.length];

    for (int r = 0; r < obs; r++) {
        for (int c = 0; c < columns.length; c++) {
            allVals[r][c] = columns[c].getDouble(r);
        }//from ww w .j  a va  2s .c o m
    }
    return allVals;
}

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

public static Vector normalise_z(Vector z, Vector z_max) {
    Vector.Builder result = Vector.newBuilder();
    for (int i = 0; i < z.size(); i++) {
        Preconditions.checkArgument(z.doubleValueOf(i) >= 0.0);
        Preconditions.checkArgument(z.doubleValueOf(i) <= z_max.doubleValueOf(i));
        Preconditions.checkArgument(z_max.doubleValueOf(i) > 0.0);
        result.add(z.doubleValueOf(i) / z_max.doubleValueOf(i));
    }/*w  w w .j  a va  2  s.  c om*/
    return result.build();
}

From source file:com.cloudera.flume.master.SaveConfigCommand.java

/**
 * Actual Command execution.//from w  w w  .j  ava  2  s  .  c om
 */
public static Execable buildExecable() {
    return new Execable() {
        @Override
        public void exec(String[] argv) throws IOException {
            Preconditions.checkArgument(argv.length == 1);
            String configFileName = argv[0];
            FlumeMaster master = FlumeMaster.getInstance();
            try {
                master.getSpecMan().saveConfigFile(configFileName);
            } catch (IOException e) {
                LOG.error("Save Config " + configFileName + " failed", e);
                throw e;
            }
        }
    };
}

From source file:io.druid.query.topn.TopNQueryRunnerTestHelper.java

public static Result<TopNResultValue> createExpectedRows(String date, String[] columnNames,
        Iterable<Object[]> values) {
    List<Map> expected = Lists.newArrayList();
    for (Object[] value : values) {
        Preconditions.checkArgument(value.length == columnNames.length);
        Map<String, Object> theVals = Maps.newHashMapWithExpectedSize(value.length);
        for (int i = 0; i < columnNames.length; i++) {
            theVals.put(columnNames[i], value[i]);
        }//  w  ww  .  ja  va  2s.  c o  m
        expected.add(theVals);
    }
    return new Result<TopNResultValue>(new DateTime(date), new TopNResultValue(expected));
}

From source file:com.google.gerrit.common.RawInputUtil.java

public static RawInput create(final byte[] bytes, final String contentType) {
    Preconditions.checkNotNull(bytes);//from  ww w.ja v  a2  s. c o  m
    Preconditions.checkArgument(bytes.length > 0);
    return new RawInput() {
        @Override
        public InputStream getInputStream() throws IOException {
            return new ByteArrayInputStream(bytes);
        }

        @Override
        public String getContentType() {
            return contentType;
        }

        @Override
        public long getContentLength() {
            return bytes.length;
        }
    };
}