Guava ImmutableMap.Builder - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava ImmutableMap.Builder class.

This code example shows how to use the following methods:build, put, putAll
   } 
 
   @Override 
   public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
      Builder<String, Object> payload = ImmutableMap.builder();
      payload.putAll(postParams); 
      checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
               "this binder is only valid for GeneratedHttpRequests!"); 
      GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
 
      Ingress ingress = Ingress.class.cast(find(gRequest.getInvocation().getArgs(), instanceOf(Ingress.class)));
      payload.put("ip_protocol", ingress.getIpProtocol().toString());
      payload.put("from_port", ingress.getFromPort() + "");
      payload.put("to_port", ingress.getToPort() + "");
 
      return super.bindToRequest(request, ImmutableMap.of("security_group_rule", payload.build()));
   } 
} 

8
CodeRank
This code example shows how to use the following methods:build, put
 
   @Override 
   public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
      Builder<String, String> databaseBuilder = ImmutableMap.builder();
 
      databaseBuilder.put("name", (String) postParams.get("database"));
 
      if (postParams.get("character_set") != null) { 
         databaseBuilder.put("character_set", (String) postParams.get("character_set"));
      } 
      if (postParams.get("collate") != null) { 
         databaseBuilder.put("collate", (String) postParams.get("collate"));
      } 
 
      return jsonBinder.bindToRequest(request, ImmutableMap.of("databases", ImmutableSet.of(databaseBuilder.build())));
   } 
 
   @Override 
   public <R extends HttpRequest> R bindToRequest(R request, Object toBind) {
      throw new IllegalStateException("Create database is a POST operation");

8
CodeRank
This code example shows how to use the following methods:build, put, putAll
                           .createTime(dateService.iso8601DateParse("2009-12-28T05:42:53.000Z")) 
                           .build(); 
    
   public void testCreateVolumeInAvailabilityZone() { 
      Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse>builder();
      builder.put(describeRegionsRequest, describeRegionsResponse);
      builder.putAll(describeAvailabilityZonesRequestResponse);
      builder.put(
            HttpRequest.builder()
                       .method("POST") 
                       .endpoint("https://ec2.us-east-1.amazonaws.com/") 
                       .addHeader("Host", "ec2.us-east-1.amazonaws.com") 
                       .payload(payloadFromStringWithContentType("Action=CreateVolume&AvailabilityZone=us-east-1a&Signature=FB5hTZHKSAuiygoafIdJh1EnfTu0ogC2VfRQOar85mg%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Size=4&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity", "application/x-www-form-urlencoded")).build(), 
            HttpResponse.builder()
                        .statusCode(200) 
                        .payload(payloadFromResource("/created_volume.xml")).build()); 
       
      ElasticBlockStoreClient client = requestsSendResponses(builder.build()).getElasticBlockStoreServices();
 
      assertEquals(client.createVolumeInAvailabilityZone("us-east-1a", 4), creating);

8
CodeRank
This code example shows how to use the following methods:build, put
      GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of(options));
 
      BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
 
      Builder<String, Object> map = ImmutableMap.builder();
      map.put("name", "new-linux-server"); 
      map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201"); 
      map.put("IsSourceDelete", "true"); 
      assertEquals(binder.bindToRequest(request, map.build()).getPayload().getRawContent(), expected);
   } 
 
   public void testDefault() throws Exception {
      String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp-default.xml"));
      GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of());
 
      BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
 
      Builder<String, Object> map = ImmutableMap.builder();
      map.put("name", "my-vapp"); 
      map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"); 

