List of usage examples for java.util TreeMap isEmpty
boolean isEmpty();
From source file:org.jvnet.hudson.update_center.Main.java
/** * Identify the latest core, populates the htaccess redirect file, optionally download the core wars and build the index.html * @return the JSON for the core Jenkins *//* w w w .j a va 2s .c o m*/ protected JSONObject buildCore(MavenRepository repository, PrintWriter redirect) throws Exception { TreeMap<VersionNumber, HudsonWar> wars = repository.getHudsonWar(); if (wars.isEmpty()) return null; HudsonWar latest = wars.get(wars.firstKey()); JSONObject core = latest.toJSON("core"); System.out.println("core\n=> " + core); redirect.printf("Redirect 302 /latest/jenkins.war %s\n", latest.getURL().getPath()); redirect.printf( "Redirect 302 /latest/debian/jenkins.deb http://pkg.jenkins-ci.org/debian/binary/jenkins_%s_all.deb\n", latest.getVersion()); redirect.printf( "Redirect 302 /latest/redhat/jenkins.rpm http://pkg.jenkins-ci.org/redhat/RPMS/noarch/jenkins-%s-1.1.noarch.rpm\n", latest.getVersion()); redirect.printf( "Redirect 302 /latest/opensuse/jenkins.rpm http://pkg.jenkins-ci.org/opensuse/RPMS/noarch/jenkins-%s-1.1.noarch.rpm\n", latest.getVersion()); if (latestCoreTxt != null) writeToFile(latest.getVersion().toString(), latestCoreTxt); if (download != null) { // build the download server layout for (HudsonWar w : wars.values()) { stage(w, new File(download, "war/" + w.version + "/" + w.getFileName())); } } if (www != null) buildIndex(new File(www, "download/war/"), "jenkins.war", wars.values(), "/latest/jenkins.war"); return core; }
From source file:org.xwiki.contrib.mailarchive.timeline.internal.TimeLineGenerator.java
/** * {@inheritDoc}/*www . j a v a 2 s .c o m*/ * * @see org.xwiki.contrib.mailarchive.timeline.ITimeLineGenerator#compute() */ @Override public String compute(int maxItems) { try { config.reloadConfiguration(); } catch (MailArchiveException e) { logger.error("Could not load mail archive configuration", e); return null; } Map<String, IMailingList> mailingLists = config.getMailingLists(); Map<String, IType> types = config.getMailTypes(); try { this.userStatsUrl = xwiki.getDocument(docResolver.resolve("MailArchive.ViewUserMessages"), context) .getURL("view", context); } catch (XWikiException e1) { logger.warn("Could not retrieve user stats url {}", ExceptionUtils.getRootCauseMessage(e1)); } TreeMap<Long, TimeLineEvent> sortedEvents = new TreeMap<Long, TimeLineEvent>(); // Set loading user in context (for rights) String loadingUser = config.getLoadingUser(); context.setUserReference(docResolver.resolve(loadingUser)); try { // Search topics String xwql = "select doc.fullName, topic.author, topic.subject, topic.topicid, topic.startdate, topic.lastupdatedate from Document doc, doc.object(" + XWikiPersistence.CLASS_TOPICS + ") as topic order by topic.lastupdatedate desc"; List<Object[]> result = queryManager.createQuery(xwql, Query.XWQL).setLimit(maxItems).execute(); for (Object[] item : result) { XWikiDocument doc = null; try { String docurl = (String) item[0]; String author = (String) item[1]; String subject = (String) item[2]; String topicId = (String) item[3]; Date date = (Date) item[4]; Date end = (Date) item[5]; String action = ""; // Retrieve associated emails TreeMap<Long, TopicEventBubble> emails = getTopicMails(topicId, subject); if (emails == null || emails.isEmpty()) { // Invalid topic, not emails attached, do not show it logger.warn("Invalid topic, no emails attached " + doc); } else { if (date != null && end != null && date.equals(end)) { // Add 10 min just to see the tape end.setTime(end.getTime() + 600000); } doc = xwiki.getDocument(docResolver.resolve(docurl), context); final List<String> tagsList = doc.getTagsList(context); List<String> topicTypes = doc.getListValue(XWikiPersistence.CLASS_TOPICS, "type"); // Email type icon List<String> icons = new ArrayList<String>(); for (String topicType : topicTypes) { IType type = types.get(topicType); if (type != null && !StringUtils.isEmpty(type.getIcon())) { icons.add(xwiki.getSkinFile("icons/silk/" + type.getIcon() + ".png", context)); // http://localhost:8080/xwiki/skins/colibri/icons/silk/bell // http://localhost:8080/xwiki/resources/icons/silk/bell.png } } // Author and avatar final IMAUser wikiUser = mailUtils.parseUser(author, config.isMatchLdap()); final String authorAvatar = getAuthorAvatar(wikiUser.getWikiProfile()); final TimeLineEvent timelineEvent = new TimeLineEvent(); TimeLineEvent additionalEvent = null; timelineEvent.beginDate = date; timelineEvent.title = subject; timelineEvent.icons = icons; timelineEvent.lists = doc.getListValue(XWikiPersistence.CLASS_TOPICS, "list"); timelineEvent.author = wikiUser.getDisplayName(); timelineEvent.authorAvatar = authorAvatar; timelineEvent.extract = getExtract(topicId); if (emails.size() == 1) { logger.debug("Adding instant event for email '" + subject + "'"); // Unique email, we show a punctual email event timelineEvent.url = emails.firstEntry().getValue().link; timelineEvent.action = "New Email "; } else { // For email with specific type icon, and a duration, both a band and a point should be added (so 2 events) // because no icon is displayed for duration events. if (CollectionUtils.isNotEmpty(icons)) { logger.debug( "Adding additional instant event to display type icon for first email in topic"); additionalEvent = new TimeLineEvent(timelineEvent); additionalEvent.url = emails.firstEntry().getValue().link; additionalEvent.action = "New Email "; } // Email thread, we show a topic event (a range) logger.debug("Adding duration event for topic '" + subject + "'"); timelineEvent.endDate = end; timelineEvent.url = doc.getURL("view", context); timelineEvent.action = "New Topic "; timelineEvent.messages = emails; } // Add the generated Event to the list if (sortedEvents.containsKey(date.getTime())) { // Avoid having more than 1 event at exactly the same time, because some timeline don't like it date.setTime(date.getTime() + 1); } sortedEvents.put(date.getTime(), timelineEvent); if (additionalEvent != null) { sortedEvents.put(date.getTime() + 1, additionalEvent); } } } catch (Throwable t) { logger.warn("Exception for " + doc, t); } } } catch (Throwable e) { logger.warn("could not compute timeline data", e); } return printEvents(sortedEvents); }
From source file:com.webcohesion.ofx4j.io.nanoxml.TestNanoXMLOFXReader.java
/** * tests using sax to parse an OFX doc.//from ww w .j av a 2 s.c o m */ public void testVersion1() throws Exception { NanoXMLOFXReader reader = new NanoXMLOFXReader(); final Map<String, List<String>> headers = new HashMap<String, List<String>>(); final Stack<Map<String, List<Object>>> aggregateStack = new Stack<Map<String, List<Object>>>(); TreeMap<String, List<Object>> root = new TreeMap<String, List<Object>>(); aggregateStack.push(root); reader.setContentHandler(getNewDefaultHandler(headers, aggregateStack)); reader.parse(TestNanoXMLOFXReader.class.getResourceAsStream("example-response.ofx")); assertEquals(9, headers.size()); assertEquals(1, aggregateStack.size()); assertSame(root, aggregateStack.pop()); TreeMap<String, List<Object>> OFX = (TreeMap<String, List<Object>>) root.remove("OFX").get(0); assertNotNull(OFX); TreeMap<String, List<Object>> SIGNONMSGSRSV1 = (TreeMap<String, List<Object>>) OFX.remove("SIGNONMSGSRSV1") .get(0); assertNotNull(SIGNONMSGSRSV1); TreeMap<String, List<Object>> SONRS = (TreeMap<String, List<Object>>) SIGNONMSGSRSV1.remove("SONRS").get(0); assertNotNull(SONRS); TreeMap<String, List<Object>> STATUS = (TreeMap<String, List<Object>>) SONRS.remove("STATUS").get(0); assertNotNull(STATUS); assertEquals("0", STATUS.remove("CODE").get(0).toString().trim()); assertEquals("INFO", STATUS.remove("SEVERITY").get(0).toString().trim()); assertTrue(STATUS.isEmpty()); assertEquals("20071015021529.000[-8:PST]", SONRS.remove("DTSERVER").get(0).toString().trim()); assertEquals("ENG", SONRS.remove("LANGUAGE").get(0).toString().trim()); assertEquals("19900101000000", SONRS.remove("DTACCTUP").get(0).toString().trim()); TreeMap<String, List<Object>> FI = (TreeMap<String, List<Object>>) SONRS.remove("FI").get(0); assertEquals("Bank&Cd", FI.remove("ORG").get(0).toString().trim()); assertEquals("01234", FI.remove("FID").get(0).toString().trim()); assertTrue(FI.isEmpty()); assertTrue(SONRS.isEmpty()); assertTrue(SIGNONMSGSRSV1.isEmpty()); TreeMap<String, List<Object>> BANKMSGSRSV1 = (TreeMap<String, List<Object>>) OFX.remove("BANKMSGSRSV1") .get(0); TreeMap<String, List<Object>> STMTTRNRS = (TreeMap<String, List<Object>>) BANKMSGSRSV1.remove("STMTTRNRS") .get(0); assertEquals("23382938", STMTTRNRS.remove("TRNUID").get(0).toString().trim()); STATUS = (TreeMap<String, List<Object>>) STMTTRNRS.remove("STATUS").get(0); assertNotNull(STATUS); assertEquals("0", STATUS.remove("CODE").get(0).toString().trim()); assertEquals("INFO", STATUS.remove("SEVERITY").get(0).toString().trim()); assertTrue(STATUS.isEmpty()); TreeMap<String, List<Object>> STMTRS = (TreeMap<String, List<Object>>) STMTTRNRS.remove("STMTRS").get(0); assertEquals("USD", STMTRS.remove("CURDEF").get(0).toString().trim()); TreeMap<String, List<Object>> BANKACCTFROM = (TreeMap<String, List<Object>>) STMTRS.remove("BANKACCTFROM") .get(0); assertEquals("SAVINGS", BANKACCTFROM.remove("ACCTTYPE").get(0).toString().trim()); assertEquals("098-121", BANKACCTFROM.remove("ACCTID").get(0).toString().trim()); assertEquals("987654321", BANKACCTFROM.remove("BANKID").get(0).toString().trim()); assertTrue(BANKACCTFROM.isEmpty()); TreeMap<String, List<Object>> BANKTRANLIST = (TreeMap<String, List<Object>>) STMTRS.remove("BANKTRANLIST") .get(0); assertEquals("20070101", BANKTRANLIST.remove("DTSTART").get(0).toString().trim()); assertEquals("20071015", BANKTRANLIST.remove("DTEND").get(0).toString().trim()); TreeMap<String, List<Object>> STMTTRN = (TreeMap<String, List<Object>>) BANKTRANLIST.remove("STMTTRN") .get(0); assertEquals("CREDIT", STMTTRN.remove("TRNTYPE").get(0).toString().trim()); assertEquals("20070329", STMTTRN.remove("DTPOSTED").get(0).toString().trim()); assertEquals("20070329", STMTTRN.remove("DTUSER").get(0).toString().trim()); assertEquals("150.00", STMTTRN.remove("TRNAMT").get(0).toString().trim()); assertEquals("980310001", STMTTRN.remove("FITID").get(0).toString().trim()); assertEquals("TRANSFER", STMTTRN.remove("NAME").get(0).toString().trim()); assertEquals("Transfer from checking &<> etc.", STMTTRN.remove("MEMO").get(0).toString().trim()); assertTrue(STMTTRN.isEmpty()); assertTrue(BANKTRANLIST.isEmpty()); TreeMap<String, List<Object>> LEDGERBAL = (TreeMap<String, List<Object>>) STMTRS.remove("LEDGERBAL").get(0); assertEquals("5250.00", LEDGERBAL.remove("BALAMT").get(0).toString().trim()); assertEquals("20071015021529.000[-8:PST]", LEDGERBAL.remove("DTASOF").get(0).toString().trim()); assertTrue(LEDGERBAL.isEmpty()); TreeMap<String, List<Object>> AVAILBAL = (TreeMap<String, List<Object>>) STMTRS.remove("AVAILBAL").get(0); assertEquals("5250.00", AVAILBAL.remove("BALAMT").get(0).toString().trim()); assertEquals("20071015021529.000[-8:PST]", AVAILBAL.remove("DTASOF").get(0).toString().trim()); assertTrue(AVAILBAL.isEmpty()); assertTrue(LEDGERBAL.isEmpty()); assertTrue(STMTRS.isEmpty()); assertTrue(STMTTRNRS.isEmpty()); assertTrue(BANKMSGSRSV1.isEmpty()); assertTrue(OFX.isEmpty()); assertTrue(root.isEmpty()); }
From source file:com.webcohesion.ofx4j.io.nanoxml.TestNanoXMLOFXReader.java
/** * tests for closing tags in v1/*from w w w . j a v a 2s .c o m*/ */ public void testClosingTagsVersion1() throws Exception { NanoXMLOFXReader reader = new NanoXMLOFXReader(); final Map<String, List<String>> headers = new HashMap<String, List<String>>(); final Stack<Map<String, List<Object>>> aggregateStack = new Stack<Map<String, List<Object>>>(); TreeMap<String, List<Object>> root = new TreeMap<String, List<Object>>(); aggregateStack.push(root); reader.setContentHandler(getNewDefaultHandler(headers, aggregateStack)); reader.parse(TestNanoXMLOFXReader.class.getResourceAsStream("closing-tags.ofx")); assertEquals(9, headers.size()); assertEquals(1, aggregateStack.size()); assertSame(root, aggregateStack.pop()); TreeMap<String, List<Object>> OFX = (TreeMap<String, List<Object>>) root.remove("OFX").get(0); assertNotNull(OFX); TreeMap<String, List<Object>> SIGNONMSGSRSV1 = (TreeMap<String, List<Object>>) OFX.remove("SIGNONMSGSRSV1") .get(0); assertNotNull(SIGNONMSGSRSV1); TreeMap<String, List<Object>> SONRS = (TreeMap<String, List<Object>>) SIGNONMSGSRSV1.remove("SONRS").get(0); assertNotNull(SONRS); TreeMap<String, List<Object>> STATUS = (TreeMap<String, List<Object>>) SONRS.remove("STATUS").get(0); assertNotNull(STATUS); TreeMap<String, List<Object>> FI = (TreeMap<String, List<Object>>) SONRS.remove("FI").get(0); assertNotNull(FI); assertEquals("0", STATUS.remove("CODE").get(0).toString().trim()); assertEquals("INFO", STATUS.remove("SEVERITY").get(0).toString().trim()); assertTrue(STATUS.isEmpty()); assertEquals("20100717152132", SONRS.remove("DTSERVER").get(0).toString().trim()); assertEquals("ENG", SONRS.remove("LANGUAGE").get(0).toString().trim()); assertEquals("ameritrade.com", FI.remove("ORG").get(0).toString().trim()); assertTrue(SONRS.isEmpty()); assertTrue(SIGNONMSGSRSV1.isEmpty()); assertTrue(OFX.isEmpty()); assertTrue(root.isEmpty()); }
From source file:com.smartitengineering.cms.api.impl.type.ContentTypeImpl.java
@Override public RepresentationDef getRepresentationDefForMimeType(String mimeType) { TreeMap<String, RepresentationDef> map = new TreeMap<String, RepresentationDef>(); for (RepresentationDef def : representationDefs) { if (def.getMIMEType().equals(mimeType)) { map.put(def.getName(), def); }//from w w w. ja v a2 s . co m } if (map.isEmpty()) { return null; } else { return map.firstEntry().getValue(); } }
From source file:org.jenkins_ci.update_center.Main.java
/** * Identify the latest core, populates the htaccess redirect file, optionally download the core wars and build the * index.html/*w w w .jav a 2 s .co m*/ * * @return the JSON for the core Jenkins */ protected JSONObject buildCore(MavenRepository repository, PrintWriter redirect) throws Exception { TreeMap<VersionNumber, HudsonWar> wars = repository.getHudsonWar(); if (wars.isEmpty()) { return null; } HudsonWar latest = wars.get(wars.firstKey()); latest.file = repository.resolve(latest.artifact); JSONObject core = latest.toJSON("core"); System.out.println("core\n=> " + core); redirect.printf("Redirect 302 /latest/jenkins.war %s\n", latest.getURL().getPath()); redirect.printf( "Redirect 302 /latest/debian/jenkins.deb http://pkg.jenkins-ci.org/debian/binary/jenkins_%s_all.deb\n", latest.getVersion()); redirect.printf( "Redirect 302 /latest/redhat/jenkins.rpm http://pkg.jenkins-ci.org/redhat/RPMS/noarch/jenkins-%s-1.1.noarch.rpm\n", latest.getVersion()); redirect.printf( "Redirect 302 /latest/opensuse/jenkins.rpm http://pkg.jenkins-ci.org/opensuse/RPMS/noarch/jenkins-%s-1.1.noarch.rpm\n", latest.getVersion()); if (latestCoreTxt != null) { writeToFile(latest.getVersion().toString(), latestCoreTxt); } if (download != null) { // build the download server layout for (HudsonWar w : wars.values()) { stage(w, new File(download, "war/" + w.version + "/" + w.getFileName())); } } if (www != null) { buildIndex(new File(www, "download/war/"), "jenkins.war", wars.values(), "/latest/jenkins.war"); } return core; }
From source file:net.sf.maltcms.chromaui.charts.overlay.Peak1DOverlay.java
/** * * @param ce//from w w w . ja v a 2s. co m */ @Override public void selectionStateChanged(SelectionChangeEvent ce) { if (isVisible() && ce.getSource() != this && ce.getSelection() != null) { if (ce.getSelection().getType().equals(ISelection.Type.CLEAR)) { Logger.getLogger(getClass().getName()).fine("Received clear selection type"); clear(); return; } if (dataset != null) { IScan target = dataset.getTarget(ce.getSelection().getSeriesIndex(), ce.getSelection().getItemIndex()); TreeMap<Double, IPeakAnnotationDescriptor> distanceMap = new TreeMap<>(); for (IPeakAnnotationDescriptor ipad : peakAnnotations.getMembers()) { double absDiff = Math.abs(ipad.getApexTime() - target.getScanAcquisitionTime()); if (absDiff < 10.0d) { distanceMap.put(absDiff, ipad); } } if (!distanceMap.isEmpty()) { IPeakAnnotationDescriptor ipad = distanceMap.firstEntry().getValue(); if (!activeSelection.contains(ipad)) { switch (ce.getSelection().getType()) { case CLICK: Logger.getLogger(getClass().getName()).fine("Click selection received"); renderer.generatePeakShape(peakAnnotations.getChromatogram(), ipad, dataset, renderer.getSeriesIndex(dataset, peakAnnotations.getChromatogram()), selectedPeaks); activeSelection.add(ipad); break; case HOVER: // System.out.println("Hover selection received"); // // content.add(ipad); // activeSelection.add(ipad); default: break; } fireOverlayChanged(); } } } } }
From source file:disAMS.AMRMClient.Impl.AMRMClientImpl.java
/** * ContainerRequests with locality relaxation cannot be made at the same * priority as ContainerRequests without locality relaxation. *//*from w w w . ja v a2 s . c om*/ private void checkLocalityRelaxationConflict(Priority priority, Collection<String> locations, boolean relaxLocality) { Map<String, TreeMap<Resource, ResourceRequestInfo>> remoteRequests = this.remoteRequestsTable.get(priority); if (remoteRequests == null) { return; } // Locality relaxation will be set to relaxLocality for all implicitly // requested racks. Make sure that existing rack requests match this. for (String location : locations) { TreeMap<Resource, ResourceRequestInfo> reqs = remoteRequests.get(location); if (reqs != null && !reqs.isEmpty()) { boolean existingRelaxLocality = reqs.values().iterator().next().remoteRequest.getRelaxLocality(); if (relaxLocality != existingRelaxLocality) { throw new InvalidContainerRequestException( "Cannot submit a " + "ContainerRequest asking for location " + location + " with locality relaxation " + relaxLocality + " when it has " + "already been requested with locality relaxation " + existingRelaxLocality); } } } }
From source file:de.suse.swamp.core.container.WorkflowManager.java
/** * Workflowtemplates from results without errors * will get added to the list of available templates, and their files * doc + image files will get installed. *///w ww.j a va 2 s. c o m public void installValidTemplates(List results) { for (Iterator it = results.iterator(); it.hasNext();) { WorkflowReadResult result = (WorkflowReadResult) it.next(); if (result.getErrors().size() == 0) { WorkflowTemplate wfTemp = result.getTemplate(); TreeMap templateVersions = new TreeMap(); if (workflowTempls.keySet().contains(wfTemp.getName())) { templateVersions = (TreeMap) workflowTempls.get(wfTemp.getName()); } else { workflowTempls.put(wfTemp.getName(), templateVersions); } // only install files from the latest version: if (templateVersions.isEmpty() || ((String) templateVersions.lastKey()).compareTo(result.getWfVersion()) < 0) { try { installWorkflowFiles(wfTemp.getName(), wfTemp.getVersion()); } catch (Exception e) { Logger.ERROR("Installing files from template: " + wfTemp.getName() + " failed. " + e.getMessage()); } } templateVersions.put(result.getWfVersion(), wfTemp); clearWorkflowCache(result.getWfName(), result.getWfVersion()); Logger.DEBUG("Successfully added " + result.getWfName() + "-" + result.getWfVersion() + " to TemplateList"); } } }
From source file:com.impetus.ankush2.framework.monitor.AbstractMonitor.java
/** * Method to convert null value maps to list object. * // w w w.j a va2s. c om * @param treeMap * the tree map * @return the object */ private static Object convertToList(TreeMap treeMap) { // if treemap is null or empty return null. if (treeMap == null || treeMap.isEmpty()) return null; boolean isList = false; // item set List itemSet = new ArrayList(); // iterating over the treemap. for (Object m : treeMap.keySet()) { // item key. String itemKey = m.toString(); // if value is null. if (treeMap.get(itemKey) == null) { isList = true; // adding item to item set. itemSet.add(itemKey); } else { // getting the object. Object obj = convertToList((TreeMap) (treeMap.get(itemKey))); // empty map. TreeMap map = new TreeMap(); // putting object in map. map.put(itemKey, obj); // putting object in tree map. treeMap.put(itemKey, obj); // adding the item in set. itemSet.add(map); } } // if it is list then return list else return map. if (isList) { return itemSet; } else { return treeMap; } }