• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 
15 package com.google.android.apps.common.testing.accessibility.framework.replacements;
16 
17 import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
18 import org.checkerframework.checker.nullness.qual.Nullable;
19 
20 /** Used as a local replacement for Android's {@link android.text.TextUtils} */
21 public class TextUtils {
TextUtils()22   private TextUtils() {
23     // Not instantiable
24   }
25 
26   /**
27    * @see android.text.TextUtils#isEmpty(CharSequence)
28    */
29   @EnsuresNonNullIf(expression = "#1", result = false)
isEmpty(@ullable CharSequence str)30   public static boolean isEmpty(@Nullable CharSequence str) {
31     return (str == null) || (str.length() == 0);
32   }
33 
34   /** See {@link android.text.TextUtils#getTrimmedLength(CharSequence)}. */
getTrimmedLength(CharSequence str)35   public static int getTrimmedLength(CharSequence str) {
36     return str.toString().trim().length();
37   }
38 
39   /** See {@link android.text.TextUtils#equals(CharSequence, CharSequence)}. */
equals(@ullable CharSequence s1, @Nullable CharSequence s2)40   public static boolean equals(@Nullable CharSequence s1, @Nullable CharSequence s2) {
41     if (s1 == s2) {
42       return true;
43     }
44 
45     if ((s1 != null) && (s2 != null) && (s1.length() == s2.length())) {
46       if (s1 instanceof String && s2 instanceof String) {
47         return ((String) s1).equals((String) s2);
48       } else {
49         for (int i = 0; i < s1.length(); i++) {
50           if (s1.charAt(i) != s2.charAt(i)) {
51             return false;
52           }
53         }
54         return true;
55       }
56     }
57     return false;
58   }
59 }
60