8
CodeRank
This code example shows how to use the following methods:build, put
   } 
 
   @Provides 
   public Map<Type, Object> provideCustomAdapterBindings() {
      return ImmutableMap.<Type, Object> builder()
            .put(ExtractArchiveResponse.class, new ExtractArchiveResponseAdapter()) 
            .put(BulkDeleteResponse.class, new BulkDeleteResponseAdapter()).build(); 
   } 
 
   static class ExtractArchiveResponseAdapter extends TypeAdapter<ExtractArchiveResponse> {
 
      @Override 
      public ExtractArchiveResponse read(JsonReader reader) throws IOException {
         int created = 0;
         Builder<String, String> errors = ImmutableMap.<String, String> builder();
         reader.beginObject();
         while (reader.hasNext()) {
            String key = reader.nextName();
            if (key.equals("Number Files Created")) {
               created = reader.nextInt();

7
CodeRank
This code example shows how to use the following methods:build, put, putAll
    */ 
   @VisibleForTesting 
   static <V> Map<String, V> renameKey(Map<String, V> in, String k1, String k2) {
      if (checkNotNull(in, "input map").containsKey(checkNotNull(k1, "old key"))) {
         Builder<String, V> builder = ImmutableMap.builder();
         builder.putAll(filterKeys(in, not(equalTo(k1))));
         V tags = in.get(k1);
         builder.put(checkNotNull(k2, "new key"), tags);
         in = builder.build();
      } 
      return in;
   } 
 
} 

8
CodeRank
This code example shows how to use the following methods:build, put
 
      BindCloneVAppTemplateParamsToXmlPayload binder = injector
            .getInstance(BindCloneVAppTemplateParamsToXmlPayload.class); 
 
      Builder<String, Object> map = ImmutableMap.builder();
      map.put("name", "new-linux-server"); 
      map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201"); 
      map.put("IsSourceDelete", "true"); 
 
      assertEquals(binder.bindToRequest(request, map.build()).getPayload().getRawContent(), expected);
   } 
 
   public void testDefault() throws IOException {
      String expected = toStringAndClose(getClass().getResourceAsStream("/copyVAppTemplate-default.xml"));
 
      GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of());
 
      BindCloneVAppTemplateParamsToXmlPayload binder = injector
            .getInstance(BindCloneVAppTemplateParamsToXmlPayload.class); 
 

8
CodeRank
This code example shows how to use the following methods:build, put, putAll
           .createTime(dateService.iso8601DateParse("2009-12-28T05:42:53.000Z")) 
           .build(); 
    
   public void testCreateVolumeInAvailabilityZone() { 
      Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse>builder();
      builder.put(describeRegionsRequest, describeRegionsResponse);
      builder.putAll(describeAvailabilityZonesRequestResponse);
      builder.put(
            HttpRequest.builder()
                       .method("POST") 
                       .endpoint("https://ec2.us-east-1.amazonaws.com/") 
                       .addHeader("Host", "ec2.us-east-1.amazonaws.com") 
                       .payload(payloadFromStringWithContentType("Action=CreateVolume&AvailabilityZone=us-east-1a&Signature=NCu8HU8u0A385rTgj%2BN5lq606jkc1eu88jof9yAxb6s%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Size=4&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-08-31&AWSAccessKeyId=identity", "application/x-www-form-urlencoded")).build(), 
            HttpResponse.builder()
                        .statusCode(200) 
                        .payload(payloadFromResource("/created_volume.xml")).build()); 
       
      ElasticBlockStoreApi client = requestsSendResponses(builder.build()).getElasticBlockStoreApi().get();
 
      assertEquals(client.createVolumeInAvailabilityZone("us-east-1a", 4), creating);

7
CodeRank
This code example shows how to use the following methods:build
      } 
      if (!md.getListableTags().isEmpty()) {
         String header = Joiner.on(',').join(md.getListableTags());
         headers.put("x-emc-listable-tags", header);
      } 
      return headers.build();
   } 
} 

6
CodeRank
This code example shows how to use the following methods:build
    @Override 
    protected LrsObject getLrsObject(PortalEvent event) {
        Builder<String, LocalizedString> definitionBuilder = ImmutableMap.builder();
        return new LrsObject(buildUrn("Login"), 
                getDefaultObjectType(), 
                definitionBuilder.build());
    } 
} 

6
CodeRank
See Code Examples for Guava ImmutableMap.Builder Methods: