Java源码示例:org.checkerframework.checker.nullness.qual.PolyNull

示例1
@PolyNull
public static Object invoke(
    Object receiver, @PolyNull Object defaultValue, Method method, Object... args) {
  if (method == null) {
    return defaultValue;
  }

  try {
    return method.invoke(receiver, args);
  } catch (Exception e) {
    Log.e(TAG, "Exception in invoke: " + e.getClass().getSimpleName());

    if (DEBUG) {
      e.printStackTrace();
    }
  }

  return defaultValue;
}
 
示例2
/**
 * Cleans up text for speech. Converts symbols to their spoken equivalents.
 *
 * @param context The context used to resolve string resources.
 * @param text The text to clean up.
 * @return Cleaned up text, or null if text is null.
 */
public static @PolyNull CharSequence cleanUp(Context context, @PolyNull CharSequence text) {
  if (text != null) {
    CharSequence textAfterTrim = trimText(text);
    int trimmedLength = textAfterTrim.length();
    if (trimmedLength == 1) {
      CharSequence textAfterCleanUp = getCleanValueFor(context, textAfterTrim.charAt(0));

      // Return the text as it is if it remains the same after clean up so
      // that any Span information is not lost
      if (TextUtils.equals(textAfterCleanUp, textAfterTrim)) {
        return textAfterTrim;
      }

      // Retaining Spans that might have got stripped during cleanUp
      CharSequence formattedText = retainSpans(text, textAfterCleanUp);
      return formattedText;

    } else if (trimmedLength == 0 && text.length() > 0) {
      // For example, just spaces.
      return getCleanValueFor(context, text.toString().charAt(0));
    }
  }
  return text;
}
 
示例3
private static @PolyNull String parseOptionalStringAttr(
    String line,
    Pattern pattern,
    @PolyNull String defaultValue,
    Map<String, String> variableDefinitions) {
  Matcher matcher = pattern.matcher(line);
  String value = matcher.find() ? matcher.group(1) : defaultValue;
  return variableDefinitions.isEmpty() || value == null
      ? value
      : replaceVariableReferences(value, variableDefinitions);
}
 
示例4
/**
 * Returns a normalized IETF BCP 47 language tag for {@code language}.
 *
 * @param language A case-insensitive language code supported by {@link
 *     Locale#forLanguageTag(String)}.
 * @return The all-lowercase normalized code, or null if the input was null, or {@code
 *     language.toLowerCase()} if the language could not be normalized.
 */
public static @PolyNull String normalizeLanguageCode(@PolyNull String language) {
  if (language == null) {
    return null;
  }
  // Locale data (especially for API < 21) may produce tags with '_' instead of the
  // standard-conformant '-'.
  String normalizedTag = language.replace('_', '-');
  if (Util.SDK_INT >= 21) {
    // Filters out ill-formed sub-tags, replaces deprecated tags and normalizes all valid tags.
    normalizedTag = normalizeLanguageCodeSyntaxV21(normalizedTag);
  }
  if (normalizedTag.isEmpty() || "und".equals(normalizedTag)) {
    // Tag isn't valid, keep using the original.
    normalizedTag = language;
  }
  normalizedTag = Util.toLowerInvariant(normalizedTag);
  String mainLanguage = Util.splitAtFirst(normalizedTag, "-")[0];
  if (mainLanguage.length() == 3) {
    // 3-letter ISO 639-2/B or ISO 639-2/T language codes will not be converted to 2-letter ISO
    // 639-1 codes automatically.
    if (languageTagIso3ToIso2 == null) {
      languageTagIso3ToIso2 = createIso3ToIso2Map();
    }
    String iso2Language = languageTagIso3ToIso2.get(mainLanguage);
    if (iso2Language != null) {
      normalizedTag = iso2Language + normalizedTag.substring(/* beginIndex= */ 3);
    }
  }
  return normalizedTag;
}
 
示例5
/**
 * Converts a list of integers to a primitive array.
 *
 * @param list A list of integers.
 * @return The list in array form, or null if the input list was null.
 */
public static int @PolyNull [] toArray(@PolyNull List<Integer> list) {
  if (list == null) {
    return null;
  }
  int length = list.size();
  int[] intArray = new int[length];
  for (int i = 0; i < length; i++) {
    intArray[i] = list.get(i);
  }
  return intArray;
}
 
示例6
/**
 * Converts a list of integers to a primitive array.
 *
 * @param list A list of integers.
 * @return The list in array form, or null if the input list was null.
 */
public static int @PolyNull [] toArray(@PolyNull List<Integer> list) {
  if (list == null) {
    return null;
  }
  int length = list.size();
  int[] intArray = new int[length];
  for (int i = 0; i < length; i++) {
    intArray[i] = list.get(i);
  }
  return intArray;
}
 
示例7
/**
 * Converts a list of integers to a primitive array.
 *
 * @param list A list of integers.
 * @return The list in array form, or null if the input list was null.
 */
public static int @PolyNull [] toArray(@PolyNull List<Integer> list) {
  if (list == null) {
    return null;
  }
  int length = list.size();
  int[] intArray = new int[length];
  for (int i = 0; i < length; i++) {
    intArray[i] = list.get(i);
  }
  return intArray;
}
 
示例8
private static @PolyNull String convert(DatabaseMetaData metaData, @PolyNull String name)
        throws SQLException {
    if (name == null) {
        return null;
    }
    if (metaData.storesUpperCaseIdentifiers()) {
        return name.toUpperCase(Locale.ENGLISH);
    } else {
        return name;
    }
}
 
示例9
public static @PolyNull String fromInternalName(@PolyNull String internalName) {
    if (internalName == null) {
        return null;
    } else {
        return internalName.replace('/', '.');
    }
}
 
示例10
private @PolyNull Type hack(@PolyNull Type type) {
    if (type == null) {
        return null;
    }
    String internalName = type.getInternalName();
    if (collocate(internalName)) {
        return Type.getObjectType(internalName + "_");
    } else {
        return type;
    }
}
 
示例11
private static @PolyNull String parseOptionalStringAttr(
    String line,
    Pattern pattern,
    @PolyNull String defaultValue,
    Map<String, String> variableDefinitions) {
  Matcher matcher = pattern.matcher(line);
  String value = matcher.find() ? matcher.group(1) : defaultValue;
  return variableDefinitions.isEmpty() || value == null
      ? value
      : replaceVariableReferences(value, variableDefinitions);
}
 
示例12
/**
 * Returns a normalized IETF BCP 47 language tag for {@code language}.
 *
 * @param language A case-insensitive language code supported by {@link
 *     Locale#forLanguageTag(String)}.
 * @return The all-lowercase normalized code, or null if the input was null, or {@code
 *     language.toLowerCase()} if the language could not be normalized.
 */
public static @PolyNull String normalizeLanguageCode(@PolyNull String language) {
  if (language == null) {
    return null;
  }
  // Locale data (especially for API < 21) may produce tags with '_' instead of the
  // standard-conformant '-'.
  String normalizedTag = language.replace('_', '-');
  if (Util.SDK_INT >= 21) {
    // Filters out ill-formed sub-tags, replaces deprecated tags and normalizes all valid tags.
    normalizedTag = normalizeLanguageCodeSyntaxV21(normalizedTag);
  }
  if (normalizedTag.isEmpty() || "und".equals(normalizedTag)) {
    // Tag isn't valid, keep using the original.
    normalizedTag = language;
  }
  normalizedTag = Util.toLowerInvariant(normalizedTag);
  String mainLanguage = Util.splitAtFirst(normalizedTag, "-")[0];
  if (mainLanguage.length() == 3) {
    // 3-letter ISO 639-2/B or ISO 639-2/T language codes will not be converted to 2-letter ISO
    // 639-1 codes automatically.
    if (languageTagIso3ToIso2 == null) {
      languageTagIso3ToIso2 = createIso3ToIso2Map();
    }
    String iso2Language = languageTagIso3ToIso2.get(mainLanguage);
    if (iso2Language != null) {
      normalizedTag = iso2Language + normalizedTag.substring(/* beginIndex= */ 3);
    }
  }
  return normalizedTag;
}
 
