List of usage examples for android.support.v4.util Preconditions checkArgument
public static void checkArgument(boolean expression, final Object errorMessage)
From source file:android.support.text.emoji.MetadataRepo.java
/** * Add an EmojiMetadata to the index./* w ww.j av a2 s. c o m*/ * * @hide */ @RestrictTo(LIBRARY_GROUP) @VisibleForTesting void put(@NonNull final EmojiMetadata data) { Preconditions.checkNotNull(data, "emoji metadata cannot be null"); Preconditions.checkArgument(data.getCodepointsLength() > 0, "invalid metadata codepoint length"); mRootNode.put(data, 0, data.getCodepointsLength() - 1); }
From source file:android.support.text.emoji.EmojiCompat.java
/** * Checks a given CharSequence for emojis, and adds EmojiSpans if any emojis are found. * <p>/*from w w w . ja v a 2s.c o m*/ * <ul> * <li>If no emojis are found, {@code charSequence} given as the input is returned without * any changes. i.e. charSequence is a String, and no emojis are found, the same String is * returned.</li> * <li>If the given input is not a Spannable (such as String), and at least one emoji is found * a new {@link android.text.Spannable} instance is returned. </li> * <li>If the given input is a Spannable, the same instance is returned. </li> * </ul> * When used on devices running API 18 or below, returns the given {@code charSequence} without * processing it. * * @param charSequence CharSequence to add the EmojiSpans, cannot be {@code null} * @param start start index in the charSequence to look for emojis, should be greater than or * equal to {@code 0}, also less than {@code charSequence.length()} * @param end end index in the charSequence to look for emojis, should be greater than or * equal to {@code start} parameter, also less than {@code charSequence.length()} * @param maxEmojiCount maximum number of emojis in the {@code charSequence}, should be greater * than or equal to {@code 0} * @param replaceStrategy whether to replace all emoji with {@link EmojiSpan}s, should be one of * {@link #REPLACE_STRATEGY_DEFAULT}, * {@link #REPLACE_STRATEGY_NON_EXISTENT}, * {@link #REPLACE_STRATEGY_ALL} * * @throws IllegalStateException if not initialized yet * @throws IllegalArgumentException in the following cases: * {@code start < 0}, {@code end < 0}, {@code end < start}, * {@code start > charSequence.length()}, * {@code end > charSequence.length()} * {@code maxEmojiCount < 0} */ @CheckResult public CharSequence process(@NonNull final CharSequence charSequence, @IntRange(from = 0) final int start, @IntRange(from = 0) final int end, @IntRange(from = 0) final int maxEmojiCount, @ReplaceStrategy int replaceStrategy) { Preconditions.checkState(isInitialized(), "Not initialized yet"); Preconditions.checkArgumentNonnegative(start, "start cannot be negative"); Preconditions.checkArgumentNonnegative(end, "end cannot be negative"); Preconditions.checkArgumentNonnegative(maxEmojiCount, "maxEmojiCount cannot be negative"); Preconditions.checkArgument(start <= end, "start should be <= than end"); // early return since there is nothing to do //noinspection ConstantConditions if (charSequence == null) { return charSequence; } Preconditions.checkArgument(start <= charSequence.length(), "start should be < than charSequence length"); Preconditions.checkArgument(end <= charSequence.length(), "end should be < than charSequence length"); // early return since there is nothing to do if (charSequence.length() == 0 || start == end) { return charSequence; } final boolean replaceAll; switch (replaceStrategy) { case REPLACE_STRATEGY_ALL: replaceAll = true; break; case REPLACE_STRATEGY_NON_EXISTENT: replaceAll = false; break; case REPLACE_STRATEGY_DEFAULT: default: replaceAll = mReplaceAll; break; } return mHelper.process(charSequence, start, end, maxEmojiCount, replaceAll); }