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:be.ac.ucl.lfsab1509.llncampus.ADE.java

/**
 * Start information update from ADE.//from  ww  w. j a  va2  s.co  m
 * 
 * @param sa
 *            Activity that launches the update thread.
 * @param updateRunnable
 *            Runnable that launches the display update.
 * @param handler
 *            Handler to allow the display update at the end of the execution.
 */
public static void runUpdateADE(final ScheduleActivity sa, final Handler handler,
        final Runnable updateRunnable) {
    final Resources r = sa.getResources();

    final NotificationManager nm = (NotificationManager) sa.getSystemService(Context.NOTIFICATION_SERVICE);

    final NotificationCompat.Builder nb = new NotificationCompat.Builder(sa)
            .setSmallIcon(android.R.drawable.stat_sys_download)
            .setContentTitle(r.getString(R.string.download_from_ADE))
            .setContentText(r.getString(R.string.download_progress)).setAutoCancel(true);

    final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    inboxStyle.setBigContentTitle(r.getString(R.string.download_from_ADE));

    nm.notify(NOTIFY_ID, nb.build());
    new Thread(new Runnable() {
        @Override
        public void run() {

            /*
             * Fetching of code of courses to load.
             */
            ArrayList<Course> courses = Course.getList();

            if (courses == null || courses.isEmpty()) {
                // Take the context of the ScheduleActivity
                SharedPreferences preferences = new SecurePreferences(sa);
                String username = preferences.getString("username", null);
                String password = preferences.getString("password", null);
                if (username != null && password != null) {
                    UCLouvain.downloadCoursesFromUCLouvain(sa, username, password, new Runnable() {
                        public void run() {
                            runUpdateADE(sa, handler, updateRunnable);
                        }
                    }, handler);
                }

            }

            /*
             * Number of weeks. To download all the schedule, the numbers go from 0 to 51
             * (0 = beginning of first semester, 51 = ending of the September exams session).
             */
            String weeks = getWeeks();

            /*
             * Fetching data from ADE and updating the database
             */
            int nbError = 0;
            int i = 0;
            ArrayList<Event> events;
            for (Course course : courses) {
                i++;
                nb.setProgress(courses.size(), i, false);
                nb.setContentText(r.getString(R.string.download_for) + " " + course.getCourseCode() + "...");
                nm.notify(NOTIFY_ID, nb.build());
                events = ADE.getInfo(course.getCourseCode(), weeks);
                if (events == null) {
                    nbError++;
                    inboxStyle.addLine(course.getCourseCode() + " : " + r.getString(R.string.download_error));
                } else {
                    // Removing old data
                    LLNCampus.getDatabase().delete("Horaire", "COURSE = ?",
                            new String[] { course.getCourseCode() });
                    // Adding new data
                    for (Event e : events) {
                        ContentValues cv = e.toContentValues();
                        cv.put("COURSE", course.getCourseCode());
                        if (LLNCampus.getDatabase().insert("Horaire", cv) < 0) {
                            nbError++;
                        }
                    }
                    inboxStyle.addLine(course.getCourseCode() + " : " + events.size() + " "
                            + r.getString(R.string.events));
                    nb.setStyle(inboxStyle);
                }
            }

            nb.setProgress(courses.size(), courses.size(), false);

            if (nbError == 0) {
                nb.setContentText(r.getString(R.string.download_done));
                inboxStyle.setBigContentTitle(r.getString(R.string.download_done));
                nb.setSmallIcon(android.R.drawable.stat_sys_download_done);
                nb.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            } else {
                nb.setContentText(r.getString(R.string.download_done) + ". " + r.getString(R.string.nb_error)
                        + nbError + " :/");
                inboxStyle.setBigContentTitle(r.getString(R.string.download_done) + ". "
                        + r.getString(R.string.nb_error) + nbError + " :/");
                nb.setSmallIcon(android.R.drawable.stat_notify_error);
                nb.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            }
            nb.setStyle(inboxStyle);
            nm.notify(NOTIFY_ID, nb.build());

            handler.post(updateRunnable);

        }
    }).start();
}

From source file:com.cyou.poplauncher.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;

            if (LauncherAppState.isDisableAllApps() && !isValidShortcutLaunchIntent(intent)) {
                if (DBG)
                    Log.d(TAG, "Ignoring shortcut with launchIntent:" + intent);
                continue;
            }/* ww w .  j a  v a 2s .c  om*/

            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);
            }
            /*
            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().addAndBindAddedWorkspaceApps(context, addShortcuts);
        }
    }
}

From source file:com.yuchu.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;

            if (LauncherAppState.isDisableAllApps() && !isValidShortcutLaunchIntent(intent)) {
                if (DBG)
                    Log.d(TAG, "Ignoring shortcut with launchIntent:" + intent);
                continue;
            }//from  w w  w . j a v  a2 s . c  om

            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);
            }
            /*
            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, new ArrayList<AppInfo>());
        }
    }
}

From source file:css.variable.converter.CSSVariableConverter.java

private static void loadCSSFiles(File releaseDirectory) {
    CSSFilter theCSSFilter = new CSSFilter();
    DirectoryFilter theDirectoryFilter = new DirectoryFilter();
    ArrayList<String> theDirectoryList = new ArrayList<String>();

    // We're about to go look for every CSS file in a sub directory
    theDirectoryList.add(releaseDirectory.getAbsolutePath());// Add the current directory

    while (!theDirectoryList.isEmpty()) {
        File currentDirectory = new File(theDirectoryList.get(0));

        File[] currentCSSFiles = currentDirectory.listFiles(theCSSFilter);
        File[] subDirectories = currentDirectory.listFiles(theDirectoryFilter);

        // Add any css files found to theCSSList
        if (currentCSSFiles != null) {
            for (File cssFile : currentCSSFiles) {
                theCSSList.add(cssFile);
            }/*from w  w w  .  j  a va2 s . co m*/
        }

        // Add any more subdirectories found to the directory list.
        if (subDirectories != null) {
            for (File dir : subDirectories) {
                theDirectoryList.add(dir.getPath());
            }
        }

        // Remove current directory.
        theDirectoryList.remove(0);
    }
}

From source file:com.epam.dlab.backendapi.dao.BaseDAO.java

private static Object getDotted(Document d, String fieldName) {
    if (fieldName.isEmpty()) {
        return null;
    }//from  www.  j ava 2s.c  o m
    final String[] fieldParts = StringUtils.split(fieldName, '.');
    Object val = d.get(fieldParts[0]);
    for (int i = 1; i < fieldParts.length; ++i) {
        if (fieldParts[i].equals("$") && val instanceof ArrayList) {
            ArrayList<?> array = (ArrayList<?>) val;
            if (array.isEmpty()) {
                return val;
            } else {
                val = array.get(0);
            }
        } else if (val instanceof Document) {
            val = ((Document) val).get(fieldParts[i]);
        } else {
            return val;
        }
    }
    return val;
}

From source file:com.clustercontrol.notify.util.NotifyValidator.java

private static boolean validateJobInfo(NotifyJobInfo info, NotifyInfo notifyInfo)
        throws InvalidSetting, InvalidRole {
    ArrayList<Integer> validFlgIndexes = NotifyUtil.getValidFlgIndexes(info);
    if (validFlgIndexes.isEmpty()) {
        return false;
    }/*ww  w  .j  a  va  2  s  . c  o  m*/

    if (info.getJobExecFacilityFlg() == ExecFacilityConstant.TYPE_FIX) {
        // ???????
        if (info.getJobExecFacility() == null) {
            throwInvalidSetting(MessageConstant.MESSAGE_PLEASE_SET_SCOPE_NOTIFY.getMessage());
        }
        try {
            FacilityTreeCache.validateFacilityId(info.getJobExecFacility(), notifyInfo.getOwnerRoleId(), false);
        } catch (FacilityNotFound e) {
            throwInvalidSetting(e);
        }
    }

    String[] jobIds = new String[] { info.getInfoJobId(), info.getWarnJobId(), info.getCriticalJobId(),
            info.getUnknownJobId() };
    for (int i = 0; i < validFlgIndexes.size(); i++) {
        int validFlgIndex = validFlgIndexes.get(i);
        if (isNullOrEmpty(jobIds[validFlgIndex])) {
            throwInvalidSetting(MessageConstant.MESSAGE_PLEASE_SET_JOBID.getMessage());
        }
    }

    return true;
}

From source file:jp.sonymusicstudio.cast.castcompanionlibrary.utils.Utils.java

/**
 * Builds and returns a {@link MediaInfo} that was wrapped in a {@link Bundle} by
 * <code>mediaInfoToBundle</code>. It is assumed that the type of the {@link MediaInfo} is
 * {@code MediaMetaData.MEDIA_TYPE_MOVIE}
 *
 * @see <code>mediaInfoToBundle()</code>
 *//*from  w ww  . ja  v  a2 s.com*/
public static MediaInfo bundleToMediaInfo(Bundle wrapper) {
    if (wrapper == null) {
        return null;
    }

    MediaMetadata metaData = new MediaMetadata(wrapper.getInt(KEY_MEDIA_TYPE));

    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));
    metaData.putString(MediaMetadata.KEY_ALBUM_ARTIST, wrapper.getString(MediaMetadata.KEY_ALBUM_ARTIST));
    metaData.putString(MediaMetadata.KEY_ALBUM_TITLE, wrapper.getString(MediaMetadata.KEY_ALBUM_TITLE));
    metaData.putString(MediaMetadata.KEY_COMPOSER, wrapper.getString(MediaMetadata.KEY_COMPOSER));
    metaData.putString(MediaMetadata.KEY_SERIES_TITLE, wrapper.getString(MediaMetadata.KEY_SERIES_TITLE));

    metaData.putInt(MediaMetadata.KEY_SEASON_NUMBER, wrapper.getInt(MediaMetadata.KEY_SEASON_NUMBER));
    metaData.putInt(MediaMetadata.KEY_EPISODE_NUMBER, wrapper.getInt(MediaMetadata.KEY_EPISODE_NUMBER));

    long releaseDateMillis = wrapper.getLong(MediaMetadata.KEY_RELEASE_DATE, 0);
    if (releaseDateMillis > 0) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(releaseDateMillis);
        metaData.putDate(MediaMetadata.KEY_RELEASE_DATE, calendar);
    }

    ArrayList<String> images = wrapper.getStringArrayList(KEY_IMAGES);
    if (images != null && !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);
        }
    }

    List<MediaTrack> mediaTracks = null;
    if (wrapper.getString(KEY_TRACKS_DATA) != null) {
        try {
            JSONArray jsonArray = new JSONArray(wrapper.getString(KEY_TRACKS_DATA));
            mediaTracks = new ArrayList<MediaTrack>();

            if (jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObj = (JSONObject) jsonArray.get(i);
                    MediaTrack.Builder builder = new MediaTrack.Builder(jsonObj.getLong(KEY_TRACK_ID),
                            jsonObj.getInt(KEY_TRACK_TYPE));
                    if (jsonObj.has(KEY_TRACK_NAME)) {
                        builder.setName(jsonObj.getString(KEY_TRACK_NAME));
                    }
                    if (jsonObj.has(KEY_TRACK_SUBTYPE)) {
                        builder.setSubtype(jsonObj.getInt(KEY_TRACK_SUBTYPE));
                    }
                    if (jsonObj.has(KEY_TRACK_CONTENT_ID)) {
                        builder.setContentType(jsonObj.getString(KEY_TRACK_CONTENT_ID));
                    }
                    if (jsonObj.has(KEY_TRACK_LANGUAGE)) {
                        builder.setLanguage(jsonObj.getString(KEY_TRACK_LANGUAGE));
                    }
                    if (jsonObj.has(KEY_TRACKS_DATA)) {
                        builder.setCustomData(new JSONObject(jsonObj.getString(KEY_TRACKS_DATA)));
                    }
                    mediaTracks.add(builder.build());
                }
            }

        } catch (JSONException e) {
            LOGE(TAG, "Failed to build media tracks from the wrapper bundle", e);
        }
    }
    MediaInfo.Builder mediaBuilder = new MediaInfo.Builder(wrapper.getString(KEY_URL))
            .setStreamType(wrapper.getInt(KEY_STREAM_TYPE)).setContentType(wrapper.getString(KEY_CONTENT_TYPE))
            .setMetadata(metaData).setCustomData(customData).setMediaTracks(mediaTracks);

    if (wrapper.containsKey(KEY_STREAM_DURATION) && wrapper.getLong(KEY_STREAM_DURATION) >= 0) {
        mediaBuilder.setStreamDuration(wrapper.getLong(KEY_STREAM_DURATION));
    }

    return mediaBuilder.build();
}

From source file:Main.java

/**
 * Convert capitalize mode flags into human readable text.
 *
 * @param capsFlags The modes flags to be converted. It may be any combination of
 * {@link TextUtils#CAP_MODE_CHARACTERS}, {@link TextUtils#CAP_MODE_WORDS}, and
 * {@link TextUtils#CAP_MODE_SENTENCES}.
 * @return the text that describe the <code>capsMode</code>.
 *///from  w w  w. j av  a  2s .  c o  m
public static String flagsToString(final int capsFlags) {
    final int capsFlagsMask = TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS
            | TextUtils.CAP_MODE_SENTENCES;
    if ((capsFlags & ~capsFlagsMask) != 0) {
        return "unknown<0x" + Integer.toHexString(capsFlags) + ">";
    }
    final ArrayList<String> builder = new ArrayList<>();
    if ((capsFlags & android.text.TextUtils.CAP_MODE_CHARACTERS) != 0) {
        builder.add("characters");
    }
    if ((capsFlags & android.text.TextUtils.CAP_MODE_WORDS) != 0) {
        builder.add("words");
    }
    if ((capsFlags & android.text.TextUtils.CAP_MODE_SENTENCES) != 0) {
        builder.add("sentences");
    }
    return builder.isEmpty() ? "none" : TextUtils.join("|", builder);
}

From source file:com.clustercontrol.notify.util.NotifyValidator.java

private static boolean validateInfraInfo(NotifyInfraInfo info, NotifyInfo notifyInfo)
        throws InvalidSetting, InvalidRole {
    ArrayList<Integer> validFlgIndexes = NotifyUtil.getValidFlgIndexes(info);
    if (validFlgIndexes.isEmpty()) {
        return false;
    }/*from  w w  w  . j a va  2  s  . c  o  m*/

    if (info.getInfraExecFacilityFlg() == ExecFacilityConstant.TYPE_FIX) {
        // ???????
        if (info.getInfraExecFacility() == null) {
            throwInvalidSetting(MessageConstant.MESSAGE_PLEASE_SET_SCOPE_NOTIFY.getMessage());
        }
        try {
            FacilityTreeCache.validateFacilityId(info.getInfraExecFacility(), notifyInfo.getOwnerRoleId(),
                    false);
        } catch (FacilityNotFound e) {
            throwInvalidSetting(e);
        }
    }

    String[] infraIds = new String[] { info.getInfoInfraId(), info.getWarnInfraId(), info.getCriticalInfraId(),
            info.getUnknownInfraId() };
    for (int i = 0; i < validFlgIndexes.size(); i++) {
        int validFlgIndex = validFlgIndexes.get(i);
        if (isNullOrEmpty(infraIds[validFlgIndex])) {
            throwInvalidSetting(MessageConstant.MESSAGE_PLEASE_SET_INFRA_MANAGEMENT_ID.getMessage());
        }

        // ID??????????????
        InfraManagementValidator.validateInfraManagementId(infraIds[validFlgIndex],
                notifyInfo.getOwnerRoleId());
    }

    return true;
}

From source file:com.clustercontrol.notify.util.NotifyValidator.java

private static boolean validateCommandInfo(NotifyCommandInfo info, NotifyInfo notifyInfo)
        throws InvalidSetting {
    ArrayList<Integer> validFlgIndexes = NotifyUtil.getValidFlgIndexes(info);
    if (validFlgIndexes.isEmpty()) {
        return false;
    }/*  w w  w  . ja  v  a 2s  . c o m*/

    // 
    String[] effectiveUsers = new String[] { info.getInfoEffectiveUser(), info.getWarnEffectiveUser(),
            info.getCriticalEffectiveUser(), info.getUnknownEffectiveUser() };
    // 
    String[] commands = new String[] { info.getInfoCommand(), info.getWarnCommand(), info.getCriticalCommand(),
            info.getUnknownCommand() };

    for (int i = 0; i < validFlgIndexes.size(); i++) {
        int validFlgIndex = validFlgIndexes.get(i);
        if (isNullOrEmpty(effectiveUsers[validFlgIndex])) {
            throwInvalidSetting(MessageConstant.MESSAGE_PLEASE_SET_EFFECTIVEUSER.getMessage());
        }
        CommonValidator.validateString("effective.user", effectiveUsers[validFlgIndex], true, 1, 64);

        if (isNullOrEmpty(commands[validFlgIndex])) {
            throwInvalidSetting(MessageConstant.MESSAGE_PLEASE_SET_COMMAND_NOTIFY.getMessage());
        }
        CommonValidator.validateString("command", commands[validFlgIndex], true, 1, 1024);
    }

    // 
    if (info.getTimeout() == null) {
        InvalidSetting e = new InvalidSetting(MessageConstant.MESSAGE_PLEASE_INPUT_TIMEOUT.getMessage());
        m_log.info("validateCustom() : " + e.getClass().getSimpleName() + ", " + e.getMessage());
        throw e;
    }
    CommonValidator.validateInt(MessageConstant.TIME_OUT.getMessage(), info.getTimeout(), 1, 60 * 60 * 1000);

    return true;
}