Example usage for java.util ArrayList isEmpty

List of usage examples for java.util ArrayList isEmpty

Introduction

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

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:Main.java

public static ArrayList<Node> findAllChildren(final Node n, final String name) {
    final ArrayList<Node> retVal = new ArrayList<Node>();
    for (int i = 0; i < n.getChildNodes().getLength(); i++) {
        if (n.getChildNodes().item(i).getNodeName().equals(name)) {
            retVal.add(n.getChildNodes().item(i));
        }//from   w  ww  . j a  v  a2  s.c  o m
    }
    if (retVal.isEmpty()) {
        throw new IllegalStateException("no " + name + " children found in: " + n.getNodeName());
    }
    return retVal;
}

From source file:FileUtils.java

private static ArrayList<String> splitPath(String path) {
    ArrayList<String> pathElements = new ArrayList<String>();
    for (StringTokenizer st = new StringTokenizer(path, File.separator); st.hasMoreTokens();) {
        String token = st.nextToken();
        if (token.equals(".")) {
            // do nothing
        } else if (token.equals("..")) {
            if (!pathElements.isEmpty()) {
                pathElements.remove(pathElements.size() - 1);
            }/*from w  w w.jav  a 2s.  co m*/
        } else {
            pathElements.add(token);
        }
    }
    return pathElements;
}

From source file:com.android.launcher4.InstallShortcutReceiver.java

public static void removeFromInstallQueue(SharedPreferences sharedPrefs, ArrayList<String> packageNames) {
    if (packageNames.isEmpty()) {
        return;// w  ww  .  java 2  s.co m
    }
    synchronized (sLock) {
        Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null);
        if (DBG) {
            Log.d(TAG, "APPS_PENDING_INSTALL: " + strings + ", removing packages: " + packageNames);
        }
        if (strings != null) {
            Set<String> newStrings = new HashSet<String>(strings);
            Iterator<String> newStringsIter = newStrings.iterator();
            while (newStringsIter.hasNext()) {
                String json = newStringsIter.next();
                try {
                    JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
                    Intent launchIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0);
                    String pn = launchIntent.getPackage();
                    if (pn == null) {
                        pn = launchIntent.getComponent().getPackageName();
                    }
                    if (packageNames.contains(pn)) {
                        newStringsIter.remove();
                    }
                } catch (org.json.JSONException e) {
                    Log.d(TAG, "Exception reading shortcut to remove: " + e);
                } catch (java.net.URISyntaxException e) {
                    Log.d(TAG, "Exception reading shortcut to remove: " + e);
                }
            }
            sharedPrefs.edit().putStringSet(APPS_PENDING_INSTALL, new HashSet<String>(newStrings)).commit();
        }
    }
}

From source file:Main.java

public static HttpEntity getEntity(String uri, ArrayList<BasicNameValuePair> params, int method)
        throws ClientProtocolException, IOException {
    mClient = new DefaultHttpClient();
    HttpUriRequest request = null;//from   w  w  w .j a  v a  2 s.c  om
    switch (method) {
    case METHOD_GET:
        StringBuilder sb = new StringBuilder(uri);
        if (params != null && !params.isEmpty()) {
            sb.append("?");
            for (BasicNameValuePair param : params) {
                sb.append(param.getName()).append("=").append(URLEncoder.encode(param.getValue(), "UTF_8"))
                        .append("&");
            }
            sb.deleteCharAt(sb.length() - 1);
        }
        request = new HttpGet(sb.toString());
        break;
    case METHOD_POST:
        HttpPost post = new HttpPost(uri);
        if (params != null && !params.isEmpty()) {
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF_8");
            post.setEntity(entity);
        }
        request = post;
        break;
    }
    mClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000);
    mClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 5000);
    HttpResponse response = mClient.execute(request);
    System.err.println(response.getStatusLine().toString());
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        return response.getEntity();
    }
    return null;
}

From source file:com.joysee.portal.launcher.InstallShortcutReceiver.java

