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.wavemaker.tools.ws.XJCCompiler.java

@SuppressWarnings("deprecation")
public static S2JJAXBModel createSchemaModel(Map<String, Element> schemas,
        List<com.wavemaker.tools.io.File> bindingFiles, String packageName, Set<String> auxiliaryClasses,
        WebServiceType type) throws GenerationException {
    if (schemas == null || schemas.isEmpty()) {
        return null;
    }/*ww w.ja v a  2  s . com*/
    SchemaCompiler sc = XJC.createSchemaCompiler();
    if (type == WebServiceType.SOAP) {
        // mimic what JAXWS's WsimportTool would do for SEI class name and
        // JAXB class name collision.
        ClassNameAllocator allocator = new ClassNameAllocatorImpl(
                new SimpleClassNameCollector(auxiliaryClasses));
        sc.setClassNameAllocator(allocator);
    }
    JAXBCompilerErrorListener listener = new JAXBCompilerErrorListener();
    sc.setErrorListener(listener);
    try {
        Field ncc = sc.getClass().getDeclaredField("NO_CORRECTNESS_CHECK");
        ncc.setAccessible(true);
        ncc.set(sc, true);
    } catch (Exception e) {
        throw new GenerationException(e);
    }

    if (packageName != null) {
        sc.setDefaultPackageName(packageName);
    }

    for (Entry<String, Element> entry : schemas.entrySet()) {
        Element schema = entry.getValue();
        // need to remove xsd:import or you will get element/type already
        // defined error during sc.bind()
        Element updatedSchema = removeImportElement(schema);

        sc.parseSchema(entry.getKey(), updatedSchema);
    }

    if (bindingFiles != null) {
        for (com.wavemaker.tools.io.File file : bindingFiles) {
            try {
                InputSource inputSource = new InputSource(file.getContent().asInputStream());
                // cftempfix - if binding files are NOT ALWAYS local files (eg. mongo DB file), we may need to
                // correctly implement
                // logic for none-local file case.
                if (file instanceof LocalFile) {
                    File f = ((LocalFile) file).getLocalFile();
                    inputSource.setSystemId(f.toURI().toString());
                } else {
                    inputSource.setSystemId(ResourceURL.get(file).toURI().toString());
                }
                sc.parseSchema(inputSource);
            } catch (MalformedURLException e) {
                throw new GenerationException(e);
            } catch (URISyntaxException e) {
                throw new GenerationException(e);
            }
        }
    }

    Options options = sc.getOptions();
    options.target = SpecVersion.V2_1;
    // suppress generation of package level annotations
    options.packageLevelAnnotations = false;
    // generate setter methods for Collection based properties
    options.activePlugins.add(new com.sun.tools.xjc.addon.collection_setter_injector.PluginImpl());
    // replace isXXX with getXXX for Boolean type properties
    options.activePlugins.add(new com.wavemaker.tools.ws.jaxb.boolean_getter.PluginImpl());

    S2JJAXBModel model = sc.bind();
    if (listener.hasError) {
        throw listener.getException();
    }
    return model;
}

From source file:com.comcast.cats.service.util.HttpClientUtil.java

