List of usage examples for com.google.common.base Preconditions checkArgument
public static void checkArgument(boolean expression)
From source file:edu.byu.nlp.classify.NaiveBayesClassifier.java
public static NaiveBayesClassifier newClassifier(double[] logPOfY, double[] logPOfXGivenY, boolean copy) { Preconditions.checkNotNull(logPOfY); Preconditions.checkNotNull(logPOfXGivenY); Preconditions.checkArgument(logPOfXGivenY.length % logPOfY.length == 0); if (copy) {//w w w . ja va2s. c o m logPOfY = logPOfY.clone(); logPOfXGivenY = logPOfXGivenY.clone(); } return new NaiveBayesClassifier(logPOfY, logPOfXGivenY); }
From source file:org.apache.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]); }//from w w w . j a v a 2s .c o m expected.add(theVals); } return new Result<TopNResultValue>(DateTimes.of(date), new TopNResultValue(expected)); }
From source file:org.eclipse.buildship.core.util.file.RelativePathUtils.java
/** * Calculates the relative path from a base to a target path. * * @param base the base path to make the target path relative to * @param target the target file to which the relative path is calculated * @return the relative path from the base to the target location * @throws NullPointerException if an argument is {@code null} * @throws IllegalArgumentException if an argument does not denote an absolute path *//* w ww .j a va 2 s. com*/ public static IPath getRelativePath(IPath base, IPath target) { Preconditions.checkNotNull(base); Preconditions.checkNotNull(target); Preconditions.checkArgument(base.isAbsolute()); Preconditions.checkArgument(target.isAbsolute()); return target.makeRelativeTo(base); }
From source file:org.xacml4j.v30.types.DoubleExp.java
public static DoubleExp of(String v) { Preconditions.checkArgument(!Strings.isNullOrEmpty(v)); if (v.endsWith("INF")) { int infIndex = v.lastIndexOf("INF"); v = v.substring(0, infIndex) + "Infinity"; }//from w ww .ja va 2 s . c om return new DoubleExp(Double.parseDouble(v)); }
From source file:qa.qcri.qnoise.util.NoiseHelper.java
/** * Change cell value based on distance./*from w w w.ja v a2 s . c om*/ * @param distances the distance from the new value. * @param selectedColumns changed column names. * @param profile data profile. * @param rowIndex tuple index. */ public static void playTheJazz(@NotNull double[] distances, @NotNull String[] selectedColumns, DataProfile profile, int rowIndex, NoiseReport report) { Preconditions.checkArgument(distances.length > 0); String[] tuple = profile.getReadOnlyTuple(rowIndex); BiMap<String, Integer> indexes = profile.getIndexes(); HashMap<String, DataType> types = profile.getTypes(); for (int i = 0; i < selectedColumns.length; i++) { String columnName = selectedColumns[i]; int columnIndex = indexes.get(columnName); double distance = distances[i]; DataType type = types.get(columnName); String currentValue = tuple[columnIndex]; String newValue = ""; switch (type) { case Text: if (currentValue != null) { StringBuilder sb = new StringBuilder(currentValue); int len = (int) Math.floor(distance * sb.length()); // TODO: currently we start to mess the text from the 1st char. // It might be more reasonable to use a random gen. again to pick // the char to change. for (int j = 0; j < len; j++) { char c = sb.charAt(j); char nc = getRandomChar(); while (nc == c) { nc = getRandomChar(); } sb.setCharAt(j, nc); } newValue = sb.toString(); } break; case Numerical: double std = profile.getStandardDeviationOn(columnName); double nvalue = distance * std * getRandomSign() + Double.parseDouble(currentValue); newValue = Double.toString(nvalue); break; case Categorical: for (int j = 0; j < profile.getLength(); j++) { String t = profile.getCell(j, columnIndex); if (!t.equals(currentValue)) { newValue = t; break; } } break; default: throw new UnsupportedOperationException("Unknown type " + type); } Pair<Integer, Integer> index = new Pair<>(rowIndex, columnIndex); if (profile.set(index, newValue)) { tracer.infoChange(index, currentValue, newValue); report.logChange(index, tuple[columnIndex], newValue); } else { tracer.infoUnchange(index); } } }
From source file:net.sourceforge.cilib.functions.continuous.moo.wfg.ShapeFunctions.java
public static double linear(Vector x, int m) { Preconditions.checkArgument(shape_args_ok(x, m)); int M = x.size(); double result = 1.0; for (int i = 1; i <= M - m; i++) { result *= x.doubleValueOf(i - 1); }// w w w. j av a 2 s .com if (m != 1) { result *= 1 - x.doubleValueOf(M - m); } return Misc.correct_to_01(result); }
From source file:li.klass.fhem.util.BuildVersion.java
public static void execute(VersionDependent versionDependent, int buildVersion) { Preconditions.checkNotNull(versionDependent); Preconditions.checkArgument(buildVersion > 0); int apiVersion = android.os.Build.VERSION.SDK_INT; if (apiVersion >= buildVersion) { versionDependent.ifAboveOrEqual(); } else {/* ww w . jav a2 s. c o m*/ versionDependent.ifBelow(); } }
From source file:com.twitter.distributedlog.util.BitMaskUtils.java
/** * 1) Unset all bits where value in mask is set. * 2) Set these bits to value specified by newValue. * * e.g./*w w w .ja va 2 s . co m*/ * if oldValue = 1010, mask = 0011, newValue = 0001 * 1) 1010 -> 1000 * 2) 1000 -> 1001 * * @param oldValue expected old value * @param mask the mask of the value for updates * @param newValue new value to set * @return updated value */ public static long set(long oldValue, long mask, long newValue) { Preconditions.checkArgument(oldValue >= 0L && mask >= 0L && newValue >= 0L); return ((oldValue & (~mask)) | (newValue & mask)); }
From source file:com.facebook.buck.jvm.core.JavaAbis.java
public static BuildTarget getClassAbiJar(BuildTarget libraryTarget) { Preconditions.checkArgument(isLibraryTarget(libraryTarget)); return libraryTarget.withAppendedFlavors(CLASS_ABI_FLAVOR); }
From source file:com.kumbaya.dht.Values.java
public static String of(DHTValueEntity entity) { Preconditions.checkArgument(entity.getValue().getValueType() == DHTValueType.TEXT); return new String(entity.getValue().getValue()); }