Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// Use of this source code is governed by a BSD-style license that can be

import android.net.Uri;
import android.support.annotation.Nullable;
import android.text.TextUtils;

public class Main {
    /**
     * Returns a title suitable for display for a link. If |title| is non-empty, this simply returns
     * it. Otherwise, returns a shortened form of the URL.
     */
    static String getTitleForDisplay(@Nullable String title, @Nullable String url) {
        if (!TextUtils.isEmpty(title) || TextUtils.isEmpty(url)) {
            return title;
        }

        Uri uri = Uri.parse(url);
        String host = uri.getHost();
        if (host == null)
            host = "";
        String path = uri.getPath();
        if (path == null || path.equals("/"))
            path = "";
        title = host + path;
        return title;
    }
}