Code example for ImmutableMap.Builder

Methods: build, put

0
   } 
 
   @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();
            } else if (key.equals("Errors")) {
               readErrors(reader, errors);
            } else { 
               reader.skipValue();
            } 
         } 
         reader.endObject();
         return ExtractArchiveResponse.create(created, errors.build());
      } 
 
      @Override 
      public void write(JsonWriter arg0, ExtractArchiveResponse arg1) throws IOException {
         throw new UnsupportedOperationException();
      } 
   } 
 
   static class BulkDeleteResponseAdapter extends TypeAdapter<BulkDeleteResponse> {
 
      @Override 
      public BulkDeleteResponse read(JsonReader reader) throws IOException {
         int deleted = 0;
         int notFound = 0;
         Builder<String, String> errors = ImmutableMap.<String, String> builder();
         reader.beginObject();
         while (reader.hasNext()) {
            String key = reader.nextName();
            if (key.equals("Number Deleted")) {
               deleted = reader.nextInt();
            } else if (key.equals("Number Not Found")) {
               notFound = reader.nextInt();
            } else if (key.equals("Errors")) {
               readErrors(reader, errors);
            } else { 
               reader.skipValue();
            } 
         } 
         reader.endObject();
         return BulkDeleteResponse.create(deleted, notFound, errors.build());
      } 
 
      @Override 
      public void write(JsonWriter arg0, BulkDeleteResponse arg1) throws IOException {
         throw new UnsupportedOperationException();
      } 
   } 
 
   static void readErrors(JsonReader reader, Builder<String, String> errors) throws IOException {
      reader.beginArray();
      while (reader.hasNext()) {
         reader.beginArray();
         String decodedPath = URI.create(reader.nextString()).getPath();
         errors.put(decodedPath, reader.nextString());
         reader.endArray();
      } 
      reader.endArray();
   } 
 
} 
Experience pair programming with AI  Get Codota for Java