Example usage for java.util HashMap isEmpty

List of usage examples for java.util HashMap isEmpty

Introduction

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

Prototype

public boolean isEmpty() 

Source Link

Document

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

Usage

From source file:de.gfz_potsdam.datasync.Datasync.java

public void syncDeletedToRemote(String basedir, HashSet<String> entities, Container parent) throws Exception {

    //delete in infrastructure container members, where there is no local file but it is in our database

    if (parent == null)
        return;/*w w w  .j  a  v a2  s . c  o m*/

    HashMap<String, String> syncedfiles = App.db.listEntries(basedir, File.separator);
    HashMap<String, String> srvdelete = new HashMap<String, String>();

    HashMap<String, Integer> pathToIdCount = new HashMap<String, Integer>();
    for (String path : syncedfiles.keySet()) {
        String id = syncedfiles.get(path);
        Integer count = pathToIdCount.get(id);
        if (count == null)
            count = new Integer(1);
        else
            count = new Integer(count.intValue() + 1);
        pathToIdCount.put(id, count);
    }

    for (String path : syncedfiles.keySet()) {
        String id = syncedfiles.get(path);
        Integer count = pathToIdCount.get(id);
        if (!entities.contains(path)) {
            if (count.intValue() <= 1) {
                srvdelete.put(path, id);
                log.log(Level.INFO, "Remote delete: {0} {1}", new Object[] { path, id });
            }
        }
    }
    //items with more components

    if (!srvdelete.isEmpty()) {

        srv.containerRemoveMembers(parent, srvdelete.values());
        for (String path : srvdelete.keySet()) {
            App.db.deleteMapping(path, srvdelete.get(path), File.separator);

        }
        File parentdir = new File(directory + File.separator + basedir);
        App.db.storeMapping(basedir, parent.getObjid(), parentdir.lastModified(),
                parent.getLastModificationDate(), SyncDB.DIRECTORY);

    }

}

From source file:com.thoughtworks.go.server.service.RulesService.java

public boolean validateSecretConfigReferences(ScmMaterial scmMaterial) {
    List<CaseInsensitiveString> pipelines = goConfigService.pipelinesWithMaterial(scmMaterial.getFingerprint());

    HashMap<CaseInsensitiveString, StringBuilder> pipelinesWithErrors = new HashMap<>();
    pipelines.forEach(pipelineName -> {
        MaterialConfig materialConfig = goConfigService.findPipelineByName(pipelineName).materialConfigs()
                .getByMaterialFingerPrint(scmMaterial.getFingerprint());
        PipelineConfigs group = goConfigService.findGroupByPipeline(pipelineName);
        ScmMaterialConfig scmMaterialConfig = (ScmMaterialConfig) materialConfig;
        SecretParams secretParams = SecretParams.parse(scmMaterialConfig.getPassword());
        secretParams.forEach(secretParam -> {
            String secretConfigId = secretParam.getSecretConfigId();
            SecretConfig secretConfig = goConfigService.getSecretConfigById(secretConfigId);
            if (secretConfig == null) {
                addError(pipelinesWithErrors, pipelineName,
                        format("Pipeline '%s' is referring to none-existent secret config '%s'.", pipelineName,
                                secretConfigId));
            } else if (!secretConfig.canRefer(group.getClass(), group.getGroup())) {
                addError(pipelinesWithErrors, pipelineName, format(
                        "Pipeline '%s' does not have permission to refer to secrets using secret config '%s'",
                        pipelineName, secretConfigId));
            }// w ww  .  ja  v  a  2 s  .c  om
        });
    });
    StringBuilder errorMessage = new StringBuilder();
    if (!pipelinesWithErrors.isEmpty()) {
        errorMessage.append(StringUtils.join(pipelinesWithErrors.values(), '\n').trim());
        LOGGER.error("[Material Update] Failure: {}", errorMessage.toString());
    }
    if (pipelines.size() == pipelinesWithErrors.size()) {
        throw new RulesViolationException(errorMessage.toString());
    }
    return true;
}

From source file:com.yahoo.ycsb.db.RedisClient.java

@Override
public int read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    if (fields == null) {

        if (cluster) {
            Map<String, String> in = jedisCluster.hgetAll(key);
            for (String s : in.keySet()) {
                result.put(s, decompress(new StringByteIterator(in.get(s))));
            }//  w ww.j  av  a  2s .co  m
        } else {
            Map<String, String> in = jedis.hgetAll(key);
            for (String s : in.keySet()) {
                result.put(s, decompress(new StringByteIterator(in.get(s))));
            }
        }
    } else {
        String[] fieldArray = (String[]) fields.toArray(new String[fields.size()]);
        List<String> values;
        if (cluster) {
            values = jedisCluster.hmget(key, fieldArray);
        } else {
            values = jedis.hmget(key, fieldArray);
        }
        Iterator<String> fieldIterator = fields.iterator();
        Iterator<String> valueIterator = values.iterator();

        while (fieldIterator.hasNext() && valueIterator.hasNext()) {
            result.put(fieldIterator.next(), decompress(new StringByteIterator(valueIterator.next())));
        }
        assert !fieldIterator.hasNext() && !valueIterator.hasNext();
    }
    return result.isEmpty() ? 1 : 0;
}

From source file:de.bangl.lm.LotManagerPlugin.java

public void listLotGroups(CommandSender sender) {
    HashMap<String, LotGroup> thegroups = this.lots.getAllLotGroups();

    if (thegroups.isEmpty()) {
        sendInfo(sender, "No lotgroups defined.");
    }/* w w w  . j  av  a2 s .c  o  m*/

    for (LotGroup lotgroup : thegroups.values()) {
        sendInfo(sender, lotgroup.getId());
    }
}

From source file:com.mirth.connect.server.migration.ServerMigrator.java

private void runConfigurationMigrator(ConfigurationMigrator configurationMigrator,
        PropertiesConfiguration mirthConfig, Version version) {
    configurationMigrator.updateConfiguration(mirthConfig);

    HashMap<String, Object> addedProperties = new LinkedHashMap<String, Object>();
    Map<String, Object> propertiesToAdd = configurationMigrator.getConfigurationPropertiesToAdd();

    if (propertiesToAdd != null) {
        for (Entry<String, Object> propertyToAdd : propertiesToAdd.entrySet()) {
            if (!mirthConfig.containsKey(propertyToAdd.getKey())) {
                PropertiesConfigurationLayout layout = mirthConfig.getLayout();
                String key = propertyToAdd.getKey();
                Object value;/*from   w  w w. j  a  v  a  2s .  c om*/
                String comment = "";

                if (propertyToAdd.getValue() instanceof Pair) {
                    // If a pair is used, get both the value and comment
                    Pair<Object, String> pair = (Pair<Object, String>) propertyToAdd.getValue();
                    value = pair.getLeft();
                    comment = pair.getRight();
                } else {
                    // Only the value was specified
                    value = propertyToAdd.getValue();
                }

                mirthConfig.setProperty(key, value);

                // If this is the first added property, add a general comment about the added properties before it
                if (addedProperties.isEmpty()) {
                    if (StringUtils.isNotEmpty(comment)) {
                        comment = "\n\n" + comment;
                    }
                    comment = "The following properties were automatically added on startup for version "
                            + version + comment;
                }

                if (StringUtils.isNotEmpty(comment)) {
                    // When a comment is specified, always put a blank line before it
                    layout.setBlancLinesBefore(key, 1);
                    layout.setComment(key, comment);
                }

                addedProperties.put(key, value);
            }
        }
    }

    List<String> removedProperties = new ArrayList<String>();
    String[] propertiesToRemove = configurationMigrator.getConfigurationPropertiesToRemove();

    if (propertiesToRemove != null) {
        for (String propertyToRemove : propertiesToRemove) {
            if (mirthConfig.containsKey(propertyToRemove)) {
                mirthConfig.clearProperty(propertyToRemove);
                removedProperties.add(propertyToRemove);
            }
        }
    }

    if (!addedProperties.isEmpty() || !removedProperties.isEmpty()) {
        if (!addedProperties.isEmpty()) {
            logger.info("Adding properties in mirth.properties: " + addedProperties);
        }

        if (!removedProperties.isEmpty()) {
            logger.info("Removing properties in mirth.properties: " + removedProperties);
        }

        try {
            mirthConfig.save();
        } catch (ConfigurationException e) {
            logger.error("There was an error updating mirth.properties.", e);

            if (!addedProperties.isEmpty()) {
                logger.error("The following properties should be added to mirth.properties manually: "
                        + addedProperties.toString());
            }

            if (!removedProperties.isEmpty()) {
                logger.error("The following properties should be removed from mirth.properties manually: "
                        + removedProperties.toString());
            }
        }
    }
}

From source file:org.pentaho.platform.plugin.action.jasperreports.JasperReportsComponent.java

private boolean processCurrentReport(IActionSequenceResource resource, HashSet<String> compiledReportPaths,
        JasperReport jrreport, HashMap allReportParameters, HashMap returnImmediately,
        String reportOutputType) {

    boolean continueProcessing = true;
    String reportDefinitionPath = getReportDefinitionPath(resource);
    String compiledReportPath = ""; //$NON-NLS-1$

    if (reportDefinitionPath == null) {
        error(Messages.getErrorString("JasperReport.ERROR_0008_REPORT_DEFINITION_UNREADABLE")); //$NON-NLS-1$
        continueProcessing = false;//from  w w  w  . ja  v a2s. c o m
    }

    if (continueProcessing) {
        compiledReportPath = getCompiledReportPath(reportDefinitionPath);
        if (null == compiledReportPath) {
            continueProcessing = false;
        }
    }

    if (continueProcessing) {
        compiledReportPaths.add(compiledReportPath);
        continueProcessing = didReportCompile(reportDefinitionPath, compiledReportPath);
    }

    if (continueProcessing) {
        jrreport = loadJasperReport(compiledReportPath);
        if (null == jrreport) {
            continueProcessing = false;
        }
    }

    if (continueProcessing && (jrreport != null)) {
        // We have a compiled reports, ready to run.          
        JRParameter[] jrparams = jrreport.getParameters();

        if (debug) {
            debug(Messages.getString("JasperReport.DEBUG_LOADED_DESIGN", Integer.toString(jrparams.length))); //$NON-NLS-1$
        }

        HashMap needToPrompt = new HashMap();
        Map reportParameters = getReportParameters(jrparams, needToPrompt);

        // We're adding a parameter with the report's location. Useful for
        // subreports
        reportParameters.put(REPORT_FOLDER_PARAMETER, (new java.io.File(reportDefinitionPath)).getParent());

        // Add a ignore pagination parameter for xls, html and csv
        if (XLS.equals(reportOutputType) || HTML.equals(reportOutputType) || CSV.equals(reportOutputType)) {
            reportParameters.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);
        }

        allReportParameters.put(compiledReportPath, reportParameters);

        // If we have parameters to prompt for, have Pentaho create the
        // parameter
        // page for us.
        if (!needToPrompt.isEmpty() && needToPrompt.containsKey(NEED_TO_PROMPT)) {
            // make sure the type parameter comes back to us...
            // context.createFeedbackParameter( "type", "type",
            // reportOutputType, false ); //$NON-NLS-1$ //$NON-NLS-1$
            // //$NON-NLS-2$
            // Isn't the parameter page always HTML?
            setFeedbackMimeType("text/html"); //$NON-NLS-1$
            /*
             *  Creation of the key RETURN IMMEDIATELY is important here.
             *  We would like to return because we need to prompt the 
             *  user for input at this point.
             */
            returnImmediately.put(RETURN_IMMEDIATELY, null);
        } else if (getRuntimeContext().isPromptPending()) {
            returnImmediately.put(RETURN_IMMEDIATELY, null);
        }
    }

    return continueProcessing;
}

From source file:integratedtoolkit.util.OptimisComponents.java

