List of usage examples for java.util SortedSet last
E last();
From source file:net.sf.jasperreports.engine.export.tabulator.Tabulator.java
protected boolean placeElement(Table table, FrameCell parentCell, int xOffset, int yOffset, JRPrintElement element, PrintElementIndex parentIndex, int elementIndex, boolean allowOverlap) { DimensionRange<Column> colRange = table.columns.getRange(element.getX() + xOffset, element.getX() + element.getWidth() + xOffset); DimensionRange<Row> rowRange = table.rows.getRange(element.getY() + yOffset, element.getY() + element.getHeight() + yOffset); if (log.isTraceEnabled()) { log.trace("placing element " + element.getUUID() + " at " + colRange.start + ", " + colRange.end + ", " + rowRange.start + ", " + rowRange.end); }//from w w w. j a v a2s . c om boolean overlap = false; Bounds overlapBounds = new Bounds(colRange.start, colRange.end, rowRange.start, rowRange.end); JROrigin elementOrigin = element.getOrigin(); if (parentCell == null // top level element && elementOrigin != null && elementOrigin.getReportName() == null // master background element // TODO lucianc do something for subreport background bands as well && elementOrigin.getBandTypeValue() == BandTypeEnum.BACKGROUND) { // create a layer as big as the table for the master background band SortedSet<Column> userColumns = table.columns.getUserEntries(); SortedSet<Row> userRows = table.rows.getUserEntries(); // check if we have something in the table if (!userColumns.isEmpty() && !userRows.isEmpty()) { overlapBounds.grow(userColumns.first().startCoord, userColumns.last().endCoord, userRows.first().startCoord, userRows.last().endCoord); // TODO lucianc avoid the following cell overlap checks } } Bounds covered = null; Bounds originalBounds; overlapLoop: do { originalBounds = overlapBounds.cloneBounds(); if (rowRange.start != overlapBounds.getStartY() || rowRange.end != overlapBounds.getEndY()) { rowRange = table.rows.getRange(overlapBounds.getStartY(), overlapBounds.getEndY()); } if (colRange.start != overlapBounds.getStartX() || colRange.end != overlapBounds.getEndX()) { colRange = table.columns.getRange(overlapBounds.getStartX(), overlapBounds.getEndX()); } for (Row row : rowRange.rangeSet) { for (Column col : colRange.rangeSet) { if (covered != null && covered.contains(col.startCoord, col.endCoord, row.startCoord, row.endCoord)) { //we've been here before continue; } Cell cell = row.getCell(col); if (!canOverwrite(cell, parentCell)) { overlap = true; if (!allowOverlap) { break overlapLoop; } // TODO lucianc see if we can avoid some of these checks Cell overlapParentCell = overlapParentCell(cell, parentCell); Pair<Column, Column> colSpanRange = getColumnSpanRange(table, col, row, overlapParentCell); Pair<Row, Row> rowSpanRange = getRowSpanRange(table, col, row, overlapParentCell); if (log.isTraceEnabled()) { log.trace("found overlap with cell " + cell + ", overlap parent " + overlapParentCell + ", column span range " + colSpanRange.first().startCoord + " to " + colSpanRange.second().startCoord + ", row span range " + rowSpanRange.first().startCoord + " to " + rowSpanRange.second().startCoord); } overlapBounds.grow(colSpanRange.first().startCoord, colSpanRange.second().startCoord, rowSpanRange.first().startCoord, rowSpanRange.second().startCoord); } } } covered = originalBounds; } while (!originalBounds.equals(overlapBounds)); if (!overlap) { setElementCells(table, parentCell, xOffset, yOffset, element, parentIndex, elementIndex, colRange, rowRange); return true; } if (!allowOverlap) { return false; } placeOverlappedElement(table, parentCell, xOffset, yOffset, element, parentIndex, elementIndex, overlapBounds); return true; }
From source file:org.egov.ptis.bean.PropertyInfo.java
/** * The method returns the date the property was transfered last. If the * property has not been transfered, transfer date is null. * /* www . jav a 2s . c o m*/ * @return a <code>Date</code> instance indicating the date when the * property was transfered */ public Date getTransferDate() { Set<PropertyMutation> propMutSet = property.getBasicProperty().getPropertyMutations(); if (propMutSet.isEmpty()) { return null; } SortedSet<Date> mutationDates = new TreeSet<Date>(); for (PropertyMutation propertyMutation : propMutSet) { mutationDates.add(propertyMutation.getCreatedDate()); } return mutationDates.last(); }
From source file:org.libreplan.web.limitingresources.LimitingResourceQueueModel.java
/** * Returns queue which last element is at a earliest date. * * @param potentiallyValidQueues//from w w w . j ava 2 s . co m * @return {@link LimitingResourceQueue} */ private LimitingResourceQueue earliestQueue(List<LimitingResourceQueue> potentiallyValidQueues) { LimitingResourceQueue result = null; LocalDate latestDate = null; for (LimitingResourceQueue each : potentiallyValidQueues) { SortedSet<LimitingResourceQueueElement> elements = each.getLimitingResourceQueueElements(); if (!elements.isEmpty()) { LocalDate date = elements.last().getEndDate(); if (latestDate == null || date.isAfter(latestDate)) { latestDate = date; result = each; } } } if (result == null && !potentiallyValidQueues.isEmpty()) { result = potentiallyValidQueues.get(0); } return result; }
From source file:net.sourceforge.fenixedu.domain.Lesson.java
public LessonInstance getLastLessonInstance() { SortedSet<LessonInstance> result = new TreeSet<LessonInstance>( LessonInstance.COMPARATOR_BY_BEGIN_DATE_TIME); result.addAll(getLessonInstancesSet()); return !result.isEmpty() ? result.last() : null; }
From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java
/** * @throws ParseException //w ww . j a v a 2s . co m * @throws InputFormatException * */ @Test public void testTwentyMinuteDuration() throws InputFormatException, ParseException { SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat(); SortedSet<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "11:40 AM", "MW", dateFormat.parse("20100830"), dateFormat.parse("20100903")); Assert.assertEquals(2, blocks.size()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100830-0900"), blocks.first().getStartTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100830-1140"), blocks.first().getEndTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100901-0900"), blocks.last().getStartTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100901-1140"), blocks.last().getEndTime()); SortedSet<AvailableBlock> expanded = AvailableBlockBuilder.expand(blocks, 20); Assert.assertEquals(16, expanded.size()); Date originalStart = CommonDateOperations.getDateTimeFormat().parse("20100830-0900"); Date currentStart = originalStart; for (AvailableBlock e : expanded) { if (!DateUtils.isSameDay(e.getStartTime(), currentStart)) { currentStart = DateUtils.addDays(originalStart, 2); } Assert.assertEquals(currentStart, e.getStartTime()); currentStart = DateUtils.addMinutes(currentStart, 20); Assert.assertEquals(currentStart, e.getEndTime()); } }
From source file:controllers.Statistics.java
private static void getElapsedTimeStatisticsForSeconds(long secondInMillis, int previousSeconds, String target, ObjectNode objectNode) {/*w w w. ja v a 2 s . co m*/ TitanGraph g = Global.getGraph(); long second = (secondInMillis / 1000) * 1000; SortedSet<Integer> numSet = new TreeSet<Integer>(); int value = 0; int sum = 0; int count = 0; for (int i = (previousSeconds - 1); i > -1; i--) { //Logger.info("previousSeconds=" + (second - (i * 1000))); Iterator<Vertex> it = g.getVertices("second", second - (i * 1000)).iterator(); Vertex v = null; //if(it.hasNext()) { while (it.hasNext()) { v = it.next(); for (Vertex vertex : v.query().labels("include").has("event", target).vertices()) { if (vertex == null) { continue; } value = (Integer) vertex.getProperty("elapsedTime"); count++; sum += value; numSet.add(value); } } } objectNode.put("cnt", count); if (count > 0) { objectNode.put("avg", sum / count); objectNode.put("min", numSet.first()); objectNode.put("max", numSet.last()); } else { objectNode.put("avg", 0); objectNode.put("min", 0); objectNode.put("max", 0); } }
From source file:org.hyperic.hq.plugin.dotnet.DotNetDetector.java
private String getVersion() { RegistryKey key = null;//from ww w . jav a2 s . c o m RegistryKey versionKey = null; SortedSet<String> versions = new TreeSet<String>(); try { key = getRegistryKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP"); String[] names = key.getSubKeyNames(); for (String versionKeyName : names) { if (versionKeyName.startsWith("v") && !versionKeyName.startsWith("v4")) { versionKey = key.openSubKey(versionKeyName); findVersion(versionKey, versions); } else if (versionKeyName.startsWith("v4")) { versionKey = key.openSubKey(versionKeyName); for (String subKeyName : versionKey.getSubKeyNames()) { RegistryKey subKey = versionKey.openSubKey(subKeyName); findVersion(subKey, versions); } } } } catch (Win32Exception e) { log.debug(e, e); return null; } finally { if (key != null) { key.close(); } } log.debug("Found .NET versions=" + versions); //all runtime versions have the same metrics, //so just discover the highest version return (versions.size() > 0) ? versions.last() : ""; }
From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java
/** * Test that highlights the problem when a customer specifies a start/end range * for blocks and a meeting duration that leaves a remainder. * /*ww w .ja v a 2s.co m*/ * @throws ParseException * @throws InputFormatException */ @Test public void testDurationLeavesRemainder() throws InputFormatException, ParseException { SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat(); SortedSet<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("9:03 AM", "3:19 PM", "MWF", dateFormat.parse("20100830"), dateFormat.parse("20100903")); Assert.assertEquals(3, blocks.size()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100830-0903"), blocks.first().getStartTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100830-1519"), blocks.first().getEndTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100903-0903"), blocks.last().getStartTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100903-1519"), blocks.last().getEndTime()); SortedSet<AvailableBlock> expanded = AvailableBlockBuilder.expand(blocks, 17); AvailableBlock last = null; long millisIn17Minutes = 1020000L; for (AvailableBlock e : expanded) { if (last != null) { if (DateUtils.isSameDay(e.getStartTime(), last.getStartTime())) { Assert.assertEquals(last.getEndTime(), e.getStartTime()); Assert.assertEquals(e.getEndTime().getTime() - last.getEndTime().getTime(), millisIn17Minutes); } else { Calendar cal = Calendar.getInstance(); cal.setTime(e.getStartTime()); Assert.assertEquals(9, cal.get(Calendar.HOUR_OF_DAY)); Assert.assertEquals(3, cal.get(Calendar.MINUTE)); cal.setTime(e.getEndTime()); Assert.assertEquals(9, cal.get(Calendar.HOUR_OF_DAY)); Assert.assertEquals(20, cal.get(Calendar.MINUTE)); // double check yesterday's endpoint cal.setTime(last.getStartTime()); Assert.assertEquals(15, cal.get(Calendar.HOUR_OF_DAY)); Assert.assertEquals(0, cal.get(Calendar.MINUTE)); cal.setTime(last.getEndTime()); Assert.assertEquals(15, cal.get(Calendar.HOUR_OF_DAY)); Assert.assertEquals(17, cal.get(Calendar.MINUTE)); } } else { // first block in the series Calendar cal = Calendar.getInstance(); cal.setTime(e.getStartTime()); Assert.assertEquals(9, cal.get(Calendar.HOUR_OF_DAY)); Assert.assertEquals(3, cal.get(Calendar.MINUTE)); cal.setTime(e.getEndTime()); Assert.assertEquals(9, cal.get(Calendar.HOUR_OF_DAY)); Assert.assertEquals(20, cal.get(Calendar.MINUTE)); } last = e; } Assert.assertEquals(66, expanded.size()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100830-0903"), expanded.first().getStartTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100830-0920"), expanded.first().getEndTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100903-1500"), expanded.last().getStartTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100903-1517"), expanded.last().getEndTime()); }
From source file:com.google.gwt.emultest.java.util.TreeSetTest.java
/** * Test method for 'java.util.SortedSet.last()'. * * @see java.util.SortedSet#last()/*from ww w .ja v a 2 s .c om*/ */ public void testLastKey() { SortedSet<E> sortedSet = createNavigableSet(); // test with a single entry set sortedSet.add(getKeys()[0]); assertEquals(getKeys()[0], sortedSet.last()); // is it consistent with other methods assertEquals(sortedSet.toArray()[0], sortedSet.last()); assertEquals(getKeys()[0], sortedSet.first()); assertEquals(sortedSet.first(), sortedSet.last()); // test with two entry set sortedSet.add(getKeys()[1]); assertEquals(getKeys()[1], sortedSet.last()); assertFalse(getKeys()[0].equals(sortedSet.last())); // is it consistent with other methods assertEquals(sortedSet.toArray()[1], sortedSet.last()); assertEquals(getKeys()[0], sortedSet.first()); assertFalse(sortedSet.first().equals(sortedSet.last())); }
From source file:com.google.gwt.emultest.java.util.TreeSetTest.java
/** * Test method for 'java.util.SortedSet.first()'. * * @see java.util.SortedSet#first()// ww w .j a v a2s. com */ public void testFirst() { SortedSet<E> sortedSet = createNavigableSet(); // test with a single entry set sortedSet.add(getKeys()[0]); assertEquals(getKeys()[0], sortedSet.first()); // is it consistent with other methods assertEquals(sortedSet.toArray()[0], sortedSet.first()); assertEquals(getKeys()[0], sortedSet.last()); assertEquals(sortedSet.last(), sortedSet.first()); // test with two entry set sortedSet.add(getKeys()[1]); assertEquals(getKeys()[0], sortedSet.first()); assertFalse(getKeys()[1].equals(sortedSet.first())); // is it consistent with other methods assertEquals(sortedSet.toArray()[0], sortedSet.first()); assertFalse(getKeys()[0].equals(sortedSet.last())); assertFalse(sortedSet.last().equals(sortedSet.first())); }