com.google.api.client.util.Preconditions.checkState()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中com.google.api.client.util.Preconditions.checkState()方法的一些代码示例,展示了Preconditions.checkState()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Preconditions.checkState()方法的具体详情如下:
包路径:com.google.api.client.util.Preconditions
类名称:Preconditions
方法名:checkState

Preconditions.checkState介绍

暂无

代码示例

代码示例来源:origin: com.google.cloud.datastore/datastore-v1-proto-client

public synchronized File getProjectDirectory() {
 checkState(state == State.STARTED);
 return projectDirectory;
}

代码示例来源:origin: GoogleCloudPlatform/google-cloud-datastore

public synchronized File getProjectDirectory() {
 checkState(state == State.STARTED);
 return projectDirectory;
}

代码示例来源:origin: spotify/dbeam

static DateTime queryReplication(Connection connection, String query) throws SQLException {
 final ResultSet resultSet = connection.createStatement().executeQuery(query);
 Preconditions.checkState(resultSet.next(), "Replication query returned empty results");
 DateTime lastReplication = new DateTime(resultSet.getTimestamp("last_replication"));
 Duration replicationDelay = new Duration(resultSet.getLong("replication_delay"));
 LOGGER.info("Psql replication check lastReplication={} replicationDelay={}",
       lastReplication, replicationDelay);
 return lastReplication;
}

代码示例来源: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: 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: googlegenomics/dataflow-java

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.auth/google-auth-library-oauth2-http

/**
 * Constructor with all parameters allowing custom transport and server URL.
 *
 * @param clientId Client ID of the credential from the console.
 * @param clientSecret Client ID of the credential from the console.
 * @param refreshToken A refresh token resulting from a OAuth2 consent flow.
 * @param accessToken Initial or temporary access token.
 * @param transportFactory HTTP transport factory, creates the transport used to get access
 *        tokens.
 * @param tokenServerUri URI of the end point that provides tokens.
 * @deprecated Use {@link #newBuilder()} instead. This constructor will either be deleted or made
 *             private in a later version.
 */
@Deprecated
public UserCredentials(String clientId, String clientSecret, String refreshToken,
            AccessToken accessToken, HttpTransportFactory transportFactory, URI tokenServerUri) {
 super(accessToken);
 this.clientId = Preconditions.checkNotNull(clientId);
 this.clientSecret = Preconditions.checkNotNull(clientSecret);
 this.refreshToken = refreshToken;
 this.transportFactory = firstNonNull(transportFactory,
   getFromServiceLoader(HttpTransportFactory.class, OAuth2Utils.HTTP_TRANSPORT_FACTORY));
 this.tokenServerUri = (tokenServerUri == null) ? OAuth2Utils.TOKEN_SERVER_URI : tokenServerUri;
 this.transportFactoryClassName = this.transportFactory.getClass().getName();
 Preconditions.checkState(accessToken != null || refreshToken != null,
   "Either accessToken or refreshToken must not be null");
}

代码示例来源:origin: googleapis/google-auth-library-java

/**
 * Constructor with all parameters allowing custom transport and server URL.
 *
 * @param clientId Client ID of the credential from the console.
 * @param clientSecret Client ID of the credential from the console.
 * @param refreshToken A refresh token resulting from a OAuth2 consent flow.
 * @param accessToken Initial or temporary access token.
 * @param transportFactory HTTP transport factory, creates the transport used to get access
 *        tokens.
 * @param tokenServerUri URI of the end point that provides tokens.
 * @deprecated Use {@link #newBuilder()} instead. This constructor will either be deleted or made
 *             private in a later version.
 */
@Deprecated
public UserCredentials(String clientId, String clientSecret, String refreshToken,
            AccessToken accessToken, HttpTransportFactory transportFactory, URI tokenServerUri) {
 super(accessToken);
 this.clientId = Preconditions.checkNotNull(clientId);
 this.clientSecret = Preconditions.checkNotNull(clientSecret);
 this.refreshToken = refreshToken;
 this.transportFactory = firstNonNull(transportFactory,
   getFromServiceLoader(HttpTransportFactory.class, OAuth2Utils.HTTP_TRANSPORT_FACTORY));
 this.tokenServerUri = (tokenServerUri == null) ? OAuth2Utils.TOKEN_SERVER_URI : tokenServerUri;
 this.transportFactoryClassName = this.transportFactory.getClass().getName();
 Preconditions.checkState(accessToken != null || refreshToken != null,
   "Either accessToken or refreshToken must not be null");
}

代码示例来源: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: com.google.cloud.datastore/datastore-v1-proto-client

/**
 * Starts the emulator. It is the caller's responsibility to call {@link #stop}. Note that
 * receiving an exception does not indicate that the server did not start. We recommend calling
 * {@link #stop} to ensure the server is not running regardless of the result of this method.
 *
 * @param emulatorDir The path to the emulator directory, e.g. /usr/local/cloud-datastore-emulator
 * @param projectId The project ID
 * @param commandLineOptions Command line options to pass to the emulator on startup
 * @throws DatastoreEmulatorException If {@link #start} has already been called or the server does
 *     not start successfully.
 * @deprecated prefer setting options in the emulator options and calling {#start()}.
 */
