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.nts.alphamale.handler.DeviceHandler.java

public static String startActivity(List<String> serial, String activity, int timeoutSecond) {
    String rtnStr = "";
    List<CommandLine> cmdList = new ArrayList<CommandLine>();
    for (String s : serial) {
        cmdList.add(AdbShellCommand.cmd(s, "cmd_start_activity", new String[] { activity }));
    }//from ww w  .  java  2 s .co  m
    List<Map<String, Object>> results = new ExecutorHandler().executeParallel(cmdList, timeoutSecond);
    for (Map<String, Object> executorMap : results) {
        if (executorMap.isEmpty()) {
            break;
        }
        LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
        while (li != null && li.hasNext()) {
            rtnStr = li.nextLine();
        }
    }
    return rtnStr;
}

From source file:org.opendatakit.provider.FormsProviderUtils.java

/**
 * @param appName required.// w w w.  j  av a  2 s.  c o  m
 * @param tableId required.
 * @param formId  may be null. If null, screenPath and elementKeyToStringifiedValue must be null
 * @param instanceId may be null.
 * @param screenPath may be null.
 * @param elementKeyToValueMap may be null or empty. Contents are elementKey -to-
 *                                        value for that elementKey. Used to
 *                                        initialized field values and session variables.
 * @return URI for this survey and its arguments.
 */
public static String constructSurveyUri(String appName, String tableId, String formId, String instanceId,
        String screenPath, Map<String, Object> elementKeyToValueMap) {
    if (tableId == null) {
        WebLogger.getLogger(appName).e(TAG, "constructSurveyUri: tableId cannot be null returning.");
        return null;
    }
    if (formId == null && screenPath != null) {
        WebLogger.getLogger(appName).e(TAG,
                "constructSurveyUri: screenPath cannot be " + "specified if formId is null. returning.");
        return null;
    }
    if (formId == null && elementKeyToValueMap != null && !elementKeyToValueMap.isEmpty()) {
        WebLogger.getLogger(appName).e(TAG,
                "constructSurveyUri: jsonMap cannot be " + "specified if formId is null. returning.");
        return null;
    }

    // if no formId is specified, let ODK Survey choose the default form to use on this tableId.
    if (formId == null) {
        formId = "_";
    }

    Uri uri = Uri.withAppendedPath(
            Uri.withAppendedPath(Uri.withAppendedPath(FormsProviderAPI.CONTENT_URI, appName), tableId), formId);

    String uriStr = uri + "/" + "#";
    // Now we need to add our fragment parameters (client-side parsing).
    try {
        String continueStr = "";

        if (instanceId != null && !instanceId.isEmpty()) {
            uriStr += URI_SURVEY_QUERY_PARAM_INSTANCE_ID + "=" + encodeFragmentUnquotedStringValue(instanceId);
            continueStr = "&";
        }
        if (screenPath != null && !screenPath.isEmpty()) {
            uriStr += continueStr + URI_SURVEY_QUERY_PARAM_SCREEN_PATH + "="
                    + encodeFragmentUnquotedStringValue(screenPath);
            continueStr = "&";
        }
        if (elementKeyToValueMap != null && !elementKeyToValueMap.isEmpty()) {
            // We'll add all the entries to the URI as key-value pairs.
            // Use a StringBuilder in case we have a lot of these.
            // We'll assume we already have parameters added to the frame. This is
            // reasonable because this URI call thus far insists on an instanceId,
            // so
            // we know there will be at least that parameter.
            StringBuilder stringBuilder = new StringBuilder(uriStr);
            for (Map.Entry<String, Object> objEntry : elementKeyToValueMap.entrySet()) {
                // First add the ampersand
                stringBuilder.append(continueStr);
                continueStr = "&";
                stringBuilder.append(encodeFragmentUnquotedStringValue(objEntry.getKey()));
                stringBuilder.append("=");
                // JSON stringify the value then URL encode it.
                // We've got to replace the plus with %20, which is what js's
                // decodeURIComponent expects.
                String escapedValue = encodeFragmentObjectValue(objEntry.getValue());
                stringBuilder.append(escapedValue);
            }
            uriStr = stringBuilder.toString();
        }
    } catch (UnsupportedEncodingException e) {
        WebLogger.getLogger(appName).printStackTrace(e);
        throw new IllegalArgumentException("error escaping URI parameters");
    } catch (JsonProcessingException e) {
        WebLogger.getLogger(appName).printStackTrace(e);
        throw new IllegalArgumentException("error escaping elementKeyToValueMap parameter");
    }
    WebLogger.getLogger(appName).d(TAG, "constructSurveyUri: " + uriStr);
    return uriStr;
}

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

public static String clearAppData(List<String> serial, String pkgName, int timeoutSecond) {
    String rtnStr = "";
    List<CommandLine> cmdList = new ArrayList<CommandLine>();
    for (String s : serial) {
        cmdList.add(AdbShellCommand.cmd(s, "cmd_clear_app_data", new String[] { pkgName }));
    }// w w  w  .  j a  va2 s .  c  o  m
    List<Map<String, Object>> results = new ExecutorHandler().executeParallel(cmdList, timeoutSecond);
    for (Map<String, Object> executorMap : results) {
        if (executorMap.isEmpty()) {
            break;
        }
        LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
        while (li != null && li.hasNext()) {
            String device = li.nextLine();
            if (device.contains("Success")) {
                rtnStr = pkgName + " is cleared on " + serial + " device";
            }
        }
    }
    return rtnStr;
}

From source file:org.jodconverter.cli.Convert.java

private static Map<String, Object> buildProperties(final String[] args) {

    if (args == null || args.length == 0) {
        return null;
    }// ww w . j  ava  2 s. co m

    final Map<String, Object> argsMap = toMap(args);

    final Map<String, Object> properties = new HashMap<>();
    final Map<String, Object> filterDataProperties = new HashMap<>();
    for (final Map.Entry<String, Object> entry : argsMap.entrySet()) {
        final String key = entry.getKey();
        if (key.length() > 2 && key.startsWith("FD")) {
            filterDataProperties.put(key.substring("FD".length()), entry.getValue());
        } else {
            properties.put(key, entry.getValue());
        }
    }
    if (!filterDataProperties.isEmpty()) {
        properties.put("FilterData", filterDataProperties);
    }

    return properties;
}

From source file:com.dtolabs.rundeck.core.dispatcher.DataContextUtils.java

/**
 * Replace the embedded  properties of the form '${key.name}' in the input Strings with the value from the data
 * context/*from   w ww .j  a va  2 s  .  c om*/
 *
 * @param args argument string array
 * @param data data context
 * @return string array with replaced embedded properties
 */
public static String[] replaceDataReferences(final String[] args, final Map<String, Map<String, String>> data,
        Converter<String, String> converter, boolean failIfUnexpanded, boolean blankIfUnexpanded) {
    if (null == data || data.isEmpty()) {
        return args;
    }
    if (null == args || args.length < 1) {
        return args;
    }
    final String[] newargs = new String[args.length];

    for (int i = 0; i < args.length; i++) {
        final String arg = args[i];
        newargs[i] = replaceDataReferences(arg, data, converter, failIfUnexpanded, blankIfUnexpanded);
    }

    return newargs;
}

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

public static String installApp(List<String> serial, boolean isReinstall, String apkPath, int timeoutSecond) {
    String rtnStr = "";
    List<CommandLine> cmdList = new ArrayList<CommandLine>();
    for (String s : serial) {
        if (isReinstall) {
            cmdList.add(AdbShellCommand.cmd(s, "cmd_reinstall_app", new String[] { apkPath }));
        } else {/*from w  ww .ja  va  2 s .  c  o m*/
            cmdList.add(AdbShellCommand.cmd(s, "cmd_install_app", new String[] { apkPath }));
        }
    }
    List<Map<String, Object>> results = new ExecutorHandler().executeParallel(cmdList, timeoutSecond);
    for (Map<String, Object> executorMap : results) {
        if (executorMap.isEmpty()) {
            break;
        }
        LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
        while (li != null && li.hasNext()) {
            String output = li.nextLine();
            if (output.contains("Success")) {
                rtnStr = (new File(apkPath).getName() + " is successfully installed on " + serial + " device");
            }
            if (output.contains("Failure")) {
                rtnStr = ("Fail to install on " + serial + " device (" + output + ")");
            }
        }
    }
    return rtnStr;
}

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

public static List<String> unInstallApp(List<String> serial, boolean keepData, String pkgName,
        int timeoutSecond) {
    List<String> rtnStr = new ArrayList<String>();
    List<CommandLine> cmdList = new ArrayList<CommandLine>();
    for (String s : serial) {
        if (keepData) {
            cmdList.add(AdbShellCommand.cmd(s, "cmd_uninstall_app_keep_data", new String[] { pkgName }));
        } else {/* w w  w .  jav  a 2s  .c o m*/
            cmdList.add(AdbShellCommand.cmd(s, "cmd_uninstall_app", new String[] { pkgName }));
        }
    }

    List<Map<String, Object>> results = new ExecutorHandler().executeParallel(cmdList, timeoutSecond);
    for (Map<String, Object> executorMap : results) {
        if (executorMap.isEmpty()) {
            break;
        }
        LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
        while (li != null && li.hasNext()) {
            String device = li.nextLine();
            if (device.contains("Success")) {
                rtnStr.add(pkgName + " is successfully uninstalled on " + serial + " device");
            }
            if (device.contains("Failure")) {
                rtnStr.add("Fail to uninstalled on " + serial + " device");
            }
        }
    }
    return rtnStr;
}

From source file:net.firejack.platform.core.utils.db.DBUtils.java

private static ResultSet selectDataFromSource(Connection sourceConnection, TablesMapping mapping)
        throws SQLException {
    Map<Column, Column> columnMapping = mapping.getColumnMapping();
    StringBuilder selectQuery = new StringBuilder("select ");
    for (Map.Entry<Column, Column> columnEntry : columnMapping.entrySet()) {
        Column sourceColumn = columnEntry.getKey();
        selectQuery.append(sourceColumn.getName()).append(',');
    }//from   ww w. j a  v a  2s .c  om
    if (!columnMapping.isEmpty()) {
        selectQuery.replace(selectQuery.length() - 1, selectQuery.length(), "");
    }
    selectQuery.append(" from ").append(mapping.getSourceTable().getName());
    String sql = selectQuery.toString();
    Statement statement = sourceConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = statement.executeQuery(sql);
    rs.setFetchSize(DEFAULT_BATCH_SIZE);
    return rs;
}

From source file:com.inmobi.grill.server.metastore.JAXBUtils.java

public static DimensionTable dimTableFromCubeDimTable(CubeDimensionTable cubeDimTable) {
    if (cubeDimTable == null) {
        return null;
    }//from w w  w . j a  v  a 2 s  .  c  o m

    DimensionTable dimTab = XCF.createDimensionTable();
    dimTab.setName(cubeDimTable.getName());
    dimTab.setWeight(cubeDimTable.weight());

    Columns cols = XCF.createColumns();

    for (FieldSchema column : cubeDimTable.getColumns()) {
        cols.getColumns().add(columnFromFieldSchema(column));
    }
    dimTab.setColumns(cols);

    if (cubeDimTable.getDimensionReferences() != null && !cubeDimTable.getDimensionReferences().isEmpty()) {
        DimensionReferences dimRefs = XCF.createDimensionReferences();
        for (Entry<String, List<TableReference>> entry : cubeDimTable.getDimensionReferences().entrySet()) {
            DimensionReference ref = XCF.createDimensionReference();
            ref.setDimensionColumn(entry.getKey());
            ref.getTableReferences().addAll(dimRefListFromTabRefList(entry.getValue()));
            dimRefs.getDimReferences().add(ref);
        }
        dimTab.setDimensionReferences(dimRefs);
    }

    dimTab.setProperties(xPropertiesFromMap(cubeDimTable.getProperties()));

    Map<String, UpdatePeriod> storageToUpdatePeriod = cubeDimTable.getSnapshotDumpPeriods();
    if (storageToUpdatePeriod != null && !storageToUpdatePeriod.isEmpty()) {
        UpdatePeriods periods = XCF.createUpdatePeriods();

        for (Entry<String, UpdatePeriod> entry : storageToUpdatePeriod.entrySet()) {
            UpdatePeriodElement e = XCF.createUpdatePeriodElement();
            e.setStorageName(entry.getKey());
            if (entry.getValue() != null) {
                e.getUpdatePeriods().add(entry.getValue().toString());
            }
            periods.getUpdatePeriodElement().add(e);
        }
        dimTab.setStorageDumpPeriods(periods);
    }

    return dimTab;
}

From source file:com.vmware.bdd.utils.CommonUtil.java

public static <K, V> String inputsConvert(Map<K, V> wordsMap) {
    StringBuffer wordsBuff = new StringBuffer();
    if (wordsMap != null && !wordsMap.isEmpty()) {
        for (Entry<K, V> entry : wordsMap.entrySet()) {
            wordsBuff.append(entry.getKey()).append(":").append(entry.getValue()).append(",");
        }//from  ww w .j av  a 2s  . c o m
        wordsBuff.delete(wordsBuff.length() - 1, wordsBuff.length());
    }
    return wordsBuff.toString();
}