Code example for ImmutableMap.Builder

Methods: build, put

0
 
   @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");
   } 
}