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; }
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; } }
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(); }
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])); }
public synchronized File getProjectDirectory() { checkState(state == State.STARTED); return projectDirectory; }
/** * 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); }
@Override public Builder setScopes(Collection<String> scopes) { Preconditions.checkState(!scopes.isEmpty()); return (Builder) super.setScopes(scopes); }
public ModifyAckDeadline(String ackId, long seconds) { Preconditions.checkNotNull(ackId); this.ackId = ackId; this.seconds = seconds; }
/** * 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); } }
/** * 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(); } }
@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()); } }
/** * 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; } }
/** * 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; }
@Override public Builder setClientAuthentication(HttpExecuteInterceptor clientAuthentication) { Preconditions.checkArgument(clientAuthentication == null); return this; }
/** * 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); }
/** 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; }
/** * @param accountManager account manager */ public GoogleAccountManager(AccountManager accountManager) { this.manager = Preconditions.checkNotNull(accountManager); }
/** * 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; }
/** * 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; }
/** * 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; }