• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.appsearch.external.localstorage.converter;
18 
19 import android.annotation.NonNull;
20 import android.app.appsearch.SetSchemaResponse;
21 
22 import com.google.android.icing.proto.SetSchemaResultProto;
23 
24 import java.util.Objects;
25 
26 /**
27  * Translates a {@link SetSchemaResultProto} into {@link SetSchemaResponse}.
28  *
29  * @hide
30  */
31 public class SetSchemaResponseToProtoConverter {
32 
SetSchemaResponseToProtoConverter()33     private SetSchemaResponseToProtoConverter() {}
34 
35     /**
36      * Translate a {@link SetSchemaResultProto} into {@link SetSchemaResponse}.
37      *
38      * @param proto The {@link SetSchemaResultProto} containing results.
39      * @param prefix The prefix need to removed from schemaTypes
40      * @return The {@link SetSchemaResponse} object.
41      */
42     @NonNull
toSetSchemaResponse( @onNull SetSchemaResultProto proto, @NonNull String prefix)43     public static SetSchemaResponse toSetSchemaResponse(
44             @NonNull SetSchemaResultProto proto, @NonNull String prefix) {
45         Objects.requireNonNull(proto);
46         Objects.requireNonNull(prefix);
47         SetSchemaResponse.Builder builder = new SetSchemaResponse.Builder();
48 
49         for (int i = 0; i < proto.getDeletedSchemaTypesCount(); i++) {
50             builder.addDeletedType(proto.getDeletedSchemaTypes(i).substring(prefix.length()));
51         }
52 
53         for (int i = 0; i < proto.getIncompatibleSchemaTypesCount(); i++) {
54             builder.addIncompatibleType(
55                     proto.getIncompatibleSchemaTypes(i).substring(prefix.length()));
56         }
57 
58         return builder.build();
59     }
60 }
61