List of usage examples for com.google.common.base Preconditions checkState
public static void checkState(boolean expression, @Nullable Object errorMessage)
From source file:com.cloudera.oryx.als.serving.MultiRescorer.java
/** * @param rescorers {@link com.cloudera.oryx.als.common.Rescorer} objects to delegate to *///from w w w . j a v a2s. co m public MultiRescorer(List<Rescorer> rescorers) { Preconditions.checkNotNull(rescorers); Preconditions.checkState(!rescorers.isEmpty(), "rescorers is empty"); this.rescorers = rescorers.toArray(new Rescorer[rescorers.size()]); }
From source file:org.sonar.javascript.cfg.BranchingBlock.java
@Override public Set<MutableBlock> successors() { Preconditions.checkState(trueSuccessor != null, "Successors were not set on " + this); return ImmutableSet.of(trueSuccessor, falseSuccessor); }
From source file:org.openqa.selenium.firefox.Executable.java
public Executable(File userSpecifiedBinaryPath) { Preconditions.checkState(userSpecifiedBinaryPath != null, "Path to the firefox binary should not be null"); Preconditions.checkState(userSpecifiedBinaryPath.exists() && userSpecifiedBinaryPath.isFile(), "Specified firefox binary location does not exist or is not a real file: " + userSpecifiedBinaryPath); binary = userSpecifiedBinaryPath;/*from w ww . ja va 2 s . c om*/ }
From source file:com.lyndir.lanterna.view.TitledView.java
@Override public void addChild(final View child) { Preconditions.checkState(getChildren().isEmpty(), "Can only add a single child to a titled view."); super.addChild(child); }
From source file:com.facebook.buck.rules.AbstractSourcePath.java
@SuppressWarnings("unchecked") @Override/*w w w . j a va2s . c o m*/ public int compareTo(SourcePath o) { if (o == this) { return 0; } int result = this.getClass().getName().compareTo(o.getClass().getName()); if (result != 0) { return result; } Preconditions.checkState(this.getClass().equals(o.getClass()), "Classes are different but have the same name."); return this.compareReferences((T) o); }
From source file:org.opendaylight.controller.sal.restconf.impl.EmptyNodeWrapper.java
@Override public void setQname(final QName name) { Preconditions.checkState(unwrapped == null, "Cannot change the object, due to data inconsistencies."); this.name = name; }
From source file:com.google.cloud.hadoop.fs.gcs.ListHelperGoogleHadoopFileSystem.java
/** * Factory method for constructing and initializing an instance of * ListHelperGoogleHadoopFileSystem which is ready to list/get FileStatus entries corresponding * to {@code fileInfos}./*from ww w. j av a2 s .co m*/ */ public static GoogleHadoopFileSystem createInstance(GoogleCloudStorageFileSystem gcsfs, Collection<FileInfo> fileInfos) throws IOException { Preconditions.checkState(!fileInfos.isEmpty(), "Cannot construct ListHelperGoogleHadoopFileSystem with empty fileInfos list!"); List<GoogleCloudStorageItemInfo> infos = new ArrayList<>(); URI rootUri = null; Set<URI> providedPaths = new HashSet<>(); for (FileInfo info : fileInfos) { infos.add(info.getItemInfo()); providedPaths.add(info.getPath()); if (rootUri == null) { // Set the root URI to the first path in the collection. rootUri = info.getPath(); } } // The flow for populating this doesn't bother to populate metadata entries for parent // directories but we know the parent directories are expected to exist, so we'll just // populate the missing entries explicitly here. Necessary for getFileStatus(parentOfInfo) // to work when using an instance of this class. for (FileInfo info : fileInfos) { URI parentPath = gcsfs.getParentPath(info.getPath()); while (parentPath != null && !parentPath.equals(GoogleCloudStorageFileSystem.GCS_ROOT)) { if (!providedPaths.contains(parentPath)) { LOG.debug("Adding fake entry for missing parent path '{}'", parentPath); GoogleCloudStorageItemInfo fakeInfo = new GoogleCloudStorageItemInfo( gcsfs.getPathCodec().validatePathAndGetId(parentPath, true), 0, 0, null, null); infos.add(fakeInfo); providedPaths.add(parentPath); } parentPath = gcsfs.getParentPath(parentPath); } } // Add in placeholder bucket info, since the bucket info won't be relevant for our listObject // operations. String tempBucket = rootUri.getAuthority(); infos.add(new GoogleCloudStorageItemInfo(new StorageResourceId(tempBucket), 0, 0, "", "")); MetadataReadOnlyGoogleCloudStorage tempGcs = new MetadataReadOnlyGoogleCloudStorage(infos); GoogleCloudStorageFileSystem tempGcsFs = new GoogleCloudStorageFileSystem(tempGcs, gcsfs.getOptions()); GoogleHadoopFileSystem tempGhfs = new ListHelperGoogleHadoopFileSystem(tempGcsFs); Configuration tempConfig = new Configuration(); tempConfig.set(GoogleHadoopFileSystemBase.GCS_SYSTEM_BUCKET_KEY, tempBucket); tempConfig.setBoolean(GoogleHadoopFileSystemBase.GCS_CREATE_SYSTEM_BUCKET_KEY, false); tempConfig.set(GoogleHadoopFileSystemBase.GCS_WORKING_DIRECTORY_KEY, "/"); // Set initSuperclass == false to avoid screwing up FileSystem statistics. tempGhfs.initialize(rootUri, tempConfig, false); return tempGhfs; }
From source file:com.continuuity.weave.internal.utils.Instances.java
/** * Creates a new instance of the given class. It will use the default constructor if it is presents. * Otherwise it will try to use {@link sun.misc.Unsafe#allocateInstance(Class)} to create the instance. * @param clz Class of object to be instantiated. * @param <T> Type of the class/* ww w . j ava 2 s.c o m*/ * @return An instance of type {@code <T>} */ @SuppressWarnings("unchecked") public static <T> T newInstance(Class<T> clz) { try { try { Constructor<T> cons = clz.getDeclaredConstructor(); if (!cons.isAccessible()) { cons.setAccessible(true); } return cons.newInstance(); } catch (Exception e) { // Try to use Unsafe Preconditions.checkState(UNSAFE != null, "Fail to instantiate with Unsafe."); return (T) UNSAFE_NEW_INSTANCE.invoke(UNSAFE, clz); } } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:ezbatch.amino.job.WarehausAminoJob.java
@Override public JobOutputEstimate getJobEstimate() { Preconditions.checkState(config != null, "Configuration has not been set"); return config.getEnum(CFG_JOB_ESTIMATE, JobOutputEstimate.MEDIUM); }
From source file:org.soundboard.library.SoundLibrarian.java
private static SoundLibrary newSoundLibrary(String libraryName) { SoundLibrary lib = (SoundLibrary) SoundboardConfiguration.config().getClassProperty("SoundLibrary.impl"); Preconditions.checkState(lib != null, "Error: MISSING SoundLibrary implementation ('SoundLibrary.impl')"); lib.setName(libraryName);//from w ww . java 2s.c om return lib; }