本文整理汇总了Java中com.google.api.client.repackaged.com.google.common.base.Preconditions.checkArgument方法的典型用法代码示例。如果您正苦于以下问题:Java Preconditions.checkArgument方法的具体用法?Java Preconditions.checkArgument怎么用?Java Preconditions.checkArgument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.repackaged.com.google.common.base.Preconditions
的用法示例。
在下文中一共展示了Preconditions.checkArgument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
* Performs all necessary setup steps for running requests against the API.
*
* @param applicationName the name of the application: com.example.app
* @param serviceAccountEmail the Service Account Email (empty if using
* installed application)
* @return the {@Link AndroidPublisher} service
* @throws GeneralSecurityException
* @throws IOException
*/
public static AndroidPublisher init(String applicationName,
@Nullable String serviceAccountEmail) throws IOException, GeneralSecurityException {
Preconditions.checkArgument(!Strings.isNullOrEmpty(applicationName),
"applicationName cannot be null or empty!");
// Authorization.
newTrustedTransport();
Credential credential;
if (serviceAccountEmail == null || serviceAccountEmail.isEmpty()) {
//TODO : ask for the service account and key.p12 file with a dialog ;)
credential = authorizeWithServiceAccount(serviceAccountEmail);
} else {
credential = authorizeWithServiceAccount(serviceAccountEmail);
}
// Set up and return API client.
return new AndroidPublisher.Builder(
HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(applicationName)
.build();
}
示例2: parseJsonRequest
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
* Parse HttpServletRequest to JSON-RPC request
* Assumed the request content is encoded with UTF-8
* @param request HttpServletRequest
* @return JSONRPC2Request
* @throws IOException
*/
protected JSONRPC2Request parseJsonRequest(HttpServletRequest request) throws IOException, JSONRPC2ParseException {
String contentType = request.getHeader("Content-Type");
Integer contentLength = Ints.tryParse(request.getHeader("Content-Length"));
Preconditions.checkArgument(requestValidator(contentType, contentLength), "Invalid JSON request");
BufferedReader reader = request.getReader();
StringBuffer message = new StringBuffer();
char[] buffer = new char[contentLength];
int numRead = 0;
while (numRead < contentLength) {
int read = reader.read(buffer, 0, buffer.length);
String s = new String(buffer, 0, read);
numRead += s.getBytes(Charsets.UTF_8).length;
message.append(s);
}
return JSONRPC2Request.parse(message.toString(), true, true, true);
}
示例3: adapt
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public RowFilter adapt(FilterAdapterContext context, FuzzyRowFilter filter) throws IOException {
Interleave.Builder interleaveBuilder = Interleave.newBuilder();
List<Pair<byte[], byte[]>> pairs = extractFuzzyRowFilterPairs(filter);
if (pairs.isEmpty()) {
return ALL_VALUES_FILTER;
}
for (Pair<byte[], byte[]> pair : pairs) {
Preconditions.checkArgument(
pair.getFirst().length == pair.getSecond().length,
"Fuzzy info and match mask must have the same length");
interleaveBuilder.addFilters(
createSingleRowFilter(
pair.getFirst(), pair.getSecond()));
}
return RowFilter.newBuilder().setInterleave(interleaveBuilder).build();
}
示例4: init
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
* Performs all necessary setup steps for running requests against the API.
*
* @param applicationName the name of the application: com.example.app
* @param serviceAccountEmail the Service Account Email (empty if using
* installed application)
* @return the {@Link AndroidPublisher} service
* @throws GeneralSecurityException
* @throws IOException
*/
protected static AndroidPublisher init(String applicationName,
@Nullable String serviceAccountEmail) throws IOException, GeneralSecurityException {
Preconditions.checkArgument(!Strings.isNullOrEmpty(applicationName),
"applicationName cannot be null or empty!");
// Authorization.
newTrustedTransport();
Credential credential;
if (serviceAccountEmail == null || serviceAccountEmail.isEmpty()) {
credential = authorizeWithInstalledApplication();
} else {
credential = authorizeWithServiceAccount(serviceAccountEmail);
}
// Set up and return API client.
return new AndroidPublisher.Builder(
HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(applicationName)
.build();
}
示例5: getAndVerifyExtension
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
private AndroidPublisherExtension getAndVerifyExtension() {
AndroidPublisherExtension publisherExtension = getProject().getExtensions()
.getByType(AndroidPublisherExtension.class);
Preconditions.checkArgument(!Strings.isNullOrEmpty(
publisherExtension.getApplicationName()),
"Application name cannot be null or empty!");
Preconditions.checkArgument(!Strings.isNullOrEmpty(
publisherExtension.getTrack()),
"Track cannot be null or empty!");
Preconditions.checkArgument(!Strings.isNullOrEmpty(
publisherExtension.getVariantName()),
"Variant name cannot be null or empty!");
Preconditions.checkArgument(!Strings.isNullOrEmpty(
publisherExtension.getPackageName()),
"Package name cannot be null or empty!");
Preconditions.checkArgument(!Strings.isNullOrEmpty(
publisherExtension.getServiceAccountEmail()),
"Service account email cannot be null or empty!");
Preconditions.checkArgument(publisherExtension.getServiceAccountKeyFile() != null,
"Service account key file cannot be null or empty!");
return publisherExtension;
}
示例6: getPages
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public List<String> getPages(String siteProperty, String startDate, String endDate, String country, int rowLimit,
List<GoogleWebmasterFilter.Dimension> requestedDimensions, List<ApiDimensionFilter> filters, int startRow)
throws IOException {
checkRowLimit(rowLimit);
Preconditions.checkArgument(requestedDimensions.contains(GoogleWebmasterFilter.Dimension.PAGE));
SearchAnalyticsQueryResponse rspByCountry =
createSearchAnalyticsQuery(siteProperty, startDate, endDate, requestedDimensions,
GoogleWebmasterFilter.andGroupFilters(filters), rowLimit, startRow).execute();
List<ApiDataRow> pageRows = rspByCountry.getRows();
List<String> pages = new ArrayList<>(rowLimit);
if (pageRows != null) {
int pageIndex = requestedDimensions.indexOf(GoogleWebmasterFilter.Dimension.PAGE);
for (ApiDataRow row : pageRows) {
pages.add(row.getKeys().get(pageIndex));
}
}
return pages;
}
示例7: init
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
* Performs all necessary setup steps for running requests against the API.
*
* @param applicationName the name of the application: com.example.app
* @param serviceAccountEmail the Service Account Email (empty if using
* installed application)
* @return the {@Link AndroidPublisher} service
* @throws GeneralSecurityException
* @throws IOException
*/
protected static AndroidPublisher init(String applicationName,
@Nullable String serviceAccountEmail) throws IOException, GeneralSecurityException {
Preconditions.checkArgument(!Strings.isNullOrEmpty(applicationName),
"applicationName cannot be null or empty!");
// Authorization.
newTrustedTransport();
Credential credential;
if (serviceAccountEmail == null || serviceAccountEmail.isEmpty()) {
credential = authorizeWithInstalledApplication();
} else {
credential = authorizeWithServiceAccount(serviceAccountEmail);
}
// Set up and return API client.
return new AndroidPublisher.Builder(
HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(applicationName)
.build();
}
示例8: unbzip2Project
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public void unbzip2Project(
String projectName,
InputStream dataStream
) throws IOException {
Preconditions.checkArgument(
Project.isValidProjectName(projectName),
"[%s] invalid project name: ",
projectName
);
Preconditions.checkState(
getDirForProject(projectName).mkdirs(),
"[%s] directories for " +
"evicted project already exist",
projectName
);
Tar.bz2.unzip(dataStream, getDirForProject(projectName));
}
示例9: addTarDir
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
private static void addTarDir(
TarArchiveOutputStream tout,
Path base,
File dir
) throws IOException {
Preconditions.checkArgument(dir.isDirectory());
String name = base.relativize(
Paths.get(dir.getAbsolutePath())
).toString();
ArchiveEntry entry = tout.createArchiveEntry(dir, name);
tout.putArchiveEntry(entry);
tout.closeArchiveEntry();
for (File f : dir.listFiles()) {
addTarEntry(tout, base, f);
}
}
示例10: makeDirContents
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
private GitDirectoryContents makeDirContents(
String... contents
) {
Preconditions.checkArgument(contents.length % 2 == 0);
List<RawFile> files = new ArrayList<>(contents.length / 2);
for (int i = 0; i + 1 < contents.length; i += 2) {
files.add(
new RepositoryFile(
contents[i],
contents[i + 1].getBytes(StandardCharsets.UTF_8)
)
);
}
return new GitDirectoryContents(
files,
repoStore.getRootDirectory(),
"repo",
"Winston Li",
"[email protected]",
"Commit Message",
new Date()
);
}
示例11: FlyKit
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
public FlyKit(boolean allowFlight, @Nullable Boolean flying, float flySpeedMultiplier) {
Preconditions.checkArgument(flying == null || !(flying && !allowFlight), "Flying cannot be true if allow-flight is false");
this.allowFlight = allowFlight;
this.flying = flying;
this.flySpeedMultiplier = flySpeedMultiplier;
}
示例12: init
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
public static AndroidPublisher init(Context context, String fileName) throws IOException {
Preconditions.checkArgument(!Strings.isNullOrEmpty(context.getPackageName()), "applicationId cannot be null or empty!");
newTrustedTransport();
GoogleCredential credential = GoogleCredential.fromStream(context.getAssets().open(fileName), HTTP_TRANSPORT, JSON_FACTORY);
credential = credential.createScoped(Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER));
return new AndroidPublisher.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
.setApplicationName(context.getPackageName())
.build();
}
示例13: build
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
public HttpsConfiguration build()
{
Preconditions.checkArgument(!(httpsConf.serverKeystorePath == null ^ httpsConf.serverKeystorePassword == null),
"Both or neither of EXHIBITOR_TLS_SERVER_KEYSTORE_PATH and EXHIBITOR_TLS_SERVER_KEYSTORE_PASSWORD must be specified.");
Preconditions.checkArgument(!(httpsConf.clientKeystorePath == null ^ httpsConf.clientKeystorePassword == null),
"Both or neither of EXHIBITOR_TLS_CLIENT_KEYSTORE_PATH and EXHIBITOR_TLS_CLIENT_KEYSTORE_PASSWORD must be specified.");
Preconditions.checkArgument(!(httpsConf.truststorePath == null ^ httpsConf.truststorePassword == null),
"Both or neither of EXHIBITOR_TLS_TRUSTSTORE_PATH and EXHIBITOR_TLS_TRUSTSTORE_PASSWORD must be specified.");
Preconditions.checkArgument(httpsConf.serverKeystorePath == null || !httpsConf.verifyPeerCert
|| httpsConf.truststorePath != null,
"Verify peer cert requires truststore path and password to be specified.");
return httpsConf;
}
示例14: UnsupportedFilterException
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
public UnsupportedFilterException(List<FilterSupportStatus> filterSupportStatuses) {
super(String.format(
"Unsupported filters encountered: %s",
STATUS_JOINER.join(filterSupportStatuses)));
Preconditions.checkArgument(
!filterSupportStatuses.isEmpty(), "Unsupported statuses should not be empty.");
this.filterSupportStatuses = filterSupportStatuses;
}
示例15: collectUnsupportedStatuses
import com.google.api.client.repackaged.com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
* Collect unsupported status objects into the given list.
*/
public void collectUnsupportedStatuses(
FilterAdapterContext context,
Filter filter,
List<FilterSupportStatus> statuses) {
Preconditions.checkArgument(isFilterAProperSublcass(filter));
unsupportedStatusCollector.collectUnsupportedStatuses(
context,
unchecked(filter),
statuses);
}