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 package androidx.appsearch.debugview.samples.model;
17 
18 import androidx.appsearch.annotation.Document;
19 import androidx.appsearch.app.AppSearchSchema.StringPropertyConfig;
20 import androidx.core.util.Preconditions;
21 
22 import org.jspecify.annotations.NonNull;
23 
24 /**
25  * Encapsulates a Note document.
26  */
27 @Document
28 public class Note {
29 
Note(@onNull String namespace, @NonNull String id, @NonNull String text)30     Note(@NonNull String namespace, @NonNull String id, @NonNull String text) {
31         mId = Preconditions.checkNotNull(id);
32         mNamespace = Preconditions.checkNotNull(namespace);
33         mText = Preconditions.checkNotNull(text);
34     }
35 
36     @Document.Id
37     private final String mId;
38 
39     @Document.Namespace
40     private final String mNamespace;
41 
42     @Document.StringProperty(indexingType = StringPropertyConfig.INDEXING_TYPE_PREFIXES)
43     private final String mText;
44 
45     /** Returns the ID of the {@link Note} object. */
getId()46     public @NonNull String getId() {
47         return mId;
48     }
49 
50     /** Returns the namespace of the {@link Note} object. */
getNamespace()51     public @NonNull String getNamespace() {
52         return mNamespace;
53     }
54 
55     /** Returns the text of the {@link Note} object. */
getText()56     public @NonNull String getText() {
57         return mText;
58     }
59 
60     @Override
toString()61     public @NonNull String toString() {
62         return mText;
63     }
64 
65     /** Builder for {@link Note} objects. */
66     public static final class Builder {
67         private String mNamespace = "";
68         private String mId = "";
69         private String mText = "";
70 
71         /** Sets the namespace of the {@link Note} object. */
setNamespace(@onNull String namespace)72         public Note.@NonNull Builder setNamespace(@NonNull String namespace) {
73             mNamespace = Preconditions.checkNotNull(namespace);
74             return this;
75         }
76 
77         /** Sets the ID of the {@link Note} object. */
setId(@onNull String id)78         public Note.@NonNull Builder setId(@NonNull String id) {
79             mId = Preconditions.checkNotNull(id);
80             return this;
81         }
82 
83         /** Sets the text of the {@link Note} object. */
setText(@onNull String text)84         public Note.@NonNull Builder setText(@NonNull String text) {
85             mText = Preconditions.checkNotNull(text);
86             return this;
87         }
88 
89         /** Creates a new {@link Note} object. */
build()90         public @NonNull Note build() {
91             return new Note(mNamespace, mId, mText);
92         }
93     }
94 }
95