@Deprecated
public synchronized void start(String emulatorDir, String projectId, String... commandLineOptions)
  throws DatastoreEmulatorException {
 checkNotNull(emulatorDir, "emulatorDir cannot be null");
 checkNotNull(projectId, "projectId cannot be null");
 checkState(state == State.NEW, "Cannot call start() more than once.");
 try {
  startEmulatorInternal(
    emulatorDir + "/cloud_datastore_emulator", projectId, Arrays.asList(commandLineOptions));
  state = State.STARTED;
 } finally {
  if (state != State.STARTED) {
   // If we're not able to start the server we don't want people trying again. Just move it
   // straight to the STOPPED state.
   state = State.STOPPED;
  }
 }
}

代码示例来源:origin: GoogleCloudPlatform/google-cloud-datastore

/**
 * Starts the emulator. It is the caller's responsibility to call {@link #stop}. Note that
 * receiving an exception does not indicate that the server did not start. We recommend calling
 * {@link #stop} to ensure the server is not running regardless of the result of this method.
 *
 * @param emulatorDir The path to the emulator directory, e.g. /usr/local/cloud-datastore-emulator
 * @param projectId The project ID
 * @param commandLineOptions Command line options to pass to the emulator on startup
 * @throws DatastoreEmulatorException If {@link #start} has already been called or the server does
 *     not start successfully.
 * @deprecated prefer setting options in the emulator options and calling {#start()}.
 */
@Deprecated
public synchronized void start(String emulatorDir, String projectId, String... commandLineOptions)
  throws DatastoreEmulatorException {
 checkNotNull(emulatorDir, "emulatorDir cannot be null");
 checkNotNull(projectId, "projectId cannot be null");
 checkState(state == State.NEW, "Cannot call start() more than once.");
 try {
  startEmulatorInternal(
    emulatorDir + "/cloud_datastore_emulator", projectId, Arrays.asList(commandLineOptions));
  state = State.STARTED;
 } finally {
  if (state != State.STARTED) {
   // If we're not able to start the server we don't want people trying again. Just move it
   // straight to the STOPPED state.
   state = State.STOPPED;
  }
 }
}

代码示例来源:origin: GoogleCloudPlatform/google-cloud-datastore

public synchronized void start() throws DatastoreEmulatorException {
 checkState(state == State.NEW, "Cannot call start() more than once.");
 try {
  startEmulatorInternal(options.getCmd(), options.getProjectId(), options.getCmdLineOptions());
  state = State.STARTED;
 } finally {
  if (state != State.STARTED) {
   // If we're not able to start the server we don't want people trying again. Just move it
   // straight to the STOPPED state.
   state = State.STOPPED;
  }
 }
}

代码示例来源:origin: com.google.cloud.datastore/datastore-v1-proto-client

public synchronized void start() throws DatastoreEmulatorException {
 checkState(state == State.NEW, "Cannot call start() more than once.");
 try {
  startEmulatorInternal(options.getCmd(), options.getProjectId(), options.getCmdLineOptions());
  state = State.STARTED;
 } finally {
  if (state != State.STARTED) {
   // If we're not able to start the server we don't want people trying again. Just move it
   // straight to the STOPPED state.
   state = State.STOPPED;
  }
 }
}

代码示例来源:origin: com.google.cloud.datastore/datastore-v1beta3-proto-client

/**
 * Starts the local datastore. It is the caller's responsibility to call {@link #stop}. Note that
 * receiving an exception does not indicate that the server did not start. We recommend calling
 * {@link #stop} to ensure the server is not running regardless of the result of this method.
 *
 * @param sdkPath The path to the GCD SDK, eg /usr/local/dev/gcd
 * @param projectId The GCD project ID
 * @param cmdLineOptions Command line options to pass to the script that launches the dev server
 * @throws LocalDevelopmentDatastoreException If {@link #start} has already been called or the
 * server does not start successfully.
 */
public synchronized void start(String sdkPath, String projectId, String... cmdLineOptions)
  throws LocalDevelopmentDatastoreException {
 Preconditions.checkNotNull(sdkPath, "sdkPath cannot be null");
 Preconditions.checkNotNull(projectId, "projectId cannot be null");
 Preconditions.checkState(state == State.NEW, "Cannot call start() more than once.");
 try {
  startDatastoreInternal(sdkPath, projectId, cmdLineOptions);
  state = State.STARTED;
 } finally {
  if (state != State.STARTED) {
   // If we're not able to start the server we don't want people trying again. Just move it
   // straight to the STOPPED state.
   state = State.STOPPED;
  }
 }
}

代码示例来源:origin: com.google.http-client/google-http-client-xml

throws XmlPullParserException {
int eventType = parser.getEventType();
Preconditions.checkState(eventType == XmlPullParser.START_TAG,
  "expected start of XML element, but got something else (event type %s)", eventType);
int depth = parser.getDepth();

代码示例来源:origin: com.google.api-client/google-api-client

Preconditions.checkState(
  currentBytesServerReceived >= 0 && currentBytesServerReceived <= currentChunkLength);
long copyBytes = currentChunkLength - currentBytesServerReceived;
  Preconditions.checkState(currentBytesServerReceived == actualSkipValue);

代码示例来源:origin: com.google.api-client/google-api-client

Preconditions.checkState(!requestInfos.isEmpty());
HttpRequest batchRequest = requestFactory.buildPostRequest(this.batchUrl, null);

相关文章