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.mywork.framework.util.RemoteHttpUtil.java

/**
 * ?? Post//  w ww . j  a v  a  2s.  c o  m
 * @return
 */
public static String doPost(String contentUrl, Map<String, String> headerMap, String jsonBody) {
    String result = null;
    CloseableHttpResponse response = null;
    CloseableHttpClient httpClient = HttpClients.createDefault();
    HttpPost post = new HttpPost(contentUrl);
    RequestConfig config = RequestConfig.custom().setConnectionRequestTimeout(TIMEOUT_SECONDS * 1000)
            .setConnectTimeout(TIMEOUT_SECONDS * 1000).setSocketTimeout(TIMEOUT_SECONDS * 1000).build();
    post.setConfig(config);

    try {
        if (headerMap != null && !headerMap.isEmpty()) {
            for (Map.Entry<String, String> m : headerMap.entrySet()) {
                post.setHeader(m.getKey(), m.getValue());
            }
        }

        if (jsonBody != null) {
            StringEntity entity = new StringEntity(jsonBody, "utf-8");
            entity.setContentEncoding("UTF-8");
            entity.setContentType("application/json");
            post.setEntity(entity);
        }
        long start = System.currentTimeMillis();
        response = httpClient.execute(post);
        HttpEntity entity = response.getEntity();
        result = EntityUtils.toString(entity);
        logger.info("url = " + contentUrl + " request spend time = " + (System.currentTimeMillis() - start));
        EntityUtils.consume(entity);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            response.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return result;
}

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

public static boolean isKeyPadAppear(String serial) {
    Map<String, Object> executorMap = new AdbShellExecutor()
            .execute(AdbShellCommand.cmd(serial, "cmd_keypad_monitor"), false, Settings.EXECUTOR_TIMEOUT);

    if (executorMap.isEmpty()) {
        return false;
    }/* ww w  . j  av  a 2s  . c  o m*/
    LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));

    if (li != null && li.hasNext()) {
        String str = li.nextLine().trim();
        if (str.contains("HasSurface=true")) {
            DataQueue.IS_KEYPAD_ON = true;
        } else {
            DataQueue.IS_KEYPAD_ON = false;
        }
    }

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

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

public static List<String> get3rdPartyPackageList(String serial) {
    List<String> pkgList = new ArrayList<String>();
    Map<String, Object> executorMap = new AdbShellExecutor().execute(
            AdbShellCommand.cmd(serial, "cmd_3rd_party_package_list"), false, Settings.EXECUTOR_TIMEOUT);
    if (executorMap.isEmpty()) {
        return pkgList;
    }//from w  w w .j av  a2  s. c  o  m
    LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));
    while (li != null && li.hasNext()) {
        String str = li.nextLine().trim();
        if (str.contains("package:")) {
            pkgList.add(str.replace("package:", ""));
        }
    }
    Utils.destoryExecutor(executorMap.get("executor"));
    return pkgList;
}

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

public static String getTopActivity(String serial) {
    String rtnValue = "";
    Map<String, Object> executorMap = new AdbShellExecutor()
            .execute(AdbShellCommand.cmd(serial, "cmd_dumpsys_activity_top"), false, Settings.EXECUTOR_TIMEOUT);

    if (executorMap.isEmpty()) {
        return rtnValue;
    }//from  w w  w. jav a  2  s .co  m
    LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));

    while (li != null && li.hasNext()) {
        String output = li.nextLine();
        if (output.contains("ACTIVITY")) {
            rtnValue = output.trim().split(" ")[1];
        }
    }
    Utils.destoryExecutor(executorMap.get("executor"));
    return rtnValue;
}

From source file:com.github.dryangkun.hbase.tidx.hive.HBaseSerDeHelper.java

/**
 * Autogenerates the column types from the given serialization class
 * //from w w  w .  ja v a 2s .  co m
 * @param tbl the hive table properties
 * @param columnsMapping the hbase columns mapping determining hbase column families and
 *          qualifiers
 * @param sb StringBuilder to form the list of columns
 * @param conf configuration
 * @throws IllegalArgumentException if any of the given arguments was null
 * @throws SerDeException if there was an error generating the column types
 * */