private static HashMap<String, LocationProperties> parseProductInfo(String productInfo, Object[] details) {

    HashMap<String, LocationProperties> properties = new HashMap<String, LocationProperties>();
    LocationProperties locationProperties;
    int index = productInfo.indexOf("[");
    while (index > -1) {
        String location;/*ww w. j  a  v a  2s.c om*/
        String signatures;
        productInfo = productInfo.substring(index + 1);
        index = productInfo.indexOf("]");
        productInfo = productInfo.substring(0, index);

        index = productInfo.indexOf("|");
        location = productInfo.substring(0, index);
        productInfo = productInfo.substring(index + 1);

        index = productInfo.indexOf("|");
        signatures = productInfo.substring(0, index);
        productInfo = productInfo.substring(index + 1);

        locationProperties = new LocationProperties();

        locationProperties.slots = Integer.parseInt(productInfo);//slots
        LinkedList<Integer> cores = new LinkedList();
        locationProperties.cores = cores;
        locationProperties.user = (String) details[0];
        locationProperties.iDir = (String) details[1];
        locationProperties.wDir = (String) details[2];
        locationProperties.sharedDisks = (HashMap<String, String>) details[3];

        String[] methods = signatures.split(";");
        System.out.println("Methods");
        for (String signature : methods) {
            Integer coreId = Core.signatureToId.get(signature);
            System.out.println("\t" + signature + ": " + coreId);
            if (coreId == null) {
                coreId = Core.coreCount;
                ConstraintManager.addMethods(new String[] { signature }, new String[] { null },
                        new ResourceDescription[] { null });
                LicenseManager.updateStructures();
            }
            cores.add(coreId);
        }
        properties.put(location, locationProperties);
        index = productInfo.indexOf("[");
    }
    if (properties.isEmpty()) {
        locationProperties = new LocationProperties();
        locationProperties.slots = 0;//slots
        LinkedList<Integer> cores = new LinkedList();
        locationProperties.cores = cores;
        locationProperties.user = (String) details[0];
        locationProperties.iDir = (String) details[1];
        locationProperties.wDir = (String) details[2];
        locationProperties.sharedDisks = (HashMap<String, String>) details[3];
        properties.put("", locationProperties);
    }
    return properties;
}

From source file:org.kuali.kfs.module.bc.document.web.struts.BudgetConstructionForm.java

/**
 * Populates the push or pull selection lists displayed in the drop down controls used by the pullup or pushdown actions. The
 * population considers the current level of the document and the user's BudgetConstructionDocument type approvals setup in
 * WorkFlow./*from   w  ww . j a  v a 2  s.  c  o  m*/
 * 
 * @param bcDoc
 * @param levels
 * @param isPull
 */
public void populatePushPullLevelKeyLabels(BudgetConstructionDocument bcDoc,
        List<BudgetConstructionAccountOrganizationHierarchy> levels, boolean isPull) {

    if (!levels.isEmpty()) {
        // sanity check
        if (bcDoc.getOrganizationLevelCode() >= 0 && bcDoc.getOrganizationLevelCode() < levels.size()) {
            if (isPull) {
                pullupLevelKeyLabels.clear();

                // get the keys to search
                HashMap<String, BudgetConstructionAccountOrganizationHierarchy> rvwHierMap = new HashMap<String, BudgetConstructionAccountOrganizationHierarchy>();

                // start at level above current level and get any levels where the user is an approver
                for (int i = (bcDoc.getOrganizationLevelCode() + 1); i < levels.size(); i++) {
                    BudgetConstructionAccountOrganizationHierarchy rvwHier = levels.get(i);
                    rvwHierMap.put(rvwHier.getOrganizationChartOfAccountsCode() + rvwHier.getOrganizationCode(),
                            rvwHier);
                }
                if (!rvwHierMap.isEmpty()) {
                    try {
                        List<Organization> povOrgs = SpringContext
                                .getBean(BudgetConstructionProcessorService.class)
                                .getProcessorOrgs(GlobalVariables.getUserSession().getPerson());
                        if (!povOrgs.isEmpty()) {
                            for (Organization povOrg : povOrgs) {
                                if (rvwHierMap.containsKey(
                                        povOrg.getChartOfAccountsCode() + povOrg.getOrganizationCode())) {
                                    BudgetConstructionAccountOrganizationHierarchy level = rvwHierMap.get(
                                            povOrg.getChartOfAccountsCode() + povOrg.getOrganizationCode());
                                    SpringContext.getBean(PersistenceService.class)
                                            .retrieveReferenceObject(level, "organization");
                                    pullupLevelKeyLabels
                                            .add(new BCKeyLabelPair(level.getOrganizationLevelCode().toString(),
                                                    level.getOrganizationLevelCode().toString() + ":"
                                                            + level.getOrganizationChartOfAccountsCode() + "-"
                                                            + level.getOrganizationCode() + " "
                                                            + level.getOrganization().getOrganizationName()));
                                }
                            }
                        }
                    } catch (Exception e) {
                        // any exception just leaves an empty pullup list
                    }
                }
            } else {
                pushdownLevelKeyLabels.clear();

                // start at current doc level and add all that are below current level
                for (int i = (bcDoc.getOrganizationLevelCode() - 1); i >= 0; i--) {
                    BudgetConstructionAccountOrganizationHierarchy level = levels.get(i);
                    SpringContext.getBean(PersistenceService.class).retrieveReferenceObject(level,
                            "organization");
                    if (level.getOrganizationLevelCode() == 0) {
                        // push list level zero case needs special desc
                        pushdownLevelKeyLabels.add(new BCKeyLabelPair(
                                level.getOrganizationLevelCode().toString(),
                                level.getOrganizationLevelCode().toString() + ":"
                                        + level.getOrganizationChartOfAccountsCode() + "-"
                                        + level.getOrganizationCode() + " " + "Fiscal Officer Access Level"));
                    } else {
                        pushdownLevelKeyLabels
                                .add(new BCKeyLabelPair(level.getOrganizationLevelCode().toString(),
                                        level.getOrganizationLevelCode().toString() + ":"
                                                + level.getOrganizationChartOfAccountsCode() + "-"
                                                + level.getOrganizationCode() + " "
                                                + level.getOrganization().getOrganizationName()));
                    }
                }
            }
        }
    }
}

From source file:de.uniwue.info6.database.jdbc.ConnectionManager.java

/**
 *
 *
 * @param scenario/*w ww. j a  v  a  2 s  .  c om*/
 * @param user
 * @return
 *
 * @throws SQLException
 */
private List<String> checkSumChanged(Scenario scenario, User user) throws SQLException {
    if (scenario == null) {
        LOGGER.error("GIVEN SCENARIO IS NULL!");
    } else {
        List<String> list = new ArrayList<String>();
        HashMap<String, String> tables = scenarioTablesWithHash.get(scenario);

        if (!scenarioTablesWithHash.containsKey(scenario)) {
            return list;
        }

        if (tables != null && tables.isEmpty()) {
            return list;
        }

        for (String name : tables.keySet()) {
            String sum = tables.get(name);
            String currentSum = getTableChecksum(scenario, user, name);
            if (currentSum == null || sum == null || !sum.equals(currentSum)) {
                list.add(name);
            }
        }

        if (!list.isEmpty()) {
            return list;
        }
    }
    return null;
}

From source file:de.bangl.lm.LotManagerPlugin.java

public void listLots(CommandSender sender) {
    HashMap<String, LotGroup> thegroups = this.lots.getAllLotGroups();
    HashMap<String, Lot> thelots = this.lots.getAllLots();

    if (thegroups.isEmpty()) {
        sendInfo(sender, "No lotgroups defined.");
    }//  w  w  w.  jav  a  2 s.  c o m

    if (thelots.isEmpty()) {
        sendInfo(sender, "No lots defined.");
    }

    for (LotGroup lotgroup : thegroups.values()) {
        sendInfo(sender, lotgroup.getId() + ":");
        for (Lot lot : thelots.values()) {
            if (lotgroup.getId().equals(lot.getGroup().getId())) {
                sendInfo(sender, " - " + lot.getId());
            }
        }
    }
}