Example usage for java.util Map isEmpty

List of usage examples for java.util Map isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this map contains no key-value mappings.

Usage

From source file:com.silverpeas.gallery.dao.MediaDAO.java

/**
 * Adding all data of videos./*from w  w w.  j a  v a  2 s  .  c o  m*/
 * @param con
 * @param media
 * @param videos
 * @throws SQLException
 */
private static void decorateVideos(final Connection con, List<Media> media, Map<String, Video> videos)
        throws SQLException {
    if (!videos.isEmpty()) {
        Collection<Collection<String>> idGroups = CollectionUtil.split(new ArrayList<String>(videos.keySet()));
        StringBuilder queryBase = new StringBuilder(SELECT_INTERNAL_MEDIA_PREFIX)
                .append("V.resolutionW, V.resolutionH, V.bitrate, V.duration from SC_Gallery_Internal I join "
                        + "SC_Gallery_Video V on I.mediaId = V.mediaId where I.mediaId in ");
        for (Collection<String> mediaIds : idGroups) {
            PreparedStatement prepStmt = null;
            ResultSet rs = null;
            try {
                prepStmt = con.prepareStatement(DBUtil.appendListOfParameters(queryBase, mediaIds).toString());
                DBUtil.setParameters(prepStmt, mediaIds);
                rs = prepStmt.executeQuery();
                while (rs.next()) {
                    String mediaId = rs.getString(1);
                    mediaIds.remove(mediaId);
                    Video currentVideo = videos.get(mediaId);
                    decorateInternalMedia(rs, currentVideo);
                    currentVideo.setDefinition(Definition.of(rs.getInt(8), rs.getInt(9)));
                    currentVideo.setBitrate(rs.getLong(10));
                    currentVideo.setDuration(rs.getLong(11));
                }
            } finally {
                DBUtil.close(rs, prepStmt);
            }
            // Not found
            for (String mediaIdNotFound : mediaIds) {
                Video currentVideo = videos.remove(mediaIdNotFound);
                media.remove(currentVideo);
                SilverTrace.warn(GalleryComponentSettings.COMPONENT_NAME, "MediaDAO.decorateVideos()",
                        "root.MSG_GEN_PARAM_VALUE",
                        "video not found (removed from result): " + mediaIdNotFound);
            }
        }
    }
}

From source file:de.betterform.xml.xforms.ui.state.UIElementStateUtil.java

public static void dispatchBetterFormCustomMIPEvents(BindingElement bindingElement,
        Map<String, String> currentCustomProperties, Map<String, String> newCustomProperties)
        throws XFormsException {

    Set<String> keySet = new HashSet<String>();
    if (currentCustomProperties != null) {
        keySet.addAll(currentCustomProperties.keySet());
    }//from ww  w.j a v  a 2 s  .com
    if (newCustomProperties != null) {
        keySet.addAll(newCustomProperties.keySet());
    }
    Map<String, String> customMIP = new HashMap<String, String>();
    for (String key : keySet) {
        if (hasPropertyChanged(currentCustomProperties, newCustomProperties, key)) {
            customMIP.put(key, "" + WordUtils.capitalize(newCustomProperties.get(key)));
        }
    }
    if (!customMIP.isEmpty()) {
        Container container = bindingElement.getContainerObject();
        EventTarget eventTarget = bindingElement.getTarget();
        container.dispatch(eventTarget, BetterFormEventNames.CUSTOM_MIP_CHANGED, customMIP);
    }

}

From source file:com.nts.alphamale.handler.DeviceHandler.java

/**
 * adb kill-server && adb start-server  adb 
 * /*from  w w w  . j a  v a2  s . c  om*/
 */
public static void restartAdb() {
    Map<String, Object> executorMap = new AdbShellExecutor().execute(AdbShellCommand.cmd("", "cmd_kill_server"),
            true, Settings.EXECUTOR_TIMEOUT);
    if (!executorMap.isEmpty()) {
        Utils.destoryExecutor(executorMap.get("executor"));
    }
    executorMap = new AdbShellExecutor().execute(AdbShellCommand.cmd("", "cmd_start_server"), true,
            Settings.EXECUTOR_TIMEOUT);
    if (!executorMap.isEmpty()) {
        Utils.destoryExecutor(executorMap.get("executor"));
    }
}

From source file:com.nts.alphamale.handler.DeviceHandler.java

/**
 * adb devices  ? ?? ? ??  ? ?//from  w w  w.j  av a2 s.  c  om
 * 
 * @return
 */
public static boolean isAdbReady(String serial) {
    boolean rtnValue = false;
    Map<String, Object> executorMap = new AdbShellExecutor().execute(AdbShellCommand.cmd("", "cmd_devices"),
            true, Settings.EXECUTOR_TIMEOUT);
    if (executorMap.isEmpty()) {
        return rtnValue;
    }
    LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
    while (li != null && li.hasNext()) {
        String device = li.nextLine();
        if (!device.contains("List of devices attached") && device.contains(serial)) {
            rtnValue = true;
        }
    }
    Utils.destoryExecutor(executorMap.get("executor"));
    return rtnValue;
}

From source file:com.nts.alphamale.handler.DeviceHandler.java

public static List<String> getDeviceList() {
    List<String> deviceList = new ArrayList<String>();
    Map<String, Object> executorMap = new AdbShellExecutor().execute(AdbShellCommand.cmd("", "cmd_devices"),
            true, Settings.EXECUTOR_TIMEOUT);
    if (executorMap.isEmpty()) {
        return deviceList;
    }//w  w  w .  j  a v a  2 s. com
    LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
    while (li != null && li.hasNext()) {
        String device = li.nextLine();
        if (device.contains("device")) {
            if (!device.contains("List of devices attached"))
                deviceList.add(device.replace("device", "").trim());
        }
    }
    Utils.destoryExecutor(executorMap.get("executor"));
    return deviceList;
}

From source file:com.nts.alphamale.handler.DeviceHandler.java

public static Map<String, String> getProp(String serial) {
    Map<String, String> rtnValue = new HashMap<String, String>();
    Map<String, Object> executorMap = new AdbShellExecutor().execute(AdbShellCommand.cmd(serial, "cmd_getprop"),
            false, Settings.EXECUTOR_TIMEOUT);
    if (executorMap.isEmpty()) {
        return null;
    }//w  w  w  . j  av  a 2  s . com
    LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
    while (li != null && li.hasNext()) {
        String out = li.nextLine().trim();
        if (!out.isEmpty() && !out.startsWith("[]")) {
            out = out.replace("]: [", ":").replace("[", "").replace("]", "");
            if (out.split(":").length == 2)
                rtnValue.put(out.split(":")[0], out.split(":")[1]);
        }
    }
    Utils.destoryExecutor(executorMap.get("executor"));
    return rtnValue;
}

From source file:com.nts.alphamale.handler.DeviceHandler.java

public static StringBuilder readDump(String serial, String dumpPath, StringBuilder hierarchy) {
    Map<String, Object> executorMap = new AdbShellExecutor()
            .execute(AdbShellCommand.cmd(serial, "cmd_cat", new String[] { dumpPath }), false, 3 * 1000);

    if (executorMap.isEmpty()) {
        return new StringBuilder();
    }/*from  w  w  w.  j a v a2  s. c o m*/
    LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));

    while (li != null && li.hasNext()) {
        hierarchy.append(li.nextLine().trim());
    }

    Utils.destoryExecutor(executorMap.get("executor"));
    return hierarchy;
}

From source file:com.espertech.esper.epl.lookup.EventTableIndexUtil.java

public static Pair<IndexMultiKey, EventTableIndexEntryBase> findIndexBestAvailable(
        Map<IndexMultiKey, ? extends EventTableIndexEntryBase> tablesAvailable, Set<String> keyPropertyNames,
        Set<String> rangePropertyNames, List<IndexHintInstruction> optionalIndexHintInstructions) {
    if (keyPropertyNames.isEmpty() && rangePropertyNames.isEmpty()) {
        return null;
    }/*  w w  w . j ava 2 s  .  co  m*/

    // determine candidates
    List<IndexedPropDesc> hashProps = new ArrayList<IndexedPropDesc>();
    for (String keyPropertyName : keyPropertyNames) {
        hashProps.add(new IndexedPropDesc(keyPropertyName, null));
    }
    List<IndexedPropDesc> rangeProps = new ArrayList<IndexedPropDesc>();
    for (String rangePropertyName : rangePropertyNames) {
        rangeProps.add(new IndexedPropDesc(rangePropertyName, null));
    }
    Map<IndexMultiKey, EventTableIndexEntryBase> indexCandidates = (Map<IndexMultiKey, EventTableIndexEntryBase>) EventTableIndexUtil
            .findCandidates(tablesAvailable, hashProps, rangeProps);

    // handle hint
    if (optionalIndexHintInstructions != null) {
        IndexMultiKey found = EventTableIndexUtil.findByIndexHint(indexCandidates,
                optionalIndexHintInstructions);
        if (found != null) {
            return getPair(tablesAvailable, found);
        }
    }

    // no candidates
    if (indexCandidates == null || indexCandidates.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("No index found.");
        }
        return null;
    }

    return getBestCandidate(indexCandidates);
}

From source file:com.nts.alphamale.handler.DeviceHandler.java

public static void pull(String serial, String srcPath, String destPath) {
    Map<String, Object> executorMap = new AdbShellExecutor().execute(
            AdbShellCommand.cmd(serial, "cmd_pull", new String[] { srcPath, destPath }), true, 30 * 1000);
    if (!executorMap.isEmpty()) {
        Utils.destoryExecutor(executorMap.get("executor"));
    }/*from www. j  av  a 2s.  co  m*/
}

From source file:com.nts.alphamale.handler.DeviceHandler.java

/**
 * getInputManager? SurfaceOrientation?  ??
 * {@link #getInputManager(String)}//from   w w  w. j a  v a  2  s  .  c  o  m
 * 
 * @param serial
 * @return
 */
public static int getOrientation(String serial) {
    int rtnValue = 0;
    Map<String, Object> executorMap = new AdbShellExecutor()
            .execute(AdbShellCommand.cmd(serial, "cmd_get_orientation"), false, Settings.EXECUTOR_TIMEOUT);
    if (executorMap.isEmpty()) {
        return rtnValue;
    }
    LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
    while (li != null && li.hasNext()) {
        String out = li.nextLine().trim();
        if (out.contains("SurfaceOrientation:")) {
            rtnValue = Integer.parseInt(Utils.convertRegex("(\\d)", out, 1));
        }
    }
    Utils.destoryExecutor(executorMap.get("executor"));
    return rtnValue;
}