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:com.clustercontrol.notify.util.NotifyValidator.java

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

    // ???
    if (info.getMailTemplateId() != null) {
        try {
            // ?
            com.clustercontrol.notify.mail.util.QueryUtil.getMailTemplateInfoPK(info.getMailTemplateId());
            // ??
            com.clustercontrol.notify.mail.util.QueryUtil.getMailTemplateInfoPK_OR(info.getMailTemplateId(),
                    notifyInfo.getOwnerRoleId());
        } catch (MailTemplateNotFound e) {
            throw new InvalidSetting(e.getMessage(), e);
        } catch (InvalidRole e) {
            m_log.warn("validateNotifyInfo() : " + e.getClass().getSimpleName() + ", " + e.getMessage());
            throw e;
        }
    }

    String[] mailAddresses = new String[] { info.getInfoMailAddress(), info.getWarnMailAddress(),
            info.getCriticalMailAddress(), info.getUnknownMailAddress() };
    for (int i = 0; i < validFlgIndexes.size(); i++) {
        int validFlgIndex = validFlgIndexes.get(i);

        if (isNullOrEmpty(mailAddresses[validFlgIndex])) {
            throwInvalidSetting(MessageConstant.MESSAGE_PLEASE_SET_MAILADDR_CORRECT_FORMAT.getMessage());
        }

        CommonValidator.validateString(MessageConstant.EMAIL_ADDRESS_SSV.getMessage(),
                mailAddresses[validFlgIndex], true, 1, 1024);
    }

    return true;
}

From source file:com.android.launcher4.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.jav a 2 s. co  m*/

            final boolean exists = LauncherModel.shortcutExists(context, name, intent);
            //final boolean allowDuplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);

            // If the intent specifies a package, make sure the package exists
            String packageName = intent.getPackage();
            if (packageName == null) {
                packageName = intent.getComponent() == null ? null : intent.getComponent().getPackageName();
            }
            if (packageName != null && !packageName.isEmpty()) {
                UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle();
                if (!LauncherModel.isValidPackage(context, packageName, myUserHandle)) {
                    if (DBG)
                        Log.d(TAG, "Ignoring shortcut for absent package:" + intent);
                    continue;
                }
            }

            if (!exists) {
                // Generate a shortcut info to add into the model
                ShortcutInfo info = getShortcutInfo(context, pendingInfo.data, pendingInfo.launchIntent);
                addShortcuts.add(info);
            }

        }

        // 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.mb.android.playbackmediator.utils.Utils.java

/**
 * Builds and returns a {@link MediaInfo} that was wrapped in a {@link Bundle} by
 * <code>fromMediaInfo</code>.
 *
 * @param wrapper//from  ww w .ja v a  2  s  .c om
 * @return
 * @see <code>fromMediaInfo()</code>
 */
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)
            .setStreamDuration(wrapper.getLong(KEY_STREAM_DURATION)).build();
}

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

public static void removeFromInstallQueue(Context context, ArrayList<String> packageNames,
        UserHandleCompat user) {//from   ww w  .j  a  va  2 s  .  c o  m
    if (packageNames.isEmpty()) {
        return;
    }
    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    synchronized (sLock) {
        Set<String> strings = sp.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 encoded = newStringsIter.next();
                PendingInstallShortcutInfo info = decode(encoded, context);
                if (info == null
                        || (packageNames.contains(info.getTargetPackage()) && user.equals(info.user))) {
                    newStringsIter.remove();
                }
            }
            sp.edit().putStringSet(APPS_PENDING_INSTALL, newStrings).commit();
        }
    }
}

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

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

    if (info.getEscalateFacilityFlg() == ExecFacilityConstant.TYPE_FIX) {
        // ???????
        if (info.getEscalateFacility() == null) {
            throwInvalidSetting(MessageConstant.MESSAGE_PLEASE_SET_SCOPE_NOTIFY.getMessage());
        }

        try {
            FacilityTreeCache.validateFacilityId(info.getEscalateFacility(), notifyInfo.getOwnerRoleId(),
                    false);
        } catch (FacilityNotFound e) {
            throwInvalidSetting(e);
        }
    }

    Integer[] syslogFacilities = new Integer[] { info.getInfoSyslogFacility(), info.getWarnSyslogFacility(),
            info.getCriticalSyslogFacility(), info.getUnknownSyslogFacility() };
    Integer[] syslogPriorities = new Integer[] { info.getInfoSyslogPriority(), info.getWarnSyslogPriority(),
            info.getCriticalSyslogPriority(), info.getUnknownSyslogPriority() };
    String[] escalateMessages = new String[] { info.getInfoEscalateMessage(), info.getWarnEscalateMessage(),
            info.getCriticalEscalateMessage(), info.getUnknownEscalateMessage() };

    Locale locale = NotifyUtil.getNotifyLocale();
    for (int i = 0; i < validFlgIndexes.size(); i++) {
        int validFlgIndex = validFlgIndexes.get(i);
        if (syslogFacilities[validFlgIndex] == null) {
            throwInvalidSetting(MessageConstant.MESSAGE_PLEASE_SET_FACILIY.getMessage(Messages
                    .getString(PriorityConstant.typeToMessageCode(getPriorityCode(validFlgIndex)), locale)));
        }
        if (syslogPriorities[validFlgIndex] == null) {
            throwInvalidSetting(MessageConstant.MESSAGE_PLEASE_SET_PRIORITY.getMessage(Messages
                    .getString(PriorityConstant.typeToMessageCode(getPriorityCode(validFlgIndex)), locale)));
        }
        if (isNullOrEmpty(escalateMessages[validFlgIndex])) {
            throwInvalidSetting(MessageConstant.MESSAGE_PLEASE_SET_MESSAGE.getMessage(Messages
                    .getString(PriorityConstant.typeToMessageCode(getPriorityCode(validFlgIndex)), locale)));
        }
        CommonValidator.validateString(MessageConstant.MESSAGE.getMessage(), escalateMessages[validFlgIndex],
                true, 1, 1024);

    }

    if (info.getEscalatePort() == null) {
        throwInvalidSetting(MessageConstant.MESSAGE_PLEASE_SET_PORT_NUM.getMessage());
    }
    CommonValidator.validateInt(MessageConstant.PORT_NUMBER.getMessage(), info.getEscalatePort(), 1,
            DataRangeConstant.PORT_NUMBER_MAX);

    return true;
}

From source file:com.stv.launcher.receiver.InstallShortcutReceiver.java

public static void removeFromInstallQueue(Context context, ArrayList<String> packageNames,
        UserHandleCompat user) {// w  ww  . j  a va  2s . c  o  m
    if (packageNames.isEmpty()) {
        return;
    }
    String spKey = LauncherState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    synchronized (sLock) {
        Set<String> strings = sp.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 encoded = newStringsIter.next();
                PendingInstallShortcutInfo info = decode(encoded, context);
                if (info == null
                        || (packageNames.contains(info.getTargetPackage()) && user.equals(info.user))) {
                    newStringsIter.remove();
                }
            }
            sp.edit().putStringSet(APPS_PENDING_INSTALL, newStrings).commit();
        }
    }
}

From source file:Main.java

/**
 * Splits a string into a number of tokens.
 * The text is split by '?' and '*'.//ww w . j  a  va  2  s . c  o m
 * Where multiple '*' occur consecutively they are collapsed into a single '*'.
 *
 * @param text  the text to split
 * @return the array of tokens, never null
 */
static String[] splitOnTokens(String text) {
    // used by wildcardMatch
    // package level so a unit test may run on this

    if (text.indexOf('?') == -1 && text.indexOf('*') == -1) {
        return new String[] { text };
    }

    char[] array = text.toCharArray();
    ArrayList<String> list = new ArrayList<String>();
    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < array.length; i++) {
        if (array[i] == '?' || array[i] == '*') {
            if (buffer.length() != 0) {
                list.add(buffer.toString());
                buffer.setLength(0);
            }
            if (array[i] == '?') {
                list.add("?");
            } else if (list.isEmpty() || i > 0 && list.get(list.size() - 1).equals("*") == false) {
                list.add("*");
            }
        } else {
            buffer.append(array[i]);
        }
    }
    if (buffer.length() != 0) {
        list.add(buffer.toString());
    }

    return list.toArray(new String[list.size()]);
}

From source file:com.dnielfe.manager.utils.SimpleUtils.java

@NotNull
public static ArrayList<String> listFiles(String path) {
    ArrayList<String> mDirContent = new ArrayList<String>();
    boolean showhidden = Settings.mShowHiddenFiles;

    if (!mDirContent.isEmpty())
        mDirContent.clear();/*from w  w  w .ja  va2  s . co m*/

    final File file = new File(path);

    if (file.exists() && file.canRead()) {
        String[] list = file.list();
        int len = list.length;

        // add files/folder to ArrayList depending on hidden status
        for (int i = 0; i < len; i++) {
            if (!showhidden) {
                if (list[i].toString().charAt(0) != '.')
                    mDirContent.add(path + "/" + list[i]);
            } else {
                mDirContent.add(path + "/" + list[i]);
            }
        }
    } else {
        try {
            mDirContent = RootCommands.listFiles(file.getAbsolutePath(), showhidden);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // sort files with a comparator
    SortUtils.sortList(mDirContent, file.getPath());
    return mDirContent;
}

From source file:Model.Picture.java

public static ArrayList<Picture> getNeighbors(String fileName) {
    ArrayList<Picture> neighbors = new ArrayList<Picture>();
    ArrayList<Picture> uploaded = (ArrayList) getUploadedPictures();

    for (int i = 0; i < uploaded.size() && neighbors.isEmpty(); i++) {
        if (uploaded.get(i).getName().equals(fileName)) {
            neighbors.addAll(Tools.getNeighbors(uploaded, i, Tools.NOT_CIRCULAR));
        }/*from   ww  w  .  ja v a  2  s.  c  o  m*/
    }

    return neighbors;
}

From source file:com.google.android.libraries.cast.companionlibrary.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 w  w.j a v a  2s. c o m
public static MediaInfo bundleToMediaInfo(Bundle wrapper) {
    if (wrapper == null) {
        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 (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.setContentId(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();
}