List of usage examples for com.google.common.base Preconditions checkState
public static void checkState(boolean expression, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs)
From source file:com.facebook.buck.distributed.DistBuildSlaveTimingStatsTracker.java
public long getElapsedTimeMs(SlaveEvents event) { Stopwatch watch = Preconditions.checkNotNull(watches.get(event)); Preconditions.checkState(!watch.isRunning(), "Stopwatch for %s is still running.", event); return watch.elapsed(TimeUnit.MILLISECONDS); }
From source file:com.facebook.buck.java.abi.StubJar.java
public void writeTo(ProjectFilesystem filesystem, Path path) throws IOException { Preconditions.checkState(!filesystem.exists(path), "Output file already exists: %s)", path); if (path.getParent() != null && !filesystem.exists(path.getParent())) { filesystem.createParentDirs(path); }//w w w. j ava2 s .c om Walker walker = Walkers.getWalkerFor(toMirror); try (OutputStream fos = filesystem.newFileOutputStream(path); JarOutputStream jar = new JarOutputStream(fos)) { walker.walk(new FileAction() { @Override public void visit(Path relativizedPath, InputStream stream) throws IOException { String fileName = relativizedPath.toString(); if (!fileName.endsWith(".class")) { return; } ClassReader classReader = new ClassReader(stream); ClassMirror visitor = new ClassMirror(fileName); classReader.accept(visitor, SKIP_CODE | SKIP_DEBUG | SKIP_FRAMES); visitor.writeTo(jar); } }); } }
From source file:com.facebook.util.Validator.java
public void checkState(boolean expression, String message, Object... errorMessageArgs) throws T { try {/* ww w. j a v a 2s. co m*/ Preconditions.checkState(expression, message, errorMessageArgs); } catch (Exception e) { throw ExceptionUtils.wrap(e, clazz); } }
From source file:com.google.javascript.jscomp.DefaultExterns.java
/** * Filters and orders the passed externs for the specified environment. * * @param env The environment being used. * @param externs Flat tilename to source externs map. Must be mutable and will be modified. * @return Ordered list of externs./*from ww w . j a v a 2 s .co m*/ */ public static List<SourceFile> prepareExterns(CompilerOptions.Environment env, Map<String, SourceFile> externs) { List<SourceFile> out = new ArrayList<>(); for (String key : BUILTIN_LANG_EXTERNS) { Preconditions.checkState(externs.containsKey(key), "Externs must contain builtin: %s", key); out.add(externs.remove(key)); } if (env == CompilerOptions.Environment.BROWSER) { for (String key : BROWSER_EXTERN_DEP_ORDER) { Preconditions.checkState(externs.containsKey(key), "Externs must contain builtin for env %s: %s", env, key); out.add(externs.remove(key)); } out.addAll(externs.values()); } return out; }
From source file:com.facebook.swift.generator.TypedefRegistry.java
public void add(final SwiftJavaType type, final ThriftType thriftType) { Preconditions.checkState(!registry.containsKey(type.getKey()), "The type %s was already registered!", type); add(type.getKey(), thriftType);/*from w ww . j av a 2 s. c o m*/ }
From source file:de.cosmocode.rendering.DefaultListRenderer.java
@Override public List<Object> build() throws RenderingException { final Object list = super.build(); Preconditions.checkState(list instanceof List<?>, "Expected list, but was %s", list); return cast(list); }
From source file:com.android.build.gradle.internal.tasks.BaseTask.java
/** * Returns the androidBuilder./* w w w . jav a 2 s .c o m*/ * @throws IllegalStateException if androidBuilder has not been set, */ @NonNull protected AndroidBuilder getBuilder() { Preconditions.checkState(androidBuilder != null, "androidBuilder required for task '%s'.", getName()); return androidBuilder; }
From source file:de.cosmocode.rendering.DefaultMapRenderer.java
@Override public Map<CharSequence, Object> build() throws RenderingException { final Object map = super.build(); Preconditions.checkState(map instanceof Map<?, ?>, "Expected map, but was %s", map); return cast(map); }
From source file:org.opendaylight.netconf.mapping.api.HandlingPriority.java
public HandlingPriority increasePriority(int priorityIncrease) { Preconditions.checkState(priority != null, "Unable to increase priority for %s", this); Preconditions.checkArgument(priorityIncrease > 0, "Negative increase"); Preconditions.checkArgument(Long.valueOf(priority) + priorityIncrease < Integer.MAX_VALUE, "Resulting priority cannot be higher than %s", Integer.MAX_VALUE); return getHandlingPriority(priority + priorityIncrease); }
From source file:com.hubrick.raml.mojo.SpringWebGeneratorMojo.java
public void execute() throws MojoExecutionException { final JCodeModel codeModel = generateCodeModel(); Preconditions.checkState(outputDirectory.exists() || outputDirectory.mkdirs(), "Unable to create output directory: %s", outputDirectory.getPath()); try {/*from ww w . ja v a 2 s. co m*/ codeModel.build(outputDirectory); } catch (IOException e) { throw new RuntimeException(e); } }