List of usage examples for java.util SortedMap get
V get(Object key);
From source file:org.jasig.schedassist.web.VisibleScheduleTag.java
@Override public int doStartTagInternal() { final ServletContext servletContext = pageContext.getServletContext(); final Date scheduleStart = visibleSchedule.getScheduleStart(); if (null == scheduleStart) { // the visibleSchedule is empty, short circuit try {//from w w w .j ava 2 s . c om StringBuilder noappointments = new StringBuilder(); noappointments.append("<span class=\"none-available\">"); noappointments.append(getMessageSource().getMessage("no.available.appointments", null, null)); noappointments.append("</span>"); pageContext.getOut().write(noappointments.toString()); } catch (IOException e) { LOG.error("IOException occurred in doStartTag", e); } // SKIP_BODY means don't print any content from body of tag return SKIP_BODY; } LOG.debug("scheduleStart: " + scheduleStart); SortedMap<Date, List<AvailableBlock>> dailySchedules = new TreeMap<Date, List<AvailableBlock>>(); Date index = DateUtils.truncate(scheduleStart, java.util.Calendar.DATE); Date scheduleEnd = visibleSchedule.getScheduleEnd(); while (index.before(scheduleEnd)) { dailySchedules.put(index, new ArrayList<AvailableBlock>()); index = DateUtils.addDays(index, 1); } final Date lastMapKey = dailySchedules.lastKey(); LOG.debug("visibleSchedule spans " + dailySchedules.keySet().size() + " days"); try { SortedMap<AvailableBlock, AvailableStatus> scheduleBlockMap = visibleSchedule.getBlockMap(); int numberOfEventsToDisplay = 0; for (AvailableBlock block : scheduleBlockMap.keySet()) { Date eventStartDate = block.getStartTime(); LOG.debug("event start date: " + eventStartDate); Date mapKey = DateUtils.truncate(eventStartDate, java.util.Calendar.DATE); if (CommonDateOperations.equalsOrAfter(eventStartDate, scheduleStart) && dailySchedules.containsKey(mapKey)) { dailySchedules.get(mapKey).add(block); numberOfEventsToDisplay++; } } LOG.debug("number of events to display: " + numberOfEventsToDisplay); if (numberOfEventsToDisplay == 0) { // no available times in this range! StringBuilder noappointments = new StringBuilder(); noappointments.append("<span class=\"none-available\">"); noappointments.append(getMessageSource().getMessage("no.available.appointments", null, null)); noappointments.append("</span>"); pageContext.getOut().write(noappointments.toString()); } else { int weekNumber = 1; Date currentWeekStart = DateUtils.truncate(scheduleStart, java.util.Calendar.DATE); Date currentWeekFinish = DateUtils.addDays(currentWeekStart, CommonDateOperations.numberOfDaysUntilSunday(currentWeekStart)); currentWeekFinish = DateUtils.addMinutes(currentWeekFinish, -1); boolean renderAnotherWeek = true; while (renderAnotherWeek) { if (LOG.isDebugEnabled()) { LOG.debug("will render another week using currentWeekStart " + currentWeekStart + " and currentWeekFinish " + currentWeekFinish); } SortedMap<Date, List<AvailableBlock>> subMap = dailySchedules.subMap(currentWeekStart, currentWeekFinish); renderWeek(servletContext, pageContext.getOut(), weekNumber++, subMap, scheduleBlockMap); currentWeekStart = DateUtils.addMinutes(currentWeekFinish, 1); currentWeekFinish = DateUtils.addDays(currentWeekStart, 7); currentWeekFinish = DateUtils.addMinutes(currentWeekFinish, -1); if (LOG.isDebugEnabled()) { LOG.debug("recalculated currentWeekStart " + currentWeekStart + ", currentWeekFinish " + currentWeekFinish); } if (currentWeekStart.after(lastMapKey)) { renderAnotherWeek = false; LOG.debug("will not render another week"); } } } } catch (IOException e) { LOG.error("IOException occurred in doStartTag", e); } // SKIP_BODY means don't print any content from body of tag return SKIP_BODY; }
From source file:org.apache.cayenne.map.ObjEntity.java
/** * Recursively appends all attributes in the entity inheritance hierarchy. *///from w w w. j a v a 2 s . c om final void appendAttributes(Map<String, ObjAttribute> map) { map.putAll(getAttributeMapInternal()); ObjEntity superEntity = getSuperEntity(); if (superEntity != null) { SortedMap<String, ObjAttribute> attributeMap = new TreeMap<>(); superEntity.appendAttributes(attributeMap); for (String attributeName : attributeMap.keySet()) { String overridedDbPath = attributeOverrides.get(attributeName); ObjAttribute attribute = new ObjAttribute(attributeMap.get(attributeName)); attribute.setEntity(this); if (overridedDbPath != null) { attribute.setDbAttributePath(overridedDbPath); } map.put(attributeName, attribute); } } }
From source file:org.archive.crawler.admin.StatisticsTracker.java
protected void writeHostsReportTo(final PrintWriter writer) { // TODO: use CrawlHosts for all stats; only perform sorting on // manageable number of hosts SortedMap<String, AtomicLong> hd = getReverseSortedHostsDistribution(); // header//w ww . j a v a 2 s .co m writer.print( "[#urls] [#bytes] [host] [#robots] [#remaining] [#novel-urls] [#novel-bytes] [#dup-by-hash-urls] [#dup-by-hash-bytes] [#not-modified-urls] [#not-modified-bytes]\n"); for (String key : hd.keySet()) { // Key is 'host'. CrawlHost host = controller.getServerCache().getHostFor(key); AtomicLong val = hd.get(key); writeReportLine(writer, val == null ? "-" : val.get(), getBytesPerHost(key), key, host.getSubstats().getRobotsDenials(), host.getSubstats().getRemaining(), host.getSubstats().getNovelUrls(), host.getSubstats().getNovelBytes(), host.getSubstats().getDupByHashUrls(), host.getSubstats().getDupByHashBytes(), host.getSubstats().getNotModifiedUrls(), host.getSubstats().getNotModifiedBytes()); } // StatisticsTracker doesn't know of zero-completion hosts; // so supplement report with those entries from host cache Closure logZeros = new Closure() { public void execute(Object obj) { CrawlHost host = (CrawlHost) obj; if (host.getSubstats().getRecordedFinishes() == 0) { writeReportLine(writer, host.getSubstats().getRecordedFinishes(), host.getSubstats().getTotalBytes(), host.getHostName(), host.getSubstats().getRobotsDenials(), host.getSubstats().getRemaining(), host.getSubstats().getNovelUrls(), host.getSubstats().getNovelBytes(), host.getSubstats().getDupByHashUrls(), host.getSubstats().getDupByHashBytes(), host.getSubstats().getNotModifiedUrls(), host.getSubstats().getNotModifiedBytes()); } } }; controller.getServerCache().forAllHostsDo(logZeros); }
From source file:org.omnaest.utils.table.TableTest.java
@Test public void testIndex() throws Exception { Table<String> table = this.filledTable(100, 5); TableIndex<String, Cell<String>> tableIndex = table.index().of(1); assertNotNull(tableIndex);// ww w . j a v a 2s . c om { assertFalse(tableIndex.containsKey("0:0")); assertTrue(tableIndex.containsKey("0:1")); table.setElement(0, 1, "xxx"); assertFalse(tableIndex.containsKey("0:1")); assertTrue(tableIndex.containsKey("xxx")); Set<Cell<String>> cellSet = tableIndex.get("10:1"); assertEquals(1, cellSet.size()); } { assertSame(tableIndex, table.index().of(1)); assertSame(tableIndex, table.index().of(table.column(1))); } { SortedMap<String, Set<Cell<String>>> sortedMap = tableIndex; Set<Cell<String>> set = sortedMap.get("10:1"); assertNotNull(set); assertEquals(1, set.size()); Cell<String> cell = set.iterator().next(); assertEquals("10:1", cell.getElement()); } { table.clear(); assertTrue(tableIndex.isEmpty()); } }
From source file:com.googlecode.fascinator.common.StorageDataUtil.java
/** * Getlist method to get the values of key from the sourceMap * * @param sourceMap Map container//from w w w . java 2 s .c o m * @param baseKey field to search * @return list of value based on baseKey */ public Map<String, Object> getList(JsonSimple json, String baseKey) { SortedMap<String, Object> valueMap = new TreeMap<String, Object>(); Map<String, Object> data; if (baseKey == null) { log.error("NULL baseKey provided!"); return valueMap; } if (!baseKey.endsWith(".")) { baseKey = baseKey + "."; } if (json == null) { log.error("NULL JSON object provided!"); return valueMap; } // Look through the top level nodes for (Object oKey : json.getJsonObject().keySet()) { // If the key matches String key = (String) oKey; if (key.startsWith(baseKey)) { // Find our data String value = json.getString(null, key); String field = baseKey; if (key.length() >= baseKey.length()) { field = key.substring(baseKey.length(), key.length()); } String index = field; if (field.indexOf(".") > 0) { index = field.substring(0, field.indexOf(".")); } if (valueMap.containsKey(index)) { data = (Map<String, Object>) valueMap.get(index); } else { data = new LinkedHashMap<String, Object>(); valueMap.put(index, data); } if (value.length() == 1) { value = String.valueOf(value.charAt(0)); } data.put(field.substring(field.indexOf(".") + 1, field.length()), value); } } // log.info("{}: {}", baseKey, valueMap); return valueMap; }
From source file:org.jasig.schedassist.portlet.VisibleScheduleTag.java
@Override public int doStartTagInternal() { RenderRequest renderRequest = (RenderRequest) pageContext.getRequest().getAttribute(PORTLET_REQUEST); RenderResponse renderResponse = (RenderResponse) pageContext.getRequest().getAttribute(PORTLET_RESPONSE); final Date scheduleStart = visibleSchedule.getScheduleStart(); if (null == scheduleStart) { // the visibleSchedule is empty, short circuit try {// www . java 2 s .c o m StringBuilder noappointments = new StringBuilder(); noappointments.append("<span class=\"none-available\">"); noappointments.append(getMessageSource().getMessage("no.available.appointments", null, null)); noappointments.append("</span>"); pageContext.getOut().write(noappointments.toString()); } catch (IOException e) { LOG.error("IOException occurred in doStartTag", e); } // SKIP_BODY means don't print any content from body of tag return SKIP_BODY; } LOG.debug("scheduleStart: " + scheduleStart); SortedMap<Date, List<AvailableBlock>> dailySchedules = new TreeMap<Date, List<AvailableBlock>>(); Date index = DateUtils.truncate(scheduleStart, java.util.Calendar.DATE); Date scheduleEnd = visibleSchedule.getScheduleEnd(); while (index.before(scheduleEnd)) { dailySchedules.put(index, new ArrayList<AvailableBlock>()); index = DateUtils.addDays(index, 1); } final Date lastMapKey = dailySchedules.lastKey(); LOG.debug("visibleSchedule spans " + dailySchedules.keySet().size() + " days"); try { SortedMap<AvailableBlock, AvailableStatus> scheduleBlockMap = visibleSchedule.getBlockMap(); int numberOfEventsToDisplay = 0; for (AvailableBlock block : scheduleBlockMap.keySet()) { Date eventStartDate = block.getStartTime(); LOG.debug("event start date: " + eventStartDate); Date mapKey = DateUtils.truncate(eventStartDate, java.util.Calendar.DATE); if (CommonDateOperations.equalsOrAfter(eventStartDate, scheduleStart) && dailySchedules.containsKey(mapKey)) { dailySchedules.get(mapKey).add(block); numberOfEventsToDisplay++; } } LOG.debug("number of events to display: " + numberOfEventsToDisplay); if (numberOfEventsToDisplay == 0) { // no available times in this range! StringBuilder noappointments = new StringBuilder(); noappointments.append("<span class=\"none-available\">"); noappointments.append(getMessageSource().getMessage("no.available.appointments", null, null)); noappointments.append("</span>"); pageContext.getOut().write(noappointments.toString()); } else { int weekNumber = 1; Date currentWeekStart = DateUtils.truncate(scheduleStart, java.util.Calendar.DATE); Date currentWeekFinish = DateUtils.addDays(currentWeekStart, CommonDateOperations.numberOfDaysUntilSunday(currentWeekStart)); currentWeekFinish = DateUtils.addMinutes(currentWeekFinish, -1); boolean renderAnotherWeek = true; while (renderAnotherWeek) { if (LOG.isDebugEnabled()) { LOG.debug("will render another week using currentWeekStart " + currentWeekStart + " and currentWeekFinish " + currentWeekFinish); } SortedMap<Date, List<AvailableBlock>> subMap = dailySchedules.subMap(currentWeekStart, currentWeekFinish); renderWeek(pageContext.getOut(), weekNumber++, subMap, scheduleBlockMap, renderRequest, renderResponse); currentWeekStart = DateUtils.addMinutes(currentWeekFinish, 1); currentWeekFinish = DateUtils.addDays(currentWeekStart, 7); currentWeekFinish = DateUtils.addMinutes(currentWeekFinish, -1); if (LOG.isDebugEnabled()) { LOG.debug("recalculated currentWeekStart " + currentWeekStart + ", currentWeekFinish " + currentWeekFinish); } if (currentWeekStart.after(lastMapKey)) { renderAnotherWeek = false; LOG.debug("will not render another week"); } } } } catch (IOException e) { LOG.error("IOException occurred in doStartTag", e); } // SKIP_BODY means don't print any content from body of tag return SKIP_BODY; }
From source file:org.apache.carbondata.core.scan.filter.FilterUtil.java
private static void fillNullValuesStartIndexWithDefaultKeys(SortedMap<Integer, byte[]> setOfStartKeyByteArray, SegmentProperties segmentProperties) { List<CarbonDimension> allDimension = segmentProperties.getDimensions(); for (CarbonDimension dimension : allDimension) { if (CarbonUtil.hasEncoding(dimension.getEncoder(), Encoding.DICTIONARY)) { continue; }/* w w w .j a v a 2 s .c o m*/ if (null == setOfStartKeyByteArray.get(dimension.getOrdinal())) { setOfStartKeyByteArray.put(dimension.getOrdinal(), new byte[] { 0 }); } } }
From source file:org.apache.carbondata.core.scan.filter.FilterUtil.java
private static void fillNullValuesEndIndexWithDefaultKeys(SortedMap<Integer, byte[]> setOfStartKeyByteArray, SegmentProperties segmentProperties) { List<CarbonDimension> allDimension = segmentProperties.getDimensions(); for (CarbonDimension dimension : allDimension) { if (CarbonUtil.hasEncoding(dimension.getEncoder(), Encoding.DICTIONARY)) { continue; }//from ww w . ja va 2 s. co m if (null == setOfStartKeyByteArray.get(dimension.getOrdinal())) { setOfStartKeyByteArray.put(dimension.getOrdinal(), new byte[] { (byte) 0xFF }); } } }
From source file:tajo.master.GlobalPlanner.java
private Collection<List<Fragment>> hashFragments(List<Fragment> frags) { SortedMap<String, List<Fragment>> hashed = new TreeMap<String, List<Fragment>>(); for (Fragment f : frags) { if (hashed.containsKey(f.getPath().getName())) { hashed.get(f.getPath().getName()).add(f); } else {/* ww w . j a v a 2 s. com*/ List<Fragment> list = new ArrayList<Fragment>(); list.add(f); hashed.put(f.getPath().getName(), list); } } return hashed.values(); }
From source file:org.jasig.schedassist.web.VisibleScheduleTag.java
/** * Render a single week.// w ww . j av a2 s . c o m * * @param servletContext * @param writer * @param weekNumber * @param dailySchedules * @param scheduleBlockMap * @throws IOException */ protected void renderWeek(final ServletContext servletContext, final JspWriter writer, final int weekNumber, final SortedMap<Date, List<AvailableBlock>> dailySchedules, final SortedMap<AvailableBlock, AvailableStatus> scheduleBlockMap) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("begin renderWeek for " + weekNumber); } final boolean hasBlocks = doesWeekHaveBlocks(dailySchedules); if (hasBlocks) { final SimpleDateFormat headFormat = new SimpleDateFormat("EEE M/d"); writer.write("<div class=\"weekcontainer\" id=\"week" + weekNumber + "\">"); for (Map.Entry<Date, List<AvailableBlock>> entry : dailySchedules.entrySet()) { final Date day = entry.getKey(); final List<AvailableBlock> daySchedule = entry.getValue(); if (LOG.isDebugEnabled()) { LOG.debug("in renderWeek weeknumber: " + weekNumber + ", day: " + day); } if (daySchedule.size() > 0) { writer.write("<div class=\"weekday\">"); writer.write("<ul class=\"scheduleblocks\">"); writer.write("<li class=\"dayhead\">"); writer.write(headFormat.format(day)); writer.write("</li>"); for (AvailableBlock event : daySchedule) { AvailableStatus eventStatus = scheduleBlockMap.get(event); if (AvailableStatus.BUSY.equals(eventStatus)) { renderBusyBlock(servletContext, writer, event); } else if (AvailableStatus.FREE.equals(eventStatus)) { renderFreeBlock(servletContext, writer, event); } else if (AvailableStatus.ATTENDING.equals(eventStatus)) { renderAttendingBlock(servletContext, writer, event); } } writer.write("</ul>"); writer.write("</div> <!-- end weekday -->"); } } writer.write("</div> <!-- end weekcontainer -->"); } else { if (LOG.isDebugEnabled()) { LOG.debug("renderWeek has no blocks for weekNumber: " + weekNumber); } } }