本文整理了Java中com.google.api.client.util.Preconditions
类的一些代码示例,展示了Preconditions
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Preconditions
类的具体详情如下:
包路径:com.google.api.client.util.Preconditions
类名称:Preconditions
暂无
代码示例来源:origin: pentaho/pentaho-kettle
public final DataStore<V> set( String key, V value ) throws IOException {
Preconditions.checkNotNull( key );
Preconditions.checkNotNull( value );
this.lock.lock();
try {
this.keyValueMap.put( key, IOUtils.serialize( value ) );
this.save();
} finally {
this.lock.unlock();
}
return this;
}
代码示例来源:origin: googleapis/google-cloud-java
static <T extends Option.OptionType> Map<Option.OptionType, ?> optionMap(Option... options) {
Map<Option.OptionType, Object> optionMap = Maps.newHashMap();
for (Option option : options) {
Object prev = optionMap.put(option.getOptionType(), option.getValue());
checkArgument(prev == null, "Duplicate option %s", option);
}
return optionMap;
}
}
代码示例来源:origin: googleads/aw-reporting
public void setBackoffInterval(Integer backoffInterval) {
Preconditions.checkNotNull(backoffInterval, "backoffInterval cannot be null.");
Preconditions.checkArgument(backoffInterval >= 0, "backoffInterval must be non-negative.");
this.backoffInterval = backoffInterval.intValue();
}
代码示例来源:origin: com.google.cloud.genomics/google-genomics-dataflow
public static GraphResult fromString(String tsv) {
Preconditions.checkNotNull(tsv);
String[] tokens = tsv.split("[\\s\t]+");
Preconditions.checkState(3 == tokens.length,
"Expected three values in serialized GraphResult but found %d", tokens.length);
return new GraphResult(tokens[0],
Double.parseDouble(tokens[1]),
Double.parseDouble(tokens[2]));
}
代码示例来源:origin: com.google.cloud.datastore/datastore-v1-proto-client
public synchronized File getProjectDirectory() {
checkState(state == State.STARTED);
return projectDirectory;
}
代码示例来源:origin: googleads/aw-reporting
/**
* Factory method to create a DateRange instance.
* @param dateRange the date range string, either in "yyyyMMdd,yyyyMMdd" format, or some
* ReportDefinitionDateRangeType enum value (such as "LAST_7_DAYS")
* @return the DateRange object
*/
public static DateRangeAndType fromString(final String dateRange) {
Preconditions.checkNotNull(dateRange, "DateRange cannot be null.");
Preconditions.checkArgument(!dateRange.isEmpty(), "DateRange cannot be empty.");
return dateRange.contains(",") ? parseCustomFormat(dateRange) : parseEnumFormat(dateRange);
}
代码示例来源:origin: com.google.api-client/google-api-client
@Override
public Builder setScopes(Collection<String> scopes) {
Preconditions.checkState(!scopes.isEmpty());
return (Builder) super.setScopes(scopes);
}
代码示例来源:origin: googleapis/google-cloud-java
public ModifyAckDeadline(String ackId, long seconds) {
Preconditions.checkNotNull(ackId);
this.ackId = ackId;
this.seconds = seconds;
}
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
/**
* A command-line handler to display the bucket passed in as an argument.
*
* @param args the array of command-line arguments.
*/
public static void main(final String[] args) {
try {
// Check for valid setup.
Preconditions.checkArgument(
args.length == 1,
"Please pass in the Google Cloud Storage bucket name to display");
String bucketName = args[0];
String content = listBucket(bucketName);
prettyPrintXml(bucketName, content);
System.exit(0);
} catch (IOException e) {
System.err.println(e.getMessage());
} catch (Throwable t) {
t.printStackTrace();
}
System.exit(1);
}
}
代码示例来源:origin: com.google.oauth-client/google-oauth-client-appengine
/**
* Return the user id for the currently logged in user.
*/
static final String getUserId() {
UserService userService = UserServiceFactory.getUserService();
User loggedIn = userService.getCurrentUser();
Preconditions.checkState(loggedIn != null, "This servlet requires the user to be logged in.");
return loggedIn.getUserId();
}
}
代码示例来源:origin: google/data-transfer-project
@Override
public ReservedWorker handle(GetReservedWorker workerRequest) {
String id = workerRequest.getId();
UUID jobId = decodeJobId(id);
PortabilityJob job = jobStore.findJob(jobId);
Preconditions.checkNotNull(
job, "Couldn't lookup worker for job " + id + " because the job doesn't exist");
if (job.jobAuthorization().state() != CREDS_ENCRYPTION_KEY_GENERATED) {
monitor.debug(
() -> format("Job %s has not entered state CREDS_ENCRYPTION_KEY_GENERATED yet", jobId));
return new ReservedWorker(null);
}
monitor.debug(
() ->
format(
"Got job %s in state CREDS_ENCRYPTION_KEY_GENERATED, returning its public key",
jobId));
return new ReservedWorker(job.jobAuthorization().authPublicKey());
}
}
代码示例来源:origin: google/google-api-java-client-samples
/**
* Lists all DFA user profiles associated with your Google Account.
*
* @param reporting Dfareporting service object on which to run the requests.
* @return the list of user profiles received.
* @throws Exception
*/
public static UserProfileList list(Dfareporting reporting) throws Exception {
System.out.println("=================================================================");
System.out.println("Listing all DFA user profiles");
System.out.println("=================================================================");
// Retrieve DFA user profiles and display them. User profiles do not support
// paging.
UserProfileList profiles = reporting.userProfiles().list().execute();
Preconditions.checkArgument(
profiles.getItems() != null && !profiles.getItems().isEmpty(), "No profiles found");
for (UserProfile userProfile : profiles.getItems()) {
System.out.printf("User profile with ID \"%s\" and name \"%s\" was found.%n",
userProfile.getProfileId(), userProfile.getUserName());
}
System.out.println();
return profiles;
}
}
代码示例来源:origin: com.google.api-client/google-api-client
/**
* Sets the notification channel UUID provided by the client in the watch request.
*
* <p>
* Overriding is only supported for the purpose of calling the super implementation and changing
* the return type, but nothing else.
* </p>
*/
public AbstractNotification setChannelId(String channelId) {
this.channelId = Preconditions.checkNotNull(channelId);
return this;
}
代码示例来源:origin: com.google.api-client/google-api-client
@Override
public Builder setClientAuthentication(HttpExecuteInterceptor clientAuthentication) {
Preconditions.checkArgument(clientAuthentication == null);
return this;
}
代码示例来源:origin: com.google.api-client/google-api-client
/**
* Returns an instance of a new builder.
*
* @param transport HTTP transport
* @param jsonFactory JSON factory
*/
public Builder(HttpTransport transport, JsonFactory jsonFactory) {
this.transport = Preconditions.checkNotNull(transport);
this.jsonFactory = Preconditions.checkNotNull(jsonFactory);
}
代码示例来源:origin: com.google.api-client/google-api-client
/** Returns the details for either installed or web applications. */
public Details getDetails() {
// that web or installed, but not both
Preconditions.checkArgument((web == null) != (installed == null));
return web == null ? installed : web;
}
代码示例来源:origin: com.google.api-client/google-api-client-android
/**
* @param accountManager account manager
*/
public GoogleAccountManager(AccountManager accountManager) {
this.manager = Preconditions.checkNotNull(accountManager);
}
代码示例来源:origin: com.google.api-client/google-api-client
/**
* Sets the maximum size of individual chunks that will get downloaded by single HTTP requests.
* The default value is {@link #MAXIMUM_CHUNK_SIZE}.
*
* <p>
* The maximum allowable value is {@link #MAXIMUM_CHUNK_SIZE}.
* </p>
*/
public MediaHttpDownloader setChunkSize(int chunkSize) {
Preconditions.checkArgument(chunkSize > 0 && chunkSize <= MAXIMUM_CHUNK_SIZE);
this.chunkSize = chunkSize;
return this;
}
代码示例来源:origin: com.google.api-client/google-api-client
/**
* Sets the {@link ResourceStates resource state}.
*
* <p>
* Overriding is only supported for the purpose of calling the super implementation and changing
* the return type, but nothing else.
* </p>
*/
public AbstractNotification setResourceState(String resourceState) {
this.resourceState = Preconditions.checkNotNull(resourceState);
return this;
}
代码示例来源:origin: com.google.api-client/google-api-client
/**
* Sets the message number (a monotonically increasing value starting with 1).
*
* <p>
* Overriding is only supported for the purpose of calling the super implementation and changing
* the return type, but nothing else.
* </p>
*/
public AbstractNotification setMessageNumber(long messageNumber) {
Preconditions.checkArgument(messageNumber >= 1);
this.messageNumber = messageNumber;
return this;
}
内容来源于网络,如有侵权,请联系作者删除!