public static void generateColumnTypes(Properties tbl, List<ColumnMapping> columnsMapping, StringBuilder sb,
        Configuration conf) throws SerDeException {

    if (tbl == null) {
        throw new IllegalArgumentException("tbl cannot be null");
    }

    if (columnsMapping == null) {
        throw new IllegalArgumentException("columnsMapping cannot be null");
    }

    if (sb == null) {
        throw new IllegalArgumentException("StringBuilder cannot be null");
    }

    // Generate the columns according to the column mapping provided
    for (int i = 0; i < columnsMapping.size(); i++) {
        if (sb.length() > 0) {
            sb.append(":");
        }

        ColumnMapping colMap = columnsMapping.get(i);

        if (colMap.hbaseRowKey) {

            Map<String, String> compositeKeyParts = getCompositeKeyParts(tbl);
            StringBuilder keyStruct = new StringBuilder();

            if (compositeKeyParts == null || compositeKeyParts.isEmpty()) {
                String compKeyClass = tbl.getProperty(HBaseSerDe.HBASE_COMPOSITE_KEY_CLASS);
                String compKeyTypes = tbl.getProperty(HBaseSerDe.HBASE_COMPOSITE_KEY_TYPES);

                if (compKeyTypes == null) {

                    if (compKeyClass != null) {
                        // a composite key class was provided. But neither the types
                        // property was set and
                        // neither the getParts() method of HBaseCompositeKey was
                        // overidden in the
                        // implementation. Flag exception.
                        throw new SerDeException(
                                "Either the hbase.composite.key.types property should be set or the getParts method must be overridden in "
                                        + compKeyClass);
                    }

                    // the row key column becomes a STRING
                    sb.append(serdeConstants.STRING_TYPE_NAME);
                } else {
                    generateKeyStruct(compKeyTypes, keyStruct);
                }
            } else {
                generateKeyStruct(compositeKeyParts, keyStruct);
            }
            sb.append(keyStruct);
        } else if (colMap.qualifierName == null) {

            String serClassName = null;
            String serType = null;
            String schemaLiteral = null;
            String schemaUrl = null;

            if (colMap.qualifierPrefix != null) {

                serType = tbl.getProperty(
                        colMap.familyName + "." + colMap.qualifierPrefix + "." + HBaseSerDe.SERIALIZATION_TYPE);

                if (serType == null) {
                    throw new SerDeException(
                            HBaseSerDe.SERIALIZATION_TYPE + " property not provided for column family ["
                                    + colMap.familyName + "] and prefix [" + colMap.qualifierPrefix + "]");
                }

                // we are provided with a prefix
                serClassName = tbl.getProperty(colMap.familyName + "." + colMap.qualifierPrefix + "."
                        + serdeConstants.SERIALIZATION_CLASS);

                if (serClassName == null) {
                    if (serType.equalsIgnoreCase(HBaseSerDeParameters.AVRO_SERIALIZATION_TYPE)) {
                        // for avro type, the serialization class parameter is optional
                        schemaLiteral = tbl.getProperty(colMap.familyName + "." + colMap.qualifierPrefix + "."
                                + AvroSerdeUtils.SCHEMA_LITERAL);
                        schemaUrl = tbl.getProperty(colMap.familyName + "." + colMap.qualifierPrefix + "."
                                + AvroSerdeUtils.SCHEMA_URL);

                        if (schemaLiteral == null && schemaUrl == null) {
                            // either schema literal, schema url or serialization class must
                            // be provided
                            throw new SerDeException("For an avro schema, either "
                                    + AvroSerdeUtils.SCHEMA_LITERAL + ", " + AvroSerdeUtils.SCHEMA_URL + " or "
                                    + serdeConstants.SERIALIZATION_CLASS + " property must be set.");
                        }

                        if (schemaUrl != null) {
                            schemaLiteral = getSchemaFromFS(schemaUrl, conf).toString();
                        }

                    } else {
                        throw new SerDeException(serdeConstants.SERIALIZATION_CLASS
                                + " property not provided for column family [" + colMap.familyName
                                + "] and prefix [" + colMap.qualifierPrefix + "]");
                    }
                }
            } else {
                serType = tbl.getProperty(colMap.familyName + "." + HBaseSerDe.SERIALIZATION_TYPE);

                if (serType == null) {
                    throw new SerDeException(HBaseSerDe.SERIALIZATION_TYPE
                            + " property not provided for column family [" + colMap.familyName + "]");
                }

                serClassName = tbl.getProperty(colMap.familyName + "." + serdeConstants.SERIALIZATION_CLASS);

                if (serClassName == null) {

                    if (serType.equalsIgnoreCase(AVRO_SERIALIZATION_TYPE)) {
                        // for avro type, the serialization class parameter is optional
                        schemaLiteral = tbl
                                .getProperty(colMap.familyName + "." + AvroSerdeUtils.SCHEMA_LITERAL);
                        schemaUrl = tbl.getProperty(colMap.familyName + "." + AvroSerdeUtils.SCHEMA_URL);

                        if (schemaLiteral == null && schemaUrl == null) {
                            // either schema literal or serialization class must be provided
                            throw new SerDeException("For an avro schema, either "
                                    + AvroSerdeUtils.SCHEMA_LITERAL + " property or "
                                    + serdeConstants.SERIALIZATION_CLASS + " property must be set.");
                        }

                        if (schemaUrl != null) {
                            schemaLiteral = getSchemaFromFS(schemaUrl, conf).toString();
                        }
                    } else {
                        throw new SerDeException(serdeConstants.SERIALIZATION_CLASS
                                + " property not provided for column family [" + colMap.familyName + "]");
                    }
                }
            }

            StringBuilder generatedStruct = new StringBuilder();

            // generate struct for each of the given prefixes
            generateColumnStruct(serType, serClassName, schemaLiteral, colMap, generatedStruct);

            // a column family becomes a MAP
            sb.append(serdeConstants.MAP_TYPE_NAME + "<" + serdeConstants.STRING_TYPE_NAME + ","
                    + generatedStruct + ">");

        } else {

            String qualifierName = colMap.qualifierName;

            if (colMap.qualifierName.endsWith("*")) {
                // we are provided with a prefix
                qualifierName = colMap.qualifierName.substring(0, colMap.qualifierName.length() - 1);
            }

            String serType = tbl
                    .getProperty(colMap.familyName + "." + qualifierName + "." + HBaseSerDe.SERIALIZATION_TYPE);

            if (serType == null) {
                throw new SerDeException(
                        HBaseSerDe.SERIALIZATION_TYPE + " property not provided for column family ["
                                + colMap.familyName + "] and qualifier [" + qualifierName + "]");
            }

            String serClassName = tbl.getProperty(
                    colMap.familyName + "." + qualifierName + "." + serdeConstants.SERIALIZATION_CLASS);

            String schemaLiteral = null;
            String schemaUrl = null;

            if (serClassName == null) {

                if (serType.equalsIgnoreCase(AVRO_SERIALIZATION_TYPE)) {
                    // for avro type, the serialization class parameter is optional
                    schemaLiteral = tbl.getProperty(
                            colMap.familyName + "." + qualifierName + "." + AvroSerdeUtils.SCHEMA_LITERAL);
                    schemaUrl = tbl.getProperty(
                            colMap.familyName + "." + qualifierName + "." + AvroSerdeUtils.SCHEMA_URL);

                    if (schemaLiteral == null && schemaUrl == null) {
                        // either schema literal, schema url or serialization class must
                        // be provided
                        throw new SerDeException("For an avro schema, either " + AvroSerdeUtils.SCHEMA_LITERAL
                                + ", " + AvroSerdeUtils.SCHEMA_URL + " or " + serdeConstants.SERIALIZATION_CLASS
                                + " property must be set.");
                    }

                    if (schemaUrl != null) {
                        schemaLiteral = getSchemaFromFS(schemaUrl, conf).toString();
                    }
                } else {
                    throw new SerDeException(
                            serdeConstants.SERIALIZATION_CLASS + " property not provided for column family ["
                                    + colMap.familyName + "] and qualifier [" + qualifierName + "]");
                }
            }

            StringBuilder generatedStruct = new StringBuilder();

            generateColumnStruct(serType, serClassName, schemaLiteral, colMap, generatedStruct);

            sb.append(generatedStruct);
        }
    }

    // trim off ending ",", if any
    trim(sb);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Generated column types: [" + sb.toString() + "]");
    }
}

From source file:com.jim.im.utils.Assert.java

/**
 * Assert that a Map has entries.//  www. ja  v a  2  s  .com
 * <p/>
 * 
 * <pre class="code">
 * Assert.notEmpty(MAP, &quot;Map must have entries&quot;);
 * </pre>
 *
 * @param map the MAP to check
 * @param message the exception message to use if the assertion fails
 * @throws IllegalStateException if the MAP is <code>null</code> or has no entries
 */
public static void notEmpty(Map map, String message) {
    if (map == null || map.isEmpty()) {
        throwException(message);
    }
}

From source file:io.fabric8.maven.core.util.KubernetesResourceUtil.java

private static LabelSelector toLabelSelector(Map<String, String> matchLabels) {
    if (matchLabels != null && !matchLabels.isEmpty()) {
        return new LabelSelectorBuilder().withMatchLabels(matchLabels).build();
    }//from w  w w.  jav  a 2 s  . c om
    return null;
}

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

public static Map<String, String> getCurrentActivity(String serial) {
    Map<String, String> currentActivity = new HashMap<String, String>();
    String activityName = "";
    Map<String, Object> executorMap = new AdbShellExecutor()
            .execute(AdbShellCommand.cmd(serial, "cmd_dumpsys_activity_top"), false, Settings.EXECUTOR_TIMEOUT);

    if (executorMap.isEmpty()) {
        return currentActivity;
    }//from w ww .  j a  v a2s .co m
    LineIterator li = Utils.getLineIterator(executorMap.get("stdOut"));

    boolean isHierarchyInfo = false;
    StringBuilder sb = new StringBuilder();

    while (li != null && li.hasNext()) {
        String output = li.nextLine();
        if (output.contains("ACTIVITY")) {
            activityName = output.trim().split(" ")[1];
        }
        if (output.contains("Looper"))
            isHierarchyInfo = false;
        if (isHierarchyInfo) {
            output = output.split("\\{")[0].trim();
            if (!output.isEmpty())
                sb.append(output + "\n");
        }
        if (output.contains("View Hierarchy"))
            isHierarchyInfo = true;
    }
    currentActivity.put(activityName, sb.toString());
    Utils.destoryExecutor(executorMap.get("executor"));
    return currentActivity;
}

From source file:it.geosolutions.imageio.plugins.nitronitf.NITFImageWriter.java

/**
 * /*from  ww w . j a  va  2s.c o  m*/
 * @param subheader
 * @param isSingleBand
 * @param compression
 * @param tresMap
 * @param bpppb
 * @throws NITFException
 */
private static void initTREs(final ImageSubheader subheader, final ImageWrapper wrapper,
        final WriteCompression compression, final double bpppb) throws NITFException {
    Extensions extendedSection = subheader.getExtendedSection();
    final boolean isSingleBand = wrapper.getImage().getSampleModel().getNumBands() == 1;
    final Map<String, Map<String, String>> tresMap = wrapper.getTres();
    if (tresMap != null && !tresMap.isEmpty()) {
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.log(Level.FINE, "Populating TRE");
        }

        Set<String> keys = tresMap.keySet();
        Iterator<String> it = keys.iterator();
        while (it.hasNext()) {
            String treName = it.next();
            Map<String, String> fieldsMapping = tresMap.get(treName);
            TRE tre = setTRE(treName, fieldsMapping);
            extendedSection.appendTRE(tre);
        }
    }

    if (compression != WriteCompression.UNCOMPRESSED) {
        //Setting the J2KLRA TRE in case the image need to be jp2 compressed
        setJ2KLRA(extendedSection, compression, isSingleBand, bpppb);
    }

}

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

public static void pushJar(String serial, String jarPath) {
    Map<String, Object> executorMap = new AdbShellExecutor().execute(
            AdbShellCommand.cmd(serial, "cmd_push", new String[] { jarPath, "/data/local/tmp/" }), true,
            30 * 1000);/*from  w w w .j  a  v a 2 s  .c o m*/
    if (!executorMap.isEmpty()) {
        Utils.destoryExecutor(executorMap.get("executor"));
    }
}