當前位置: 首頁>>代碼示例>>Java>>正文


Java StringUtility類代碼示例

本文整理匯總了Java中com.google.cloud.backend.config.StringUtility的典型用法代碼示例。如果您正苦於以下問題:Java StringUtility類的具體用法?Java StringUtility怎麽用?Java StringUtility使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StringUtility類屬於com.google.cloud.backend.config包,在下文中一共展示了StringUtility類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createPayload

import com.google.cloud.backend.config.StringUtility; //導入依賴的package包/類
/**
 * Create a payload to be sent to client device.
 *
 * @param alertMessage Message that is visible to end user
 * @param hiddenMessage Message that is invisible to end user
 * @return a push notification payload to send to client device
 */
public PushNotificationPayload createPayload(String alertMessage,
    String hiddenMessage) {
  if (StringUtility.isNullOrEmpty(alertMessage) || StringUtility.isNullOrEmpty(hiddenMessage)) {
    throw new IllegalArgumentException("Input arguments cannot be a null or an empty String");
  }

  PushNotificationPayload payload = new PushNotificationPayload();

  try {
    payload.addAlert(alertMessage);
    payload.addCustomDictionary("hiddenMessage", hiddenMessage);
  } catch (JSONException e) {
    log.warning(e.getClass().toString() + " " + e.getMessage());
  }

  return payload;
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:25,代碼來源:Sender.java

示例2: doPost

import com.google.cloud.backend.config.StringUtility; //導入依賴的package包/類
/**
 * Handles the POST request from Task Queue
 */
@Override
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
  String type = req.getParameter("type");
  if (StringUtility.isNullOrEmpty(type)) {
    throw new IllegalArgumentException("Parameter 'type' cannot be null or empty.");
  }

  if (SubscriptionUtility.REQUEST_TYPE_DEVICE_SUB.compareTo(type) == 0) {
    removeDeviceSubscription(req);
  } else if (SubscriptionUtility.REQUEST_TYPE_PSI_SUB.compareTo(type) == 0) {
    removePsiSubscription(req);
  } else {
    throw new IllegalArgumentException("Invalid value of parameter 'type'.");
  }
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:19,代碼來源:SubscriptionRemovalServlet.java

示例3: validateBucketAndObjectPath

import com.google.cloud.backend.config.StringUtility; //導入依賴的package包/類
private void validateBucketAndObjectPath(String bucketName, String objectPath)
  throws BadRequestException {
  if (StringUtility.isNullOrEmpty(bucketName) || StringUtility.isNullOrEmpty(objectPath)) {
    throw new BadRequestException("BucketName and objectPath cannot be null");
  }

  if (bucketName.contains("/")) {
    throw new BadRequestException("Invalid bucketName");
  }

  if (objectPath.startsWith("/") || objectPath.endsWith("/")) {
    // The client library should have validated/normalized the object path before calling the
    // backend.
    throw new BadRequestException("Invalid objectPath");
  }
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:17,代碼來源:BlobEndpoint.java

示例4: get

import com.google.cloud.backend.config.StringUtility; //導入依賴的package包/類
/**
 * Returns an entity with device subscription information from memcache or datastore based on the
 *     provided deviceId.
 *
 * @param deviceId A unique device identifier
 * @return an entity with device subscription information; or null when no corresponding
 *         information found
 */
public Entity get(String deviceId) {
  if (StringUtility.isNullOrEmpty(deviceId)) {
    throw new IllegalArgumentException("DeviceId cannot be null or empty");
  }
  Key key = getKey(deviceId);
  Entity entity = (Entity) this.memcacheService.get(key);

  // Get from datastore if unable to get data from cache
  if (entity == null) {
    try {
      entity = this.datastoreService.get(key);
    } catch (EntityNotFoundException e) {
      return null;
    }
  }

  return entity;
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:27,代碼來源:DeviceSubscription.java

示例5: getSubscriptionIds

import com.google.cloud.backend.config.StringUtility; //導入依賴的package包/類
/**
 * Returns a set of subscriptions subscribed from the device.
 *
 * @param deviceId A unique device identifier 
 */
public Set<String> getSubscriptionIds(String deviceId) {
  if (StringUtility.isNullOrEmpty(deviceId)) {
    return new HashSet<String>();
  }
  Entity deviceSubscription = get(deviceId);

  if (deviceSubscription == null) {
    return new HashSet<String>();
  }

  String subscriptionString = (String) deviceSubscription.getProperty(PROPERTY_SUBSCRIPTION_IDS);
  if (StringUtility.isNullOrEmpty(subscriptionString)) {
    return new HashSet<String>();
  }

  return this.gson.fromJson(subscriptionString, setType);
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:23,代碼來源:DeviceSubscription.java

示例6: validateBucketAndObjectPath

import com.google.cloud.backend.config.StringUtility; //導入依賴的package包/類
private void validateBucketAndObjectPath(String bucketName, String objectPath)
    throws BadRequestException {
  if (StringUtility.isNullOrEmpty(bucketName) || StringUtility.isNullOrEmpty(objectPath)) {
    throw new BadRequestException("BucketName and objectPath cannot be null");
  }

  if (bucketName.contains("/")) {
    throw new BadRequestException("Invalid bucketName");
  }

  if (objectPath.startsWith("/") || objectPath.endsWith("/")) {
    // The client library should have validated/normalized the object path before calling the
    // backend.
    throw new BadRequestException("Invalid objectPath");
  }
}
 
開發者ID:googlearchive,項目名稱:solutions-mobile-backend-starter-java,代碼行數:17,代碼來源:BlobEndpoint.java

示例7: removeDeviceSubscription

import com.google.cloud.backend.config.StringUtility; //導入依賴的package包/類
/**
 * Remove device subscription entities based on input parameters
 * @param req Http request contains parameters 'cursor' and 'timeStamp'. 'Cursor'
 *            provides hint to last query result position.  'TimeStamp' filters out
 *            entities created after delete method was initiated.
 */
private void removeDeviceSubscription(HttpServletRequest req) {
  String cursorParameter = req.getParameter("cursor");
  if (cursorParameter == null) {
    log.warning("Missing 'cursor' argument on task queue request. This indicates a bug.");
    return;
  }

  if (cursorParameter.isEmpty()) {
    backendConfigManager.setLastSubscriptionDeleteAllTime(
        Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime());
  }

  String timeParameter = req.getParameter("timeStamp");
  if (StringUtility.isNullOrEmpty(timeParameter)) {
    log.warning("Missing 'timeStamp' argument on task queue request. " +
        "This indicates a bug.");
    return;
  }

  Date time;
  try {
    time = gson.fromJson(timeParameter, Date.class);
  } catch (JsonSyntaxException e) {
    log.warning("Invalid format of 'timeStamp' argument on task queue request. " +
        "This indicates a bug: " + timeParameter);
    return;
  }

  deviceSubscription.deleteAllContinuously(time, cursorParameter);
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:37,代碼來源:SubscriptionRemovalServlet.java

示例8: extractRegId

import com.google.cloud.backend.config.StringUtility; //導入依賴的package包/類
/**
 * Extracts device registration id from subscription id.
 *
 * @param subId Subscription id sent by client during query subscription
 * @return Device registration id
 */
public static String extractRegId(String subId) {
  if (StringUtility.isNullOrEmpty(subId)) {
    throw new IllegalArgumentException("subId cannot be null or empty");
  }
  String[] tokens = subId.split(":");
  return tokens[0].replaceFirst(IOS_DEVICE_PREFIX, "");
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:14,代碼來源:SubscriptionUtility.java

示例9: constructSubId

import com.google.cloud.backend.config.StringUtility; //導入依賴的package包/類
/**
 * Constructs subscription id based on registration id and query id.
 *
 * @param regId Registration id provided by the client
 * @param queryId Query id provided by the client
 * @return
 */
public static String constructSubId(String regId, String queryId) {
  if (StringUtility.isNullOrEmpty(regId) || StringUtility.isNullOrEmpty(queryId)) {
    throw new IllegalArgumentException("regId and queryId cannot be null or empty");
  }

  // ProsSearch subId = <regId>:query:<clientSubId>
  return regId + ":" + GCM_TYPEID_QUERY + ":" + queryId;
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:16,代碼來源:SubscriptionUtility.java

示例10: delete

import com.google.cloud.backend.config.StringUtility; //導入依賴的package包/類
/**
 * Deletes an entity corresponding to the provided deviceId.
 *
 * @param deviceId the device id for which all subscription information are to be deleted
 */
public void delete(String deviceId) {
  if (StringUtility.isNullOrEmpty(deviceId)) {
    throw new IllegalArgumentException("deviceId cannot be null or empty.");
  }

  Key key = getKey(deviceId);
  this.datastoreService.delete(key);
  this.memcacheService.delete(key);
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:15,代碼來源:DeviceSubscription.java

示例11: deleteAllContinuously

import com.google.cloud.backend.config.StringUtility; //導入依賴的package包/類
/**
 * Deletes all device subscription entities continuously using task push queue.
 *
 * @param time Threshold time before which entities created will be deleted. If time is null,
 *             current time is used and set as Threshold time.
 * @param cursor Query cursor indicates last query result set position
 */
protected void deleteAllContinuously(Date time, String cursor) {
  if (time == null) {
    time = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();
  }

  Query.FilterPredicate timeFilter = new Query.FilterPredicate(PROPERTY_TIMESTAMP,
      FilterOperator.LESS_THAN_OR_EQUAL, time);
  QueryResultIterable<Entity> entities;
  List<Key> keys = new ArrayList<Key> ();
  List<String> subIds = new ArrayList<String> ();
  Query queryAll;

  queryAll = new Query(DeviceSubscription.SUBSCRIPTION_KIND).setFilter(timeFilter);
  FetchOptions options = FetchOptions.Builder.withLimit(BATCH_DELETE_SIZE);
  if (!StringUtility.isNullOrEmpty(cursor)) {
    options.startCursor(Cursor.fromWebSafeString(cursor));
  }

  entities = this.datastoreService.prepare(queryAll).asQueryResultIterable(options);
  if (entities != null && entities.iterator() != null) {
    for (Entity entity : entities) {
      keys.add(entity.getKey());
      String[] ids = new Gson().fromJson((String) entity.getProperty(PROPERTY_SUBSCRIPTION_IDS),
          String[].class);
      subIds.addAll(Arrays.asList(ids));
    }
  }

  if (keys.size() > 0) {
    deleteInBatch(keys);
    enqueueDeleteDeviceSubscription(time, entities.iterator().getCursor().toWebSafeString());
  }
  if (subIds.size() > 0) {
    deletePsiSubscriptions(subIds);
  }
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:44,代碼來源:DeviceSubscription.java

示例12: getKey

import com.google.cloud.backend.config.StringUtility; //導入依賴的package包/類
/**
 * Gets a key for subscription kind entity based on device id.
 *
 * @param deviceId A unique device identifier
 */
protected Key getKey(String deviceId) {
  if (StringUtility.isNullOrEmpty(deviceId)) {
    throw new IllegalArgumentException("deviceId cannot be null or empty");
  } else {
    return KeyFactory.createKey(SUBSCRIPTION_KIND, deviceId);
  }
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:13,代碼來源:DeviceSubscription.java

示例13: create

import com.google.cloud.backend.config.StringUtility; //導入依賴的package包/類
/**
 * Creates an entity to persist a subscriptionID subscribed by a specific device.
 *
 * @param deviceType device type according to platform
 * @param deviceId unique device identifier
 * @param subscriptionId subscription identifier subscribed by this specific device
 * @return a datastore entity
 */
public Entity create(SubscriptionUtility.MobileType deviceType, String deviceId,
    String subscriptionId) {
  if (StringUtility.isNullOrEmpty(deviceId) || StringUtility.isNullOrEmpty(subscriptionId)) {
    return null;
  }

  Key key;
  String newDeviceId = SubscriptionUtility.extractRegId(deviceId);
  Entity deviceSubscription = get(newDeviceId);
  // Subscriptions is a "set" instead of a "list" to ensure uniqueness of each subscriptionId
  // for a device
  Set<String> subscriptions = new HashSet<String>();

  if (deviceSubscription == null) {
    // Create a brand new one
    key = getKey(newDeviceId);
    deviceSubscription = new Entity(key);
    deviceSubscription.setProperty(PROPERTY_ID, newDeviceId);
    deviceSubscription.setProperty(PROPERTY_DEVICE_TYPE, deviceType.toString());
  } else {
    key = deviceSubscription.getKey();

    // Update the existing subscription list
    String ids = (String) deviceSubscription.getProperty(PROPERTY_SUBSCRIPTION_IDS);
    if (!StringUtility.isNullOrEmpty(ids)) {
      subscriptions = this.gson.fromJson(ids, setType);
    }
  }

  // Update entity subscription property and save only when subscriptionId has successfully added
  // to the subscriptions "set".  If a subscriptionId is a duplicate of an existing subscription
  // in the set, we don't save this duplicated value into the entity.
  if (subscriptions.add(subscriptionId)) {
    deviceSubscription.setProperty(PROPERTY_SUBSCRIPTION_IDS, this.gson.toJson(subscriptions));
    Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    deviceSubscription.setProperty(PROPERTY_TIMESTAMP, time.getTime());

    this.datastoreService.put(deviceSubscription);
    this.memcacheService.put(key, deviceSubscription);
  }

  return deviceSubscription;
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:52,代碼來源:DeviceSubscription.java


注:本文中的com.google.cloud.backend.config.StringUtility類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。