List of usage examples for java.util HashMap isEmpty
public boolean isEmpty()
From source file:com.pari.reports.request.handlers.ManageExportHandlerImpl.java
private ServiceContainer getManageCustomerDetails(ColumnDefinition[] colDef) { ServiceImpl service = null;/*ww w. j ava 2 s . co m*/ ServiceContainerImpl serviceContainer = null; ServerIfProvider serverIf = getRequestDetails().getServerIf(); Customer[] allCustomers = null; boolean isSuperAdmin = false; HashMap<String, Object> filterMap = getRequestDetails().getParameterFilterMap(); if ((!(filterMap.isEmpty())) && filterMap.containsKey(RequestAttributes.SuperAdmin.name())) { isSuperAdmin = filterMap.get(RequestAttributes.SuperAdmin.name()).toString().equalsIgnoreCase("true") ? true : false; } if (isSuperAdmin || getUserAccess()) { allCustomers = serverIf.getCustomerIf().getAllCustomers(); } else { allCustomers = serverIf.getCustomerIf().getAllUserCustomers(); } if (null == allCustomers) { return null; } List<Customer> allCustomerList = Arrays.asList(allCustomers); Collections.sort(allCustomerList, new PolicySorter()); serviceContainer = new ServiceContainerImpl(); for (Customer customer : allCustomerList) { if (customer != null) { service = new ServiceImpl(); service.put(colDef[0].getId(), customer.getCustomerName()); service.put(colDef[1].getId(), customer.getCreaterName()); service.put(colDef[2].getId(), customer.getContactName()); service.put(colDef[3].getId(), customer.getContactEmailAddress()); service.put(colDef[4].getId(), customer.getContactPhoneNumber()); service.put(colDef[5].getId(), customer.getNoOfDevices()); service.put(colDef[6].getId(), (customer.getAvailedLicenses() == -1) ? 0 : customer.getAvailedLicenses()); service.put(colDef[7].getId(), (customer.getNoOfLicenses() == -1) ? "" : customer.getNoOfLicenses()); serviceContainer.addManageServices(service); } } return serviceContainer; }
From source file:uk.ac.soton.itinnovation.ecc.service.utils.ExplorerDemoData.java
private void createParticipantActivitySummaryData() { // Run through participants summarising their activities participantActivitySummary = new HashMap<>(); for (String name : participantsByName.keySet()) { EccParticipant part = participantsByName.get(name); HashMap<String, Integer> actCount = new HashMap<>(); EccParticipantActivityResultSet ars = participantActivities.get(part.getIRI()); if (ars != null) { // Count activity instances by name for (EccActivity act : ars.getActivities()) { String actName = act.getName(); if (actCount.containsKey(actName)) { int count = actCount.get(actName); actCount.put(actName, ++count); } else actCount.put(actName, 1); }//from www. j a v a 2 s . c o m // Place in summary if (!actCount.isEmpty()) { EccParticipantActivitySummaryResultSet psrs = new EccParticipantActivitySummaryResultSet(part); for (String actName : actCount.keySet()) psrs.addActivitySummary(new EccActivitySummaryInfo(actName, actCount.get(actName))); participantActivitySummary.put(part.getIRI(), psrs); } } } }
From source file:com.pari.reports.request.handlers.ManageExportHandlerImpl.java
private ServiceContainer getFaultHistory(ColumnDefinition[] colDef) throws Exception { ServiceImpl service = null;/*from www . ja v a 2s . c o m*/ ServiceContainerImpl serviceContainer = null; int faultId = -1; Fault[] fault = null; ServerIfProvider serverIf = getRequestDetails().getServerIf(); HashMap<String, Object> filterMap = getRequestDetails().getParameterFilterMap(); if (filterMap.isEmpty()) { throw new Exception("Parameter tag is required."); } faultId = filterMap.get(RequestAttributes.FaultId.name()) == null ? -1 : Integer.valueOf(filterMap.get(RequestAttributes.FaultId.name()).toString()); if (faultId <= 0) { throw new Exception("Please provide faultId"); } serviceContainer = new ServiceContainerImpl(); try { fault = serverIf.getFaultManagerIf().getFaultHistory(faultId); } catch (Exception e) { logger.error("Exception while Export Fault History operation", e); } if (fault != null && fault.length > 0) { for (Fault faultObj : fault) { if (faultObj != null) { service = new ServiceImpl(); colDef[0].setRenderer(RendererType.STRING); NetworkNode node = serverIf.getCacheIf().getNodeByID(faultObj.getDevId()); if (node != null) { service.put(colDef[0].getId(), node.getNodeId()); } else { service.put(colDef[0].getId(), "Deleted Device"); } service.put(colDef[1].getId(), faultObj.getCondition()); service.put(colDef[2].getId(), faultObj.getSubModule()); service.put(colDef[3].getId(), faultObj.getSeverity()); service.put(colDef[4].getId(), faultObj.getMessage()); service.put(colDef[5].getId(), faultObj.getInvocationCount()); if (faultObj.isActive()) { service.put(colDef[6].getId(), "Yes"); } else { service.put(colDef[6].getId(), "No"); } if (faultObj.isAcked()) { service.put(colDef[7].getId(), "Yes"); } else { service.put(colDef[7].getId(), "No"); } service.put(colDef[8].getId(), (0 < faultObj.getFirstReportedTimeStamp()) ? faultObj.getFirstReportedTimeStamp() : ""); service.put(colDef[9].getId(), (0 < faultObj.getLastUpdatedTimeStamp()) ? faultObj.getLastUpdatedTimeStamp() : ""); serviceContainer.addManageServices(service); } } } return serviceContainer; }
From source file:org.freebxml.omar.common.BindingUtility.java
public SubmitObjectsRequest createSubmitRequest(boolean dontVersion, boolean dontVersionContent, List ros) throws Exception { SubmitObjectsRequest request = lcmFac.createSubmitObjectsRequest(); HashMap slotsMap = new HashMap(); if (dontVersion) { slotsMap.put(CANONICAL_SLOT_LCM_DONT_VERSION, "true"); }/*from w ww . j av a2s . co m*/ if (dontVersionContent) { slotsMap.put(CANONICAL_SLOT_LCM_DONT_VERSION_CONTENT, "true"); } if (!slotsMap.isEmpty()) { addSlotsToRequest(request, slotsMap); } if ((ros != null) && (ros.size() > 0)) { org.oasis.ebxml.registry.bindings.rim.RegistryObjectList roList = rimFac.createRegistryObjectList(); roList.getIdentifiable().addAll(ros); request.setRegistryObjectList(roList); } return request; }
From source file:org.jboss.pressgang.ccms.contentspec.utils.CSTransformer.java
/** * Transform a Level CSNode entity object into a Level Object that can be added to a Content Specification. * * @param node The CSNode entity object to be transformed. * @param nodes A mapping of node entity ids to their transformed counterparts. * @param targetTopics A mapping of target ids to SpecTopics. * @param relationshipFromNodes A list of CSNode entities that have relationships. * @param processes/* w w w . j a v a2 s . c o m*/ * @return The transformed level entity. */ protected static Level transformLevel(final CSNodeWrapper node, final Map<Integer, Node> nodes, final Map<String, SpecTopic> targetTopics, final List<CSNodeWrapper> relationshipFromNodes, List<Process> processes) { final Level level; if (node.getNodeType() == CommonConstants.CS_NODE_APPENDIX) { level = new Appendix(node.getTitle()); } else if (node.getNodeType() == CommonConstants.CS_NODE_CHAPTER) { level = new Chapter(node.getTitle()); } else if (node.getNodeType() == CommonConstants.CS_NODE_PART) { level = new Part(node.getTitle()); } else if (node.getNodeType() == CommonConstants.CS_NODE_PROCESS) { level = new Process(node.getTitle()); } else if (node.getNodeType() == CommonConstants.CS_NODE_SECTION) { level = new Section(node.getTitle()); } else if (node.getNodeType() == CommonConstants.CS_NODE_PREFACE) { level = new Preface(node.getTitle()); } else if (node.getNodeType() == CommonConstants.CS_NODE_INITIAL_CONTENT) { level = new InitialContent(); } else { throw new IllegalArgumentException("The passed node is not a Level"); } level.setConditionStatement(node.getCondition()); level.setTargetId(node.getTargetId()); level.setUniqueId(node.getId() == null ? null : node.getId().toString()); // Set the fixed url properties applyFixedURLs(node, level); // Collect any relationships for processing after everything is transformed if (node.getRelatedToNodes() != null && node.getRelatedToNodes().getItems() != null && !node.getRelatedToNodes().getItems().isEmpty()) { relationshipFromNodes.add(node); } // Transform the info topic node if one exists for the level if (node.getInfoTopicNode() != null) { final InfoTopic infoTopic = transformInfoTopic(node, node.getInfoTopicNode()); level.setInfoTopic(infoTopic); } // Add all the levels/topics if (node.getChildren() != null && node.getChildren().getItems() != null) { final List<CSNodeWrapper> childNodes = node.getChildren().getItems(); final HashMap<CSNodeWrapper, Node> levelNodes = new HashMap<CSNodeWrapper, Node>(); final HashMap<CSNodeWrapper, SpecTopic> initialContentNodes = new HashMap<CSNodeWrapper, SpecTopic>(); for (final CSNodeWrapper childNode : childNodes) { if (childNode.getNodeType() == CommonConstants.CS_NODE_TOPIC) { final SpecTopic topic = transformSpecTopic(childNode, nodes, targetTopics, relationshipFromNodes); levelNodes.put(childNode, topic); } else if (childNode.getNodeType() == CommonConstants.CS_NODE_COMMENT) { final Comment comment = transformComment(childNode); levelNodes.put(childNode, comment); } else if (childNode.getNodeType() == CommonConstants.CS_NODE_COMMON_CONTENT) { final CommonContent commonContent = transformCommonContent(childNode); levelNodes.put(childNode, commonContent); } else if (childNode.getNodeType() == CommonConstants.CS_NODE_INITIAL_CONTENT_TOPIC) { final SpecTopic initialContentTopic = transformSpecTopicWithoutTypeCheck(childNode, nodes, targetTopics, relationshipFromNodes); if (level instanceof InitialContent) { levelNodes.put(childNode, initialContentTopic); } else { initialContentNodes.put(childNode, initialContentTopic); } } else { final Level childLevel = transformLevel(childNode, nodes, targetTopics, relationshipFromNodes, processes); levelNodes.put(childNode, childLevel); } } // Sort the level nodes so that they are in the right order based on next/prev values. final LinkedHashMap<CSNodeWrapper, Node> sortedMap = CSNodeSorter.sortMap(levelNodes); // PressGang 1.4+ stores the initial content inside it's own container, instead of on the level if (!(level instanceof InitialContent) && !initialContentNodes.isEmpty()) { final LinkedHashMap<CSNodeWrapper, SpecTopic> sortedInitialContentMap = CSNodeSorter .sortMap(initialContentNodes); final InitialContent initialContent = new InitialContent(); level.appendChild(initialContent); // Add the initial content topics to the level now that they are in the right order. final Iterator<Map.Entry<CSNodeWrapper, SpecTopic>> frontMatterIter = sortedInitialContentMap .entrySet().iterator(); while (frontMatterIter.hasNext()) { final Map.Entry<CSNodeWrapper, SpecTopic> entry = frontMatterIter.next(); initialContent.appendSpecTopic(entry.getValue()); } } // Add the child nodes to the level now that they are in the right order. final Iterator<Map.Entry<CSNodeWrapper, Node>> iter = sortedMap.entrySet().iterator(); while (iter.hasNext()) { final Map.Entry<CSNodeWrapper, Node> entry = iter.next(); level.appendChild(entry.getValue()); // Add a new line to separate chapters/parts if (isNodeASeparatorLevel(entry.getValue()) && iter.hasNext()) { level.appendChild(new TextNode("\n")); } } } // Add the node to the list of processed nodes so that the relationships can be added once everything is processed nodes.put(node.getId(), level); // We need to keep track of processes to process their relationships if (level instanceof Process) { processes.add((Process) level); } return level; }
From source file:com.linkedin.databus.core.TestDbusEventBufferPersistence.java
@Test public void testMetaFileCloseMult() throws Exception { int maxEventBufferSize = 1144; int maxIndividualBufferSize = 500; int bufNum = maxEventBufferSize / maxIndividualBufferSize; if (maxEventBufferSize % maxIndividualBufferSize > 0) bufNum++;// ww w .ja va 2 s .c om DbusEventBuffer.StaticConfig config = getConfig(maxEventBufferSize, maxIndividualBufferSize, 100, 500, AllocationPolicy.MMAPPED_MEMORY, _mmapDirStr, true); // create buffer mult DbusEventBufferMult bufMult = createBufferMult(config); // Save all the files and validate the meta files. bufMult.close(); for (DbusEventBuffer dbusBuf : bufMult.bufIterable()) { File metaFile = new File(_mmapDir, dbusBuf.metaFileName()); // check that we don't have the files Assert.assertTrue(metaFile.exists()); validateFiles(metaFile, bufNum); } File[] entries = _mmapDir.listFiles(); // When we create a new multi-buffer, we should get renamed files as well as new files. bufMult = createBufferMult(config); entries = _mmapDir.listFiles(); // Has session dirs and renamed meta files. // Create an info file for one buffer. DbusEventBuffer buf = bufMult.bufIterable().iterator().next(); buf.saveBufferMetaInfo(true); File infoFile = new File(_mmapDir, buf.metaFileName() + ".info"); Assert.assertTrue(infoFile.exists()); // Create a session directory that has one file in it. File badSes1 = new File(_mmapDir, DbusEventBuffer.getSessionPrefix() + "m"); badSes1.mkdir(); badSes1.deleteOnExit(); File junkFile = new File(badSes1.getAbsolutePath() + "/junkFile"); junkFile.createNewFile(); junkFile.deleteOnExit(); // Create a directory that is empty File badSes2 = new File(_mmapDir, DbusEventBuffer.getSessionPrefix() + "n"); badSes2.mkdir(); badSes2.deleteOnExit(); // Create a good file under mmap directory that we don't want to see removed. final String goodFile = "GoodFile"; File gf = new File(_mmapDir, goodFile); gf.createNewFile(); // Now close the multibuf, and see that the new files are still there. // We should have deleted the unused sessions and info files. bufMult.close(); HashSet<String> validEntries = new HashSet<String>(bufNum); for (DbusEventBuffer dbusBuf : bufMult.bufIterable()) { File metaFile = new File(_mmapDir, dbusBuf.metaFileName()); // check that we don't have the files Assert.assertTrue(metaFile.exists()); validateFiles(metaFile, bufNum); validEntries.add(metaFile.getName()); DbusEventBufferMetaInfo mi = new DbusEventBufferMetaInfo(metaFile); mi.loadMetaInfo(); validEntries.add(mi.getSessionId()); } validEntries.add(goodFile); // Now we should be left with meta files, and session dirs and nothing else. entries = _mmapDir.listFiles(); for (File f : entries) { Assert.assertTrue(validEntries.contains(f.getName())); validEntries.remove(f.getName()); } Assert.assertTrue(validEntries.isEmpty()); // And everything else should have moved to the .BAK directory entries = _mmapBakDir.listFiles(); HashMap<String, File> fileHashMap = new HashMap<String, File>(entries.length); for (File f : entries) { fileHashMap.put(f.getName(), f); } Assert.assertTrue(fileHashMap.containsKey(badSes1.getName())); Assert.assertTrue(fileHashMap.get(badSes1.getName()).isDirectory()); Assert.assertEquals(fileHashMap.get(badSes1.getName()).listFiles().length, 1); Assert.assertEquals(fileHashMap.get(badSes1.getName()).listFiles()[0].getName(), junkFile.getName()); fileHashMap.remove(badSes1.getName()); Assert.assertTrue(fileHashMap.containsKey(badSes2.getName())); Assert.assertTrue(fileHashMap.get(badSes2.getName()).isDirectory()); Assert.assertEquals(fileHashMap.get(badSes2.getName()).listFiles().length, 0); fileHashMap.remove(badSes2.getName()); // We should have the renamed meta files in the hash now. for (File f : entries) { if (f.getName().startsWith(DbusEventBuffer.getMmapMetaInfoFileNamePrefix())) { Assert.assertTrue(fileHashMap.containsKey(f.getName())); Assert.assertTrue(f.isFile()); fileHashMap.remove(f.getName()); } } Assert.assertTrue(fileHashMap.isEmpty()); // One more test to make sure we create the BAK directory dynamically if it does not exist. FileUtils.deleteDirectory(_mmapBakDir); bufMult = createBufferMult(config); entries = _mmapDir.listFiles(); // Create an info file for one buffer. buf = bufMult.bufIterable().iterator().next(); buf.saveBufferMetaInfo(true); infoFile = new File(_mmapDir, buf.metaFileName() + ".info"); Assert.assertTrue(infoFile.exists()); bufMult.close(); entries = _mmapBakDir.listFiles(); fileHashMap = new HashMap<String, File>(entries.length); for (File f : entries) { fileHashMap.put(f.getName(), f); } Assert.assertTrue(fileHashMap.containsKey(infoFile.getName())); Assert.assertTrue(fileHashMap.get(infoFile.getName()).isFile()); }
From source file:com.android.calendar.event.EditEventView.java
private void updateAttendees(HashMap<String, Attendee> attendeesList) { if (attendeesList == null || attendeesList.isEmpty()) { return;// w w w . ja v a2 s . c o m } mAttendeesList.setText(null); for (Attendee attendee : attendeesList.values()) { // TODO: Please remove separator when Calendar uses the chips MR2 // project // Adding a comma separator between email addresses to prevent a // chips MR1.1 bug // in which email addresses are concatenated together with no // separator. mAttendeesList.append(attendee.mEmail + ", "); } }
From source file:com.erudika.scoold.utils.ScooldUtils.java
public <P extends ParaObject> P populate(HttpServletRequest req, P pobj, String... paramName) { if (pobj != null && paramName != null) { HashMap<String, Object> data = new HashMap<String, Object>(); for (String param : paramName) { String[] values;/*from ww w . j a v a 2 s . c om*/ if (param.matches(".+?\\|.$")) { // convert comma-separated value to list of strings String cleanParam = param.substring(0, param.length() - 2); values = req.getParameterValues(cleanParam); String firstValue = (values != null && values.length > 0) ? values[0] : null; String separator = param.substring(param.length() - 1); if (!StringUtils.isBlank(firstValue)) { data.put(cleanParam, Arrays.asList(firstValue.split(separator))); } } else { values = req.getParameterValues(param); String firstValue = (values != null && values.length > 0) ? values[0] : null; if (values != null && values.length > 1) { data.put(param, Arrays.asList(values)); } else if (firstValue != null) { data.put(param, firstValue); } } } if (!data.isEmpty()) { ParaObjectUtils.setAnnotatedFields(pobj, data, null); } } return pobj; }
From source file:org.encuestame.mvc.controller.json.v1.SettingsJsonController.java
/** * Upgrade profile settings./*from ww w . ja v a 2 s. c om*/ * @param model * @return */ @PreAuthorize("hasRole('ENCUESTAME_USER')") @RequestMapping(value = "/api/settings/profile/{type}/update.json", method = RequestMethod.POST) public @ResponseBody ModelMap upgradeProfile(HttpServletRequest request, @PathVariable String type, @RequestParam(value = "data", required = false) String data, HttpServletResponse response) throws JsonGenerationException, JsonMappingException, IOException { log.debug("update profile type:" + type); log.debug("update profile data:" + data); try { final SecurityOperations security = getSecurityService(); final ValidateOperations operations = new ValidateOperations(security); final HashMap<String, Object> listError = new HashMap<String, Object>(); //filter data data = filterValue(data); if (type.equals(Profile.EMAIL.toString())) { //TODO: review pattern email format validator. log.debug("update email"); final UserAccount account = getSecurityService().getUserAccount(getUserPrincipalUsername()); if (operations.validateUserEmail(data, account)) { security.updateAccountProfile(Profile.EMAIL, data); setSuccesResponse(); } else { listError.put(type, getMessage("e_005", request, null)); } } else if (type.equals(Profile.USERNAME.toString())) { log.debug("update username"); final UserAccount account = getSecurityService().getUserAccount(getUserPrincipalUsername()); if (operations.validateUsername(data, account)) { security.updateAccountProfile(Profile.USERNAME, data); setSuccesResponse(getMessage("settings_config_profile_success", request, null)); } else { listError.put(type, getMessage("e_018", request, null)); } } else if (type.equals(Profile.PICTURE.toString())) { log.debug("update PICTURE"); security.updateAccountProfile(Profile.PICTURE, data); setSuccesResponse(getMessage("settings_config_picture_success", request, null)); } else { setError(getMessage("e_023", request, null), response); } if (!listError.isEmpty()) { log.debug("list errors " + listError.size()); setError(listError, response); } } catch (Exception e) { log.error(e); e.printStackTrace(); setError(getMessage("e_023", request, null), response); //throw new JsonGenerationException(e.getMessage()); } return returnData(); }