本文整理汇总了Java中com.google.api.client.repackaged.com.google.common.base.Preconditions.checkNotNull方法的典型用法代码示例。如果您正苦于以下问题:Java Preconditions.checkNotNull方法的具体用法?Java Preconditions.checkNotNull怎么用?Java Preconditions.checkNotNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.repackaged.com.google.common.base.Preconditions
的用法示例。
在下文中一共展示了Preconditions.checkNotNull方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: indexParsedDocument
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
public void indexParsedDocument(ParsedComment document) {
Preconditions.checkNotNull(indexWriter,
"The index writer is not initialized");
Document newDoc = new Document();
newDoc.add(new TextField(ParsedComment.Fields.SEARCHABLE_TEXT.name(),
document.fullSearchableText(), Field.Store.YES));
newDoc.add(new StringField(ParsedComment.Fields.ID.name(),
document.getId(), Field.Store.YES));
newDoc.add(new StringField(ParsedComment.Fields.PRODUCT_NAME.name(),
document.getProductName(), Field.Store.YES));
newDoc.add(new StringField(ParsedComment.Fields.COMMENT.name(),
document.getComment(), Field.Store.YES));
newDoc.add(new StringField(ParsedComment.Fields.URL.name(),
document.getCommentUrl(), Field.Store.YES));
newDoc.add(new StringField(ParsedComment.Fields.SOURCE.name(),
document.getSource().name(), Field.Store.YES));
newDoc.add(new StringField(ParsedComment.Fields.LABEL.name(),
document.getCommentLabel(), Field.Store.YES));
try {
indexWriter.addDocument(newDoc);
indexWriter.commit();
} catch (IOException e) {
throw new RuntimeException(
"Could not write new document to the index directory", e);
}
}
示例2: ErrorReportDialog
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
public ErrorReportDialog (Stage owner, Collection<ErrorModel> errs) throws IOException {
super (owner) ;
Preconditions.checkNotNull(errs);
initStyle(StageStyle.UTILITY);
setTitle("Error Report");
initOwner(owner);
initModality (Modality.WINDOW_MODAL );
final FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/ErrorReportView.fxml"));
final Parent parent = (Parent) loader.load();
final ErrorReportViewController controller = loader.<ErrorReportViewController> getController();
controller.addErrors(errs);
setMinHeight(300.0);
setMinWidth(400.0);
setHeight(500.0);
setWidth(750.0);
setScene(new Scene(parent));
}
示例3: getHttpClient
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
public static CloseableHttpClient getHttpClient (HasProxySettings proxySetting) {
// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d5e475
CloseableHttpClient httpclient = null ;
if (proxySetting != null && proxySetting.isActive()) {
logger.info("Set the http proxy (" + proxySetting.getHost() + ":" + proxySetting.getPort() + ")") ;
CredentialsProvider credsProvider = Preconditions.checkNotNull(proxySetting.getCredentialsProvider()) ;
HttpHost proxy = new HttpHost(proxySetting.getHost(), proxySetting.getPort());
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
httpclient = HttpClients.custom()
.setRoutePlanner(routePlanner).setDefaultCredentialsProvider(credsProvider)
.build();
} else {
httpclient = HttpClients.createDefault();
}
return httpclient ;
}
示例4: DriveAuth
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
public DriveAuth(boolean useOldApi, HasConfiguration config) throws IOException {
super () ;
this.config = Preconditions.checkNotNull(config) ;
this.proxySetting = config.getHttpProxySettings() ;
clientSecret = config.getAuthenticationSettings().getClientSecret();
clientId = config.getAuthenticationSettings().getClientId();
config.getAuthenticationSettings().getCallBackUrl();
refreshToken = config.getCredential().getRefreshToken() ;
int retry = 0;
boolean tokensOK = false;
while (!tokensOK && retry < maxRetries) {
tokensOK = updateAccessToken();
++retry;
}
if (!tokensOK) {
logger.info("Authentication aborted after " + maxRetries + " retries.");
throw new IllegalStateException () ;
}
}
示例5: getExtractor
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
* As Google Drive extractor needs file system helper, it invokes to initialize file system helper.
* {@inheritDoc}
* @see org.apache.gobblin.source.Source#getExtractor(org.apache.gobblin.configuration.WorkUnitState)
*/
@Override
public Extractor<S, D> getExtractor(WorkUnitState state) throws IOException {
Preconditions.checkNotNull(state, "WorkUnitState should not be null");
LOG.info("WorkUnitState from getExtractor: " + state);
try {
//GoogleDriveExtractor needs GoogleDriveFsHelper
initFileSystemHelper(state);
} catch (FileBasedHelperException e) {
throw new IOException(e);
}
Preconditions.checkNotNull(fsHelper, "File system helper should not be null");
return new GoogleDriveExtractor<>(state, fsHelper);
}
示例6: getIndexWriter
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
* @return IndexWriter based on the Stop words provided
*/
private IndexWriter getIndexWriter() {
Preconditions.checkNotNull(indexDir, "No index directory specified!");
Preconditions.checkNotNull(enAnalyzer, "The English analyzer has not initialized.");
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_4_10_3, enAnalyzer);
try {
return new IndexWriter(indexDir, config);
} catch (IOException e) {
throw new RuntimeException("Unable to initialize index writer: ", e);
}
}
示例7: addErrors
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
public void addErrors (Collection<ErrorModel> errs) {
Preconditions.checkNotNull(tableErrorView) ;
Preconditions.checkNotNull(errs) ;
logger.info("Show erros");
final ObservableList<ErrorModel> data = tableErrorView.getItems();
for (ErrorModel err : errs) {
data.add(err) ;
}
}
示例8: evict
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
* @see SwapJob#evict(String) for high-level description.
*
* 1. Acquires the project lock.
* 2. Gets a bz2 stream and size of a project from the repo store, or throws
* 3. Uploads the bz2 stream and size to the projName in the swapStore.
* 4. Sets the last accessed time in the dbStore to null, which makes our
* state SWAPPED
* 5. Removes the project from the repo store.
* @param projName
* @throws IOException
*/
@Override
public void evict(String projName) throws IOException {
Preconditions.checkNotNull(projName, "projName was null");
Log.info("Evicting project: {}", projName);
try (LockGuard __ = lock.lockGuard(projName)) {
long[] sizePtr = new long[1];
try (InputStream blob = repoStore.bzip2Project(projName, sizePtr)) {
swapStore.upload(projName, blob, sizePtr[0]);
dbStore.setLastAccessedTime(projName, null);
repoStore.remove(projName);
}
}
Log.info("Evicted project: {}", projName);
}
示例9: TrackingEventBuilder
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
TrackingEventBuilder(SendsEvents eventSender, String category, String action) {
this.eventSender = Preconditions.checkNotNull(eventSender);
this.category = Preconditions.checkNotNull(category);
this.action = Preconditions.checkNotNull(action);
}
示例10: ErrorModel
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
public ErrorModel(Path srcPath, DriveDirectory destDir, Throwable err) {
this(Preconditions.checkNotNull(srcPath), Preconditions.checkNotNull(destDir), Preconditions.checkNotNull(err), null);
errStr.set(err.getMessage());
errLevelStr.set(ErrorLevel.ERROR.toString());
}
示例11: PlainTextContent
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
public PlainTextContent(String text) {
this.text = Preconditions.checkNotNull( text );
}
示例12: listFiles
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public Iterator<FileHeader> listFiles(String prefix, int limit) {
return new AbstractIterator<FileHeader>() {
String nextPageToken = null;
Iterator<FileHeader> currentBatch = null;
boolean done = false;
long remaining = limit;
@Override
protected FileHeader computeNext() {
if (currentBatch != null && currentBatch.hasNext()) {
return currentBatch.next();
} else if (done) {
return endOfData();
}
Objects result;
try {
result =
retry(
() -> {
costTracker.trackList();
Storage.Objects.List list = client.objects().list(bucket);
list.setPrefix(filePrefix + prefix);
list.setMaxResults(Math.min(1000, remaining));
list.setFields("nextPageToken,items(name,size,md5Hash,metadata/*)");
if (nextPageToken != null) {
list.setPageToken(nextPageToken);
}
return list.execute();
});
} catch (Exception e) {
throw new IllegalStateException(e);
}
Preconditions.checkNotNull(result);
List<FileHeader> batch = new ArrayList<>();
for (StorageObject object : result.getItems()) {
batch.add(toFile(object));
}
remaining -= batch.size();
currentBatch = batch.iterator();
if (batch.size() < 1000 || remaining <= 0) {
done = true;
nextPageToken = null;
} else {
nextPageToken = Preconditions.checkNotNull(result.getNextPageToken());
}
return computeNext();
}
};
}
示例13: WatchableObject
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
public WatchableObject(T object) {
this.object = Preconditions.checkNotNull(object);
}