1 /*
2  * Copyright (C) 2022 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 android.app.smartspace;
18 
19 import android.annotation.Nullable;
20 import android.app.smartspace.uitemplatedata.Text;
21 import android.text.TextUtils;
22 
23 /**
24  * Utilities for Smartspace data.
25  *
26  * @hide
27  */
28 public final class SmartspaceUtils {
29 
SmartspaceUtils()30     private SmartspaceUtils() {
31     }
32 
33     /** Returns true if the passed in {@link Text} is null or its content is empty. */
isEmpty(@ullable Text text)34     public static boolean isEmpty(@Nullable Text text) {
35         return text == null || TextUtils.isEmpty(text.getText());
36     }
37 
38     /** Returns true if the passed-in {@link Text}s are equal. */
isEqual(@ullable Text text1, @Nullable Text text2)39     public static boolean isEqual(@Nullable Text text1, @Nullable Text text2) {
40         if (text1 == null && text2 == null) return true;
41         if (text1 == null || text2 == null) return false;
42         return text1.equals(text2);
43     }
44 
45     /** Returns true if the passed-in {@link CharSequence}s are equal. */
isEqual(@ullable CharSequence cs1, @Nullable CharSequence cs2)46     public static boolean isEqual(@Nullable CharSequence cs1, @Nullable CharSequence cs2) {
47         if (cs1 == null && cs2 == null) return true;
48         if (cs1 == null || cs2 == null) return false;
49         return cs1.toString().contentEquals(cs2);
50     }
51 }
52