static void flushInstallQueue(Context context) {
    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp);
    if (!installQueue.isEmpty()) {
        Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator();
        ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>();
        int result = INSTALL_SHORTCUT_SUCCESSFUL;
        String duplicateName = "";
        while (iter.hasNext()) {
            final PendingInstallShortcutInfo pendingInfo = iter.next();
            //final Intent data = pendingInfo.data;
            final Intent intent = pendingInfo.launchIntent;
            final String name = pendingInfo.name;
            final boolean exists = LauncherModel.shortcutExists(context, name, intent);
            //final boolean allowDuplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);

            // TODO-XXX: Disable duplicates for now
            if (!exists /* && allowDuplicate */) {
                // Generate a shortcut info to add into the model
                ShortcutInfo info = getShortcutInfo(context, pendingInfo.data, pendingInfo.launchIntent);
                addShortcuts.add(info);/*  w w w . ja va2s .c  o m*/
            }
            /*
            else if (exists && !allowDuplicate) {
            result = INSTALL_SHORTCUT_IS_DUPLICATE;
            duplicateName = name;
            }
            */
        }

        // Notify the user once if we weren't able to place any duplicates
        if (result == INSTALL_SHORTCUT_IS_DUPLICATE) {
            Toast.makeText(context, duplicateName, Toast.LENGTH_SHORT).show();
        }

        // Add the new apps to the model and bind them
        if (!addShortcuts.isEmpty()) {
            LauncherAppState app = LauncherAppState.getInstance();
            app.getModel().addAndBindAddedApps(context, addShortcuts, null);
        }
    }
}

From source file:cc.flydev.launcher.InstallShortcutReceiver.java

static void flushInstallQueue(Context context) {
    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp);
    if (!installQueue.isEmpty()) {
        Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator();
        ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>();
        int result = INSTALL_SHORTCUT_SUCCESSFUL;
        String duplicateName = "";
        while (iter.hasNext()) {
            final PendingInstallShortcutInfo pendingInfo = iter.next();
            //final Intent data = pendingInfo.data;
            final Intent intent = pendingInfo.launchIntent;
            final String name = pendingInfo.name;
            final boolean exists = LauncherModel.shortcutExists(context, name, intent);
            //final boolean allowDuplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);

            // TODO-XXX: Disable duplicates for now
            if (!exists /* && allowDuplicate */) {
                // Generate a shortcut info to add into the model
                ShortcutInfo info = getShortcutInfo(context, pendingInfo.data, pendingInfo.launchIntent);
                addShortcuts.add(info);/*  w w w.j  av  a2 s . co m*/
            }
            /*
            else if (exists && !allowDuplicate) {
            result = INSTALL_SHORTCUT_IS_DUPLICATE;
            duplicateName = name;
            }
            */
        }

        // Notify the user once if we weren't able to place any duplicates
        if (result == INSTALL_SHORTCUT_IS_DUPLICATE) {
            Toast.makeText(context, context.getString(R.string.shortcut_duplicate, duplicateName),
                    Toast.LENGTH_SHORT).show();
        }

        // Add the new apps to the model and bind them
        if (!addShortcuts.isEmpty()) {
            LauncherAppState app = LauncherAppState.getInstance();
            app.getModel().addAndBindAddedApps(context, addShortcuts, null);
        }
    }
}

From source file:com.llf.android.launcher3.InstallShortcutReceiver.java

static void flushInstallQueue(Context context) {
    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp);
    if (!installQueue.isEmpty()) {
        Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator();
        ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>();
        int result = INSTALL_SHORTCUT_SUCCESSFUL;
        String duplicateName = "";
        while (iter.hasNext()) {
            final PendingInstallShortcutInfo pendingInfo = iter.next();
            // final Intent data = pendingInfo.data;
            final Intent intent = pendingInfo.launchIntent;
            final String name = pendingInfo.name;
            final boolean exists = LauncherModel.shortcutExists(context, name, intent);
            // final boolean allowDuplicate =
            // data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE,
            // true);

            // TODO-XXX: Disable duplicates for now
            if (!exists /* && allowDuplicate */) {
                // Generate a shortcut info to add into the model
                ShortcutInfo info = getShortcutInfo(context, pendingInfo.data, pendingInfo.launchIntent);
                addShortcuts.add(info);/*  ww w .  j  a  v a2 s . c  o  m*/
            }
            /*
             * else if (exists && !allowDuplicate) { result =
             * INSTALL_SHORTCUT_IS_DUPLICATE; duplicateName = name; }
             */
        }

        // Notify the user once if we weren't able to place any duplicates
        if (result == INSTALL_SHORTCUT_IS_DUPLICATE) {
            Toast.makeText(context, context.getString(R.string.shortcut_duplicate, duplicateName),
                    Toast.LENGTH_SHORT).show();
        }

        // Add the new apps to the model and bind them
        if (!addShortcuts.isEmpty()) {
            LauncherAppState app = LauncherAppState.getInstance();
            app.getModel().addAndBindAddedApps(context, addShortcuts, null);
        }
    }
}

