@NonNull public static String checkNotEmpty(@Nullable String string) { if (TextUtils.isEmpty(string)) { throw new IllegalArgumentException("Must not be null or empty"); } return string; }
@Override public int getId() { return TextUtils.isEmpty(imageUri) ? super.hashCode() : imageUri.hashCode(); }
private static String appendThrowableMessage(String message, @Nullable Throwable throwable) { if (throwable == null) { return message; } String throwableMessage = throwable.getMessage(); return TextUtils.isEmpty(throwableMessage) ? message : message + " - " + throwableMessage; } }
private static int parseContentLength(@Nullable String contentLengthHeader) { int result = UNKNOWN; if (!TextUtils.isEmpty(contentLengthHeader)) { try { result = Integer.parseInt(contentLengthHeader); } catch (NumberFormatException e) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "failed to parse content length header: " + contentLengthHeader, e); } } } return result; }
private String buildLabelString(Format format) { if (!TextUtils.isEmpty(format.label)) { return format.label; } // Fall back to using the language. String language = format.language; return TextUtils.isEmpty(language) || C.LANGUAGE_UNDETERMINED.equals(language) ? "" : buildLanguageString(language); }
protected int parseContentType(XmlPullParser xpp) { String contentType = xpp.getAttributeValue(null, "contentType"); return TextUtils.isEmpty(contentType) ? C.TRACK_TYPE_UNKNOWN : MimeTypes.BASE_TYPE_AUDIO.equals(contentType) ? C.TRACK_TYPE_AUDIO : MimeTypes.BASE_TYPE_VIDEO.equals(contentType) ? C.TRACK_TYPE_VIDEO : MimeTypes.BASE_TYPE_TEXT.equals(contentType) ? C.TRACK_TYPE_TEXT : C.TRACK_TYPE_UNKNOWN; }
@Override protected String getUrl(Api.GifResult model, int width, int height, Options options) { Api.GifImage fixedHeight = model.images.fixed_height; int fixedHeightDifference = getDifference(fixedHeight, width, height); Api.GifImage fixedWidth = model.images.fixed_width; int fixedWidthDifference = getDifference(fixedWidth, width, height); if (fixedHeightDifference < fixedWidthDifference && !TextUtils.isEmpty(fixedHeight.url)) { return fixedHeight.url; } else if (!TextUtils.isEmpty(fixedWidth.url)) { return fixedWidth.url; } else if (!TextUtils.isEmpty(model.images.original.url)) { return model.images.original.url; } else { return null; } }
private static synchronized void parseMetaData(Context context, ActivityInfo aInfo, XmlPullParser parser) throws XmlPullParserException, IOException { final ClassLoader myCl = IncrementComponentManager.class.getClassLoader(); final String name = parser.getAttributeValue(null, "name"); final String value = parser.getAttributeValue(null, "value"); if (!TextUtils.isEmpty(name)) { if (aInfo.metaData == null) { aInfo.metaData = new Bundle(myCl); } aInfo.metaData.putString(name, value); } }
private String getSafeStringUrl() { if (TextUtils.isEmpty(safeStringUrl)) { String unsafeStringUrl = stringUrl; if (TextUtils.isEmpty(unsafeStringUrl)) { unsafeStringUrl = Preconditions.checkNotNull(url).toString(); } safeStringUrl = Uri.encode(unsafeStringUrl, ALLOWED_URI_CHARS); } return safeStringUrl; }
private Map<String, String> generateHeaders() { Map<String, String> combinedHeaders = new HashMap<>(); for (Map.Entry<String, List<LazyHeaderFactory>> entry : headers.entrySet()) { String values = buildHeaderValue(entry.getValue()); if (!TextUtils.isEmpty(values)) { combinedHeaders.put(entry.getKey(), values); } } return combinedHeaders; }
private InputStream getStreamForSuccessfulRequest(HttpURLConnection urlConnection) throws IOException { if (TextUtils.isEmpty(urlConnection.getContentEncoding())) { int contentLength = urlConnection.getContentLength(); stream = ContentLengthInputStream.obtain(urlConnection.getInputStream(), contentLength); } else { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Got non empty content encoding: " + urlConnection.getContentEncoding()); } stream = urlConnection.getInputStream(); } return stream; }
/** * Splits a codecs sequence string, as defined in RFC 6381, into individual codec strings. * * @param codecs A codec sequence string, as defined in RFC 6381. * @return The split codecs, or an array of length zero if the input was empty. */ public static String[] splitCodecs(String codecs) { if (TextUtils.isEmpty(codecs)) { return new String[0]; } return split(codecs.trim(), "(\\s*,\\s*)"); }
/* package */ static void skipStyleBlock(ParsableByteArray input) { // The style block cannot contain empty lines, so we assume the input ends when a empty line // is found. String line; do { line = input.readLine(); } while (!TextUtils.isEmpty(line)); }
/** * Returns whether a {@link Format} does not define a language. * * @param format The {@link Format}. * @return Whether the {@link Format} does not define a language. */ protected static boolean formatHasNoLanguage(Format format) { return TextUtils.isEmpty(format.language) || formatHasLanguage(format, C.LANGUAGE_UNDETERMINED); }
private static void attachCookies(UrlRequest.Builder requestBuilder, String cookies) { if (TextUtils.isEmpty(cookies)) { return; } requestBuilder.addHeader(COOKIE, cookies); }
@NonNull private String buildHeaderValue(@NonNull List<LazyHeaderFactory> factories) { StringBuilder sb = new StringBuilder(); int size = factories.size(); for (int i = 0; i < size; i++) { LazyHeaderFactory factory = factories.get(i); String header = factory.buildHeader(); if (!TextUtils.isEmpty(header)) { sb.append(header); if (i != factories.size() - 1) { sb.append(','); } } } return sb.toString(); }
@Nullable private static Uri parseUri(String model) { Uri uri; if (TextUtils.isEmpty(model)) { return null; // See https://pmd.github.io/pmd-6.0.0/pmd_rules_java_performance.html#simplifystartswith } else if (model.charAt(0) == '/') { uri = toFileUri(model); } else { uri = Uri.parse(model); String scheme = uri.getScheme(); if (scheme == null) { uri = toFileUri(model); } } return uri; }
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; Image image = images.get(position); vh.title.setText( TextUtils.isEmpty(image.title) ? image.description : image.title); ImgurGlide.with(vh.imageView) .load(image.link) .into(vh.imageView); }
@Override protected void onDraw(Canvas canvas) { // super.onDraw(canvas); if (mData == null) { boolean hasText = !TextUtils.isEmpty(mNoDataText); if (hasText) { MPPointF c = getCenter(); canvas.drawText(mNoDataText, c.x, c.y, mInfoPaint); } return; } if (!mOffsetsCalculated) { calculateOffsets(); mOffsetsCalculated = true; } }
private void executeSearch(String searchString) { Query query = TextUtils.isEmpty(searchString) ? null : new SearchQuery(searchString); executeQuery(query); }