示例13
/**
 * Converts a list of integers to a primitive array.
 *
 * @param list A list of integers.
 * @return The list in array form, or null if the input list was null.
 */
public static int @PolyNull [] toArray(@PolyNull List<Integer> list) {
  if (list == null) {
    return null;
  }
  int length = list.size();
  int[] intArray = new int[length];
  for (int i = 0; i < length; i++) {
    intArray[i] = list.get(i);
  }
  return intArray;
}
 
示例14
private static @PolyNull String parseOptionalStringAttr(
    String line,
    Pattern pattern,
    @PolyNull String defaultValue,
    Map<String, String> variableDefinitions) {
  Matcher matcher = pattern.matcher(line);
  String value = matcher.find() ? matcher.group(1) : defaultValue;
  return variableDefinitions.isEmpty() || value == null
      ? value
      : replaceVariableReferences(value, variableDefinitions);
}
 
示例15
/**
 * Returns a normalized IETF BCP 47 language tag for {@code language}.
 *
 * @param language A case-insensitive language code supported by {@link
 *     Locale#forLanguageTag(String)}.
 * @return The all-lowercase normalized code, or null if the input was null, or {@code
 *     language.toLowerCase()} if the language could not be normalized.
 */
public static @PolyNull String normalizeLanguageCode(@PolyNull String language) {
  if (language == null) {
    return null;
  }
  // Locale data (especially for API < 21) may produce tags with '_' instead of the
  // standard-conformant '-'.
  String normalizedTag = language.replace('_', '-');
  if (Util.SDK_INT >= 21) {
    // Filters out ill-formed sub-tags, replaces deprecated tags and normalizes all valid tags.
    normalizedTag = normalizeLanguageCodeSyntaxV21(normalizedTag);
  }
  if (normalizedTag.isEmpty() || "und".equals(normalizedTag)) {
    // Tag isn't valid, keep using the original.
    normalizedTag = language;
  }
  normalizedTag = Util.toLowerInvariant(normalizedTag);
  String mainLanguage = Util.splitAtFirst(normalizedTag, "-")[0];
  if (mainLanguage.length() == 3) {
    // 3-letter ISO 639-2/B or ISO 639-2/T language codes will not be converted to 2-letter ISO
    // 639-1 codes automatically.
    if (languageTagIso3ToIso2 == null) {
      languageTagIso3ToIso2 = createIso3ToIso2Map();
    }
    String iso2Language = languageTagIso3ToIso2.get(mainLanguage);
    if (iso2Language != null) {
      normalizedTag = iso2Language + normalizedTag.substring(/* beginIndex= */ 3);
    }
  }
  return normalizedTag;
}
 
示例16
/**
 * Converts a list of integers to a primitive array.
 *
 * @param list A list of integers.
 * @return The list in array form, or null if the input list was null.
 */
public static int @PolyNull [] toArray(@PolyNull List<Integer> list) {
  if (list == null) {
    return null;
  }
  int length = list.size();
  int[] intArray = new int[length];
  for (int i = 0; i < length; i++) {
    intArray[i] = list.get(i);
  }
  return intArray;
}
 
示例17
private static @PolyNull String parseOptionalStringAttr(
    String line, Pattern pattern, @PolyNull String defaultValue) {
  Matcher matcher = pattern.matcher(line);
  return matcher.find() ? matcher.group(1) : defaultValue;
}
 
示例18
private static @PolyNull String parseOptionalStringAttr(
    String line, Pattern pattern, @PolyNull String defaultValue) {
  Matcher matcher = pattern.matcher(line);
  return matcher.find() ? matcher.group(1) : defaultValue;
}
 
示例19
/**
 * Collapses multiple spaces into a single space and removes leading/trailing whitespace.
 *
 * @param str The input {@link String} to normalize spaces
 * @return The input {@link String} with unnecessary whitespace removed or {@code null} if the
 *     input is {@code null}
 */
@PolyNull
public static String normalizeSpaces(@PolyNull CharSequence str) {
  return (str == null)
      ? null
      : WHITESPACE_BLOCK_PATTERN.matcher(str).replaceAll(SPACE_STRING).trim();
}
 
示例20
/**
 * A wrapper over AccessibilityNodeInfoCompat constructor, so that we can add any desired error
 * checking and memory management.
 *
 * @param nodeInfo The AccessibilityNodeInfo which will be wrapped. The caller retains the
 *     responsibility to recycle nodeInfo.
 * @return Encapsulating AccessibilityNodeInfoCompat, or null if input is null.
 */
public static @PolyNull AccessibilityNodeInfoCompat toCompat(
    @PolyNull AccessibilityNodeInfo nodeInfo) {
  if (nodeInfo == null) {
    return null;
  }
  return AccessibilityNodeInfoCompat.wrap(nodeInfo);
}
 
示例21
/**
 * Converts text to lower case using {@link Locale#US}.
 *
 * @param text The text to convert.
 * @return The lower case text, or null if {@code text} is null.
 */
public static @PolyNull String toLowerInvariant(@PolyNull String text) {
  return text == null ? text : text.toLowerCase(Locale.US);
}
 
示例22
/**
 * Converts text to upper case using {@link Locale#US}.
 *
 * @param text The text to convert.
 * @return The upper case text, or null if {@code text} is null.
 */
public static @PolyNull String toUpperInvariant(@PolyNull String text) {
  return text == null ? text : text.toUpperCase(Locale.US);
}
 
示例23
/**
 * Converts text to lower case using {@link Locale#US}.
 *
 * @param text The text to convert.
 * @return The lower case text, or null if {@code text} is null.
 */
public static @PolyNull String toLowerInvariant(@PolyNull String text) {
  return text == null ? text : text.toLowerCase(Locale.US);
}
 
示例24
/**
 * Converts text to upper case using {@link Locale#US}.
 *
 * @param text The text to convert.
 * @return The upper case text, or null if {@code text} is null.
 */
public static @PolyNull String toUpperInvariant(@PolyNull String text) {
  return text == null ? text : text.toUpperCase(Locale.US);
}
 
示例25
/**
 * Converts text to lower case using {@link Locale#US}.
 *
 * @param text The text to convert.
 * @return The lower case text, or null if {@code text} is null.
 */
public static @PolyNull String toLowerInvariant(@PolyNull String text) {
  return text == null ? text : text.toLowerCase(Locale.US);
}
 
示例26
/**
 * Converts text to upper case using {@link Locale#US}.
 *
 * @param text The text to convert.
 * @return The upper case text, or null if {@code text} is null.
 */
public static @PolyNull String toUpperInvariant(@PolyNull String text) {
  return text == null ? text : text.toUpperCase(Locale.US);
}
 
示例27
/**
 * Converts text to lower case using {@link Locale#US}.
 *
 * @param text The text to convert.
 * @return The lower case text, or null if {@code text} is null.
 */
public static @PolyNull String toLowerInvariant(@PolyNull String text) {
  return text == null ? text : text.toLowerCase(Locale.US);
}
 
示例28
/**
 * Converts text to upper case using {@link Locale#US}.
 *
 * @param text The text to convert.
 * @return The upper case text, or null if {@code text} is null.
 */
public static @PolyNull String toUpperInvariant(@PolyNull String text) {
  return text == null ? text : text.toUpperCase(Locale.US);
}
 
示例29
/**
 * Converts text to lower case using {@link Locale#US}.
 *
 * @param text The text to convert.
 * @return The lower case text, or null if {@code text} is null.
 */
public static @PolyNull String toLowerInvariant(@PolyNull String text) {
  return text == null ? text : text.toLowerCase(Locale.US);
}
 
示例30
/**
 * Converts text to upper case using {@link Locale#US}.
 *
 * @param text The text to convert.
 * @return The upper case text, or null if {@code text} is null.
 */
public static @PolyNull String toUpperInvariant(@PolyNull String text) {
  return text == null ? text : text.toUpperCase(Locale.US);
}