From source file:com.aidy.launcher3.ui.receiver.InstallShortcutReceiver.java

public static void flushInstallQueue(Context context) {
    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp);
    if (!installQueue.isEmpty()) {
        Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator();
        ArrayList<ItemInfoBean> addShortcuts = new ArrayList<ItemInfoBean>();
        int result = INSTALL_SHORTCUT_SUCCESSFUL;
        String duplicateName = "";
        while (iter.hasNext()) {
            final PendingInstallShortcutInfo pendingInfo = iter.next();
            // final Intent data = pendingInfo.data;
            final Intent intent = pendingInfo.launchIntent;
            final String name = pendingInfo.name;
            final boolean exists = LauncherModel.shortcutExists(context, name, intent);
            // final boolean allowDuplicate =
            // data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE,
            // true);

            // TODO-XXX: Disable duplicates for now
            if (!exists /* && allowDuplicate */) {
                // Generate a shortcut info to add into the model
                ShortcutInfo info = getShortcutInfo(context, pendingInfo.data, pendingInfo.launchIntent);
                addShortcuts.add(info);//from   w ww .  jav a 2 s  .  co m
            }
            /*
             * else if (exists && !allowDuplicate) { result =
             * INSTALL_SHORTCUT_IS_DUPLICATE; duplicateName = name; }
             */
        }

        // Notify the user once if we weren't able to place any duplicates
        if (result == INSTALL_SHORTCUT_IS_DUPLICATE) {
            Toast.makeText(context, context.getString(R.string.shortcut_duplicate, duplicateName),
                    Toast.LENGTH_SHORT).show();
        }

        // Add the new apps to the model and bind them
        if (!addShortcuts.isEmpty()) {
            LauncherAppState app = LauncherAppState.getInstance();
            app.getModel().addAndBindAddedApps(context, addShortcuts, null);
        }
    }
}

From source file:com.firefly.sample.castcompanionlibrary.utils.Utils.java

/**
 * Builds and returns a {@link MediaInfo} that was wrapped in a {@link Bundle} by
 * <code>fromMediaInfo</code>.
 *
 * @see <code>fromMediaInfo()</code>
 * @param wrapper/*from   w ww  .  j a v  a2  s  .  co  m*/
 * @return
 */
public static MediaInfo toMediaInfo(Bundle wrapper) {
    if (null == wrapper) {
        return null;
    }

    MediaMetadata metaData = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);

    metaData.putString(MediaMetadata.KEY_SUBTITLE, wrapper.getString(MediaMetadata.KEY_SUBTITLE));
    metaData.putString(MediaMetadata.KEY_TITLE, wrapper.getString(MediaMetadata.KEY_TITLE));
    metaData.putString(MediaMetadata.KEY_STUDIO, wrapper.getString(MediaMetadata.KEY_STUDIO));
    ArrayList<String> images = wrapper.getStringArrayList(KEY_IMAGES);
    if (null != images && !images.isEmpty()) {
        for (String url : images) {
            Uri uri = Uri.parse(url);
            metaData.addImage(new WebImage(uri));
        }
    }
    String customDataStr = wrapper.getString(KEY_CUSTOM_DATA);
    JSONObject customData = null;
    if (!TextUtils.isEmpty(customDataStr)) {
        try {
            customData = new JSONObject(customDataStr);
        } catch (JSONException e) {
            LOGE(TAG, "Failed to deserialize the custom data string: custom data= " + customDataStr);
        }
    }
    return new MediaInfo.Builder(wrapper.getString(KEY_URL)).setStreamType(wrapper.getInt(KEY_STREAM_TYPE))
            .setContentType(wrapper.getString(KEY_CONTENT_TYPE)).setMetadata(metaData).setCustomData(customData)
            .build();
}

From source file:com.dv.Utils.Tools.java

/**
 * NotNull description/* ww w  . j a  va 2s. c  o m*/
 * Description:
 *
 * @param list
 * @return
 */
public static boolean NotNull(ArrayList<?> list) {
    if ((list != null) && !list.isEmpty()) {
        return true;
    } else {
        return false;
    }
}