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


Java ImmutableMap類代碼示例

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


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

示例1: getUploadUrl

import com.google.appengine.repackaged.com.google.common.collect.ImmutableMap; //導入依賴的package包/類
/**
 * Get an upload URL
 * @param req
 * @param resp
 * @throws ServletException
 * @throws IOException
 */
private void getUploadUrl(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  LOGGER.debug("Get blobstore upload url");

  String callback = req.getParameter(CALLBACK_PARAM);
  if (null == callback) {
    callback = req.getRequestURI();
  }

  String keepQueryParam = req.getParameter(KEEP_QUERY_PARAM);
  // Forward any existing query parameters, e.g. access_token
  if (null != keepQueryParam) {
    final String queryString = req.getQueryString();
    callback = String.format("%s?%s", callback, null != queryString ? queryString : "");
  }

  Map<String, String> response = ImmutableMap.of("uploadUrl", blobstoreService.createUploadUrl(callback));

  PrintWriter out = resp.getWriter();
  resp.setContentType(JsonCharacterEncodingResponseFilter.APPLICATION_JSON_UTF8);

  ObjectMapper mapper = new ObjectMapper();
  mapper.writeValue(out, response);

  out.close();
}
 
開發者ID:Wadpam,項目名稱:guja,代碼行數:33,代碼來源:GAEBlobServlet.java

示例2: createErrorToExceptionMap

import com.google.appengine.repackaged.com.google.common.collect.ImmutableMap; //導入依賴的package包/類
public static Map<RemoteApiPb.RpcError.ErrorCode, ApiProxyException> createErrorToExceptionMap() {
  return new ImmutableMap.Builder<RemoteApiPb.RpcError.ErrorCode, ApiProxyException>()
      .put(RemoteApiPb.RpcError.ErrorCode.UNKNOWN,
          new ApiProxy.UnknownException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.CALL_NOT_FOUND,
          new ApiProxy.CallNotFoundException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.PARSE_ERROR,
          new ApiProxy.ArgumentException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.SECURITY_VIOLATION,
          new ApiProxy.UnknownException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.OVER_QUOTA,
          new ApiProxy.OverQuotaException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.REQUEST_TOO_LARGE,
          new ApiProxy.RequestTooLargeException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(
          RemoteApiPb.RpcError.ErrorCode.CAPABILITY_DISABLED,
          new ApiProxy.CapabilityDisabledException(TEST_ERROR_MESSAGE, TEST_PACKAGE_NAME,
              TEST_METHOD_NAME))
      .put(
          RemoteApiPb.RpcError.ErrorCode.FEATURE_DISABLED,
          new ApiProxy.FeatureNotEnabledException(TEST_ERROR_MESSAGE, TEST_PACKAGE_NAME,
              TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.BAD_REQUEST,
          new ApiProxy.ArgumentException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.RESPONSE_TOO_LARGE,
          new ApiProxy.ResponseTooLargeException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.CANCELLED,
          new ApiProxy.CancelledException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.REPLAY_ERROR,
          new ApiProxy.UnknownException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.DEADLINE_EXCEEDED,
          new ApiProxy.ApiDeadlineExceededException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .build();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-vm-runtime,代碼行數:35,代碼來源:VmApiProxyDelegateTest.java

示例3: sendMessage

import com.google.appengine.repackaged.com.google.common.collect.ImmutableMap; //導入依賴的package包/類
/**
 * Send to the first NUMBER_OF_DEVICE devices (you can modify this to send
 * to any number of devices or a specific device).
 * @param payload The message to send
 * @throws java.io.IOException if unable to send the message.
 */
@ApiMethod(httpMethod = "POST")
public final void sendMessage(final ImmutableMap<String, String> payload)
        throws IOException {
    if (payload == null || payload.size() == 0) {
        LOG.warning("Not sending message because payload is empty");
        return;
    }

    Sender sender = new Sender(Constants.GCM_API_KEY);
    Message msg = new Message.Builder()
            .setData(payload)
            .build();
    List<Registration> records = ofy().load()
            .type(Registration.class).limit(NUMBER_OF_DEVICES)
            .list();
    for (Registration record : records) {
        Result result = sender.send(msg, record.getRegId(),
                MAXIMUM_RETRIES);
        if (result.getMessageId() != null) {
            LOG.info("Message sent to " + record.getRegId());
            String canonicalRegId = result.getCanonicalRegistrationId();
            if (canonicalRegId != null) {
                // if the regId changed, we have to update the datastore
                LOG.info("Registration Id changed for " + record.getRegId()
                        + " updating to "
                        + canonicalRegId);
                record.setRegId(canonicalRegId);
                ofy().save().entity(record).now();
            }
        } else {
            String error = result.getErrorCodeName();
            if (error.equals(com.google.android.gcm.server.
                    Constants.ERROR_NOT_REGISTERED)) {
                LOG.warning("Registration Id " + record.getRegId()
                        + " no longer registered with GCM, "
                        + "removing from datastore");
                // if the device is no longer registered with Gcm, remove it
                // from the datastore
                ofy().delete().entity(record).now();
            } else {
                LOG.warning("Error when sending message : " + error);
            }
        }
    }
}
 
開發者ID:googlearchive,項目名稱:MobileShoppingAssistant-sample,代碼行數:52,代碼來源:MessagingEndpoint.java


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