public static synchronized Object getForObject(String uri, Map<String, String> paramMap) {
    Object responseObject = new Object();

    HttpMethod httpMethod = new GetMethod(uri);

    if ((null != paramMap) && (!paramMap.isEmpty())) {
        httpMethod.setQueryString(getNameValuePair(paramMap));
    }/*from   ww w.  ja v  a 2  s . c  o  m*/

    Yaml yaml = new Yaml();

    HttpClient client = new HttpClient();
    InputStream responseStream = null;
    Reader inputStreamReader = null;

    try {
        int responseCode = client.executeMethod(httpMethod);

        if (HttpStatus.SC_OK != responseCode) {
            logger.error("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.error("[ METHOD   ] " + httpMethod.getName());
            logger.error("[ STATUS   ] " + responseCode);
        } else {
            logger.trace("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.trace("[ METHOD   ] " + httpMethod.getName());
            logger.trace("[ STATUS   ] " + responseCode);
        }

        responseStream = httpMethod.getResponseBodyAsStream();
        inputStreamReader = new InputStreamReader(responseStream, VideoRecorderServiceConstants.UTF);
        responseObject = yaml.load(inputStreamReader);
    } catch (IOException ioException) {
        ioException.printStackTrace();
    } finally {
        cleanUp(inputStreamReader, responseStream, httpMethod);
    }

    return responseObject;
}

From source file:com.shenit.commons.utils.ValidationUtils.java

/**
 * Indicates whether a collection is null or consist of null
 * /* ww  w .  j  a  v  a  2s.  co  m*/
 * @param cols
 *            A collection
 * @return True if the collection input is null, or consist of null. False if one of its item is not null
 */
public static boolean isEmpty(Map<?, ?> cols) {
    return cols == null || cols.isEmpty();
}

From source file:com.comcast.cats.service.util.HttpClientUtil.java

public static synchronized Object postForObject(String uri, Map<String, String> paramMap) {
    Object responseObject = new Object();

    HttpMethod httpMethod = new PostMethod(uri);

    if ((null != paramMap) && (!paramMap.isEmpty())) {
        httpMethod.setQueryString(getNameValuePair(paramMap));
    }//from  ww w.j  a v  a  2 s  . c  o m

    Yaml yaml = new Yaml();

    HttpClient client = new HttpClient();
    InputStream responseStream = null;
    Reader inputStreamReader = null;

    try {
        int responseCode = client.executeMethod(httpMethod);

        if (HttpStatus.SC_OK != responseCode) {
            logger.error("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.error("[ METHOD   ] " + httpMethod.getName());
            logger.error("[ STATUS   ] " + responseCode);
        } else {
            logger.trace("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.trace("[ METHOD   ] " + httpMethod.getName());
            logger.trace("[ STATUS   ] " + responseCode);
        }

        responseStream = httpMethod.getResponseBodyAsStream();
        inputStreamReader = new InputStreamReader(responseStream, VideoRecorderServiceConstants.UTF);
        responseObject = yaml.load(inputStreamReader);
    } catch (IOException ioException) {
        ioException.printStackTrace();
    } finally {
        cleanUp(inputStreamReader, responseStream, httpMethod);
    }

    return responseObject;
}

From source file:com.comcast.cats.service.util.HttpClientUtil.java

public static synchronized Object deleteForObject(String uri, Map<String, String> paramMap) {
    Object responseObject = new Object();

    HttpMethod httpMethod = new DeleteMethod(uri);

    if ((null != paramMap) && (!paramMap.isEmpty())) {
        httpMethod.setQueryString(getNameValuePair(paramMap));
    }/*  ww w  .  j  a  va  2  s .c o  m*/

    Yaml yaml = new Yaml();

    HttpClient client = new HttpClient();
    InputStream responseStream = null;
    Reader inputStreamReader = null;

    try {
        int responseCode = client.executeMethod(httpMethod);

        if (HttpStatus.SC_OK != responseCode) {
            logger.error("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.error("[ METHOD   ] " + httpMethod.getName());
            logger.error("[ STATUS   ] " + responseCode);
        } else {
            logger.trace("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.trace("[ METHOD   ] " + httpMethod.getName());
            logger.trace("[ STATUS   ] " + responseCode);
        }

        responseStream = httpMethod.getResponseBodyAsStream();
        inputStreamReader = new InputStreamReader(responseStream, VideoRecorderServiceConstants.UTF);
        responseObject = yaml.load(inputStreamReader);
    } catch (IOException ioException) {
        ioException.printStackTrace();
    } finally {
        cleanUp(inputStreamReader, responseStream, httpMethod);
    }

    return responseObject;
}

From source file:de.cebitec.readXplorer.util.GeneralUtils.java

/**
* Joins a map of elements in a String.//from w w w.jav  a  2 s. c om
* @param valueDelim Delimiter between key and value of an element
* @param entryDelim Delimiter between each Entry element
* @param map a map of elements
* @return String
*/
public static String implodeMap(String valueDelim, String entryDelim, Map map) {
    String asImplodedString;
    if ((map == null) || (map.isEmpty())) {
        asImplodedString = "";
    } else {
        StringBuilder sb = new StringBuilder();
        Boolean firstLine = true;
        for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
            if (!firstLine) {
                sb.append(entryDelim);
            }
            Map.Entry line = (Map.Entry) it.next();
            sb.append(line.getKey());
            sb.append(valueDelim);
            sb.append(line.getValue());
            firstLine = false;
        }
        asImplodedString = sb.toString();
    }
    return asImplodedString;
}

From source file:eu.squadd.reflections.mapper.ServiceModelTranslator.java

private static void assignMapValue(Method getter, Object sourceValue, Method setter, Object destInstance) {
    System.out.println("*** Map found, resolving its payload types...");
    if (sourceValue == null || ((Map) sourceValue).isEmpty())
        return;//from   ww  w  .  j a v  a2 s  .c  o m

    Map<Integer, Class> sourceMapTypes = detectSourceMapPayload(getter);
    if (sourceMapTypes.isEmpty() || sourceMapTypes.size() != 2) {
        System.err.println("Failed to determine source Map payload types, operation aborted !!!");
        return;
    }
    Class firstSourceArgClass = sourceMapTypes.get(0);
    Class secondSourceArgClass = sourceMapTypes.get(1);

    Map<Integer, Class> destMapTypes = detectDestMapPayload(setter);
    if (destMapTypes.isEmpty() || destMapTypes.size() != 2) {
        System.err.println("Failed to determine destination Map payload types, operation aborted !!!");
        return;
    }
    Class firstDestArgClass = destMapTypes.get(0);
    Class secordDestArgsClass = destMapTypes.get(1);

    if (!firstSourceArgClass.equals(firstDestArgClass)) {
        System.err.println("Map key types are different, can't translate values !!!");
        return;
    }

    System.out.println("*** Map types sorted, populating values...");
    Map sourceItems = (Map) sourceValue;
    Map destItems = createMapOfTypes(firstDestArgClass, secordDestArgsClass);
    for (Object key : sourceItems.entrySet()) {
        Entry entry = (Entry) destItems.get(key);
        Object destValue = transposeModel(secondSourceArgClass, secordDestArgsClass, entry.getValue());
        destItems.put(entry.getKey(), destValue);
    }
    try {
        setter.invoke(destInstance, destItems);

    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
        Logger.getLogger(ServiceModelTranslator.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.println("*** done");
}

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

private static void insertDataToTargetTable(TablesMapping mapping, Connection sourceConnection,
        Connection targetConnection) throws SQLException {
    Map<Column, Column> columnMapping = mapping.getColumnMapping();
    if (columnMapping.isEmpty()) {
        logger.warn("No columns are detected - no data to insert.");
    } else {//  w ww  . j av  a 2  s .c  om
        ResultSet rs = selectDataFromSource(sourceConnection, mapping);

        String insertQuery = populateInsertQuery(mapping);
        PreparedStatement insertStatement = targetConnection.prepareStatement(insertQuery);
        targetConnection.setAutoCommit(false);
        try {
            int currentStep = 1;
            while (rs.next()) {
                for (int i = 1; i <= columnMapping.size(); i++) {
                    insertStatement.setObject(i, rs.getObject(i));
                }
                insertStatement.addBatch();
                if (++currentStep > DEFAULT_BATCH_SIZE) {
                    insertStatement.executeBatch();
                    targetConnection.commit();
                    currentStep = 1;
                }
            }
            if (currentStep != 1) {
                insertStatement.executeBatch();
                targetConnection.commit();
            }
        } catch (SQLException e) {
            logger.error(e.getMessage(), e);
            targetConnection.rollback();
        } finally {
            insertStatement.close();
            rs.close();
        }
    }
}

From source file:com.glaf.core.util.http.CommonsHttpClientUtils.java

/**
 * ??GET/*ww w  .  ja v  a 2  s.c  o m*/
 * 
 * @param url
 *            ??
 * @param encoding
 *            
 * @param dataMap
 *            ?
 * 
 * @return
 */
public static String doGet(String url, String encoding, Map<String, String> dataMap) {
    GetMethod method = null;
    String content = null;
    try {
        method = new GetMethod(url);
        method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, encoding);
        method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding);
        if (dataMap != null && !dataMap.isEmpty()) {
            NameValuePair[] nameValues = new NameValuePair[dataMap.size()];
            int i = 0;
            for (Map.Entry<String, String> entry : dataMap.entrySet()) {
                String name = entry.getKey().toString();
                String value = entry.getValue();
                nameValues[i] = new NameValuePair(name, value);
                i++;
            }
            method.setQueryString(nameValues);
        }
        HttpClient client = new HttpClient();
        int status = client.executeMethod(method);
        if (status == HttpStatus.SC_OK) {
            content = method.getResponseBodyAsString();
        }
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } finally {
        if (method != null) {
            method.releaseConnection();
            method = null;
        }
    }
    return content;
}

From source file:com.glaf.core.util.http.CommonsHttpClientUtils.java

/**
 * ??POST//  w w w  .j a  v a  2 s  .c o m
 * 
 * @param url
 *            ??
 * @param encoding
 *            
 * @param dataMap
 *            ?
 * 
 * @return
 */
public static String doPost(String url, String encoding, Map<String, String> dataMap) {
    PostMethod method = null;
    String content = null;
    try {
        method = new PostMethod(url);
        method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, encoding);
        method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding);
        if (dataMap != null && !dataMap.isEmpty()) {
            NameValuePair[] nameValues = new NameValuePair[dataMap.size()];
            int i = 0;
            for (Map.Entry<String, String> entry : dataMap.entrySet()) {
                String name = entry.getKey().toString();
                String value = entry.getValue();
                nameValues[i] = new NameValuePair(name, value);
                i++;
            }
            method.setRequestBody(nameValues);
        }
        HttpClient client = new HttpClient();
        int status = client.executeMethod(method);
        if (status == HttpStatus.SC_OK) {
            content = method.getResponseBodyAsString();
        }
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } finally {
        if (method != null) {
            method.releaseConnection();
            method = null;
        }
    }
    return content;
}