Example usage for java.util List isEmpty

List of usage examples for java.util List isEmpty

Introduction

In this page you can find the example usage for java.util List isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:Main.java

/**
 * Utility method to check if a shortcut can be added to the home screen.
 * @param context Context used to get the package manager.
 * @return if a shortcut can be added to the home screen under the current profile.
 *//*from   w w  w  .  j  a  v a  2 s.  com*/
// TODO(crbug.com/635567): Fix this properly.
@SuppressLint("WrongConstant")
public static boolean isAddToHomeIntentSupported(Context context) {
    PackageManager pm = context.getPackageManager();
    Intent i = new Intent(INSTALL_SHORTCUT);
    List<ResolveInfo> receivers = pm.queryBroadcastReceivers(i, PackageManager.GET_INTENT_FILTERS);
    return !receivers.isEmpty();
}

From source file:Main.java

/**
 * Gets an entry of given list with given index, but safely.<br>
 * That means if the index is greater or lower than the allowed
 * boundaries this method will either use the first index or the last index.<br>
 *
 * @param eList      The element's list/*from w w w.  j a  v  a 2s  .co m*/
 * @param index      The index to list the entry from
 * @param defaultVal If the value would be null
 * @param <E>        The element's type
 * @return The element (or null if the list is empty)
 */
public static <E> E getEntrySafely(List<E> eList, int index, E defaultVal) {
    if (index < 0)
        index *= -1;

    if (eList.isEmpty())
        return defaultVal;
    if (index >= eList.size())
        index = eList.size() - 1;
    else if (index < 0)
        index = 0;

    if (index >= eList.size())
        return defaultVal;
    return eList.get(index);
}

From source file:com.ms.commons.test.datareader.impl.XmlReaderUtil.java

@SuppressWarnings("unchecked")
protected static MemoryRow readRow(Element rowE) {
    if (rowE == null)
        return null;
    List<Element> elements = rowE.elements("field");
    if (elements.isEmpty())
        return null;

    List<MemoryField> fieldList = new ArrayList<MemoryField>(elements.size());
    for (Element fieldE : elements) {
        fieldList.add(readField(fieldE));
    }/*  www  .ja  v a 2  s .co  m*/
    return new MemoryRow(fieldList);
}

From source file:Main.java

public static ActivityInfo getAppInfo(String appName, Context context) {
    try {/*from   w  w w.j  av a2 s .  c  o  m*/
        List<ResolveInfo> appList = getAllAppInfo(context);
        if (appList != null && !appList.isEmpty() && appName != null && !"".equals(appName)) {
            for (int i = 0; i < appList.size(); i++) {
                String appNameTemp = appList.get(i).loadLabel(context.getPackageManager()).toString();
                // String packageName =
                // appList.get(i).activityInfo.packageName;
                // String mainName = appList.get(i).activityInfo.name;
                // Log.i(TAG, "appName:" + appName + "\n" + "packageName:" +
                // packageName + "\n" + "mainName:" + mainName);
                if (appName.equals(appNameTemp)) {
                    return appList.get(i).activityInfo;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

/**
 * whether application is in background/*from  w w w  . j  a v a2 s.  co m*/
 * <ul>
 * <li>need use permission android.permission.GET_TASKS in Manifest.xml</li>
 * </ul>
 * 
 * @param context
 * @return if application is in background return true, otherwise return
 *         false
 */
public static boolean isApplicationInBackground(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> taskList = am.getRunningTasks(1);
    if (taskList != null && !taskList.isEmpty()) {
        ComponentName topActivity = taskList.get(0).topActivity;
        if (topActivity != null && !topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static boolean isAppBackground(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    @SuppressWarnings("deprecation")
    List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
    if (!tasks.isEmpty()) {
        ComponentName topActivity = tasks.get(0).topActivity;
        if (!topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }// ww  w.ja  v a2s  .c  om
    }
    return false;
}

From source file:com.zenoss.zenpacks.zenjmx.call.CallFactory.java

/**
 * Creates a JmxCall from a configuration read from the server
 * @param config the name-value parameters from the server
 * @throws ConfigurationException if the configuration provided does not
 *         contain sufficient information to create a call.
 */// w ww  .  j  av a  2s  .  c o  m
public static JmxCall createCall(ConfigAdapter config) throws ConfigurationException {

    _logger.debug("config: " + config);

    List<String> dataPoints = config.getDataPoints();
    if (dataPoints.isEmpty()) {
        _logger.warn("no data points defined");
        throw new ConfigurationException("Datasource " + config.getDatasourceId() + "No datapoints defined;"
                + " will not run collections");
    }

    // if the attributeName is blank the configuration represents an operation
    String attributeName = config.getAttributeName();
    JmxCall call = null;
    if (attributeName.trim().length() == 0) {
        _logger.debug("creating an operation call");
        call = OperationCall.fromValue(config);
    } else {
        _logger.debug("creating an attribute call");
        call = AttributeCall.fromValue(config);
    }
    return call;
}

From source file:io.github.seleniumquery.functions.jquery.manipulation.HtmlFunction.java

/**
 * Returns the HTML of the first element of the list.
 * @param elements The list of elements.
 * @return The HTML of the first element.
 *///  w w w  .j  ava2 s .c  o m
public static String html(List<WebElement> elements) {
    if (elements.isEmpty()) {
        return null;
    }
    return html(elements.get(0));
}

From source file:Main.java

public static Intent createTakePictureIntent(@NonNull Context context, @NonNull Uri outputFileUri) {
    List<Intent> cameraIntents = createTakePictureIntentList(context, outputFileUri);

    if (cameraIntents.isEmpty())
        return null;

    Intent chooserIntent = new Intent(cameraIntents.get(0));

    cameraIntents.remove(0);/*from   w ww. ja v  a 2  s. co m*/

    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            cameraIntents.toArray(new Parcelable[cameraIntents.size()]));

    return chooserIntent;
}

From source file:Main.java

/**
 * Randomize the specified list.//from ww w.j  av a2s  .  c o  m
 * @param list the list to randomize.
 * @param <E> the type of elements in the list.
 * @return a new list with all the elements of the input but in a random order.
 */
public static <E> List<E> randomize(List<E> list) {
    List<E> tmp = new ArrayList<>(list);
    List<E> result = new ArrayList<>(list.size());
    while (!tmp.isEmpty()) {
        int n = rand.nextInt(tmp.size());
        result.add(tmp.remove(n));
    }
    return result;
}