List of usage examples for java.util SortedMap isEmpty
boolean isEmpty();
From source file:edu.umd.cfar.lamp.viper.util.Range.java
/** * Checks to see if the interval defined as [s,e) * is entirely contained within this Range object. * //from w w w . jav a 2s .c om * @param s * @param e * @return boolean */ public boolean withinRange(Comparable s, Comparable e) { SortedMap m = spans.headMap(e); if (!m.isEmpty()) { // thankfully Range keeps contiguous spans merged, // so this is easy Comparable start = (Comparable) m.lastKey(); Comparable end = (Comparable) m.get(start); if (end.compareTo(s) >= 0) { return start.compareTo(s) <= 0 && end.compareTo(e) >= 0; } } m = spans.tailMap(s); if (!m.isEmpty()) { Comparable sPrime = (Comparable) m.firstKey(); if (sPrime.compareTo(s) == 0) { return e.compareTo((Comparable) m.get(sPrime)) <= 0; } } return false; }
From source file:com.palantir.atlasdb.keyvalue.impl.AssertLockedKeyValueService.java
@Override public void put(String tableName, Map<Cell, byte[]> values, long timestamp) { if (tableName.equals(TransactionConstants.TRANSACTION_TABLE)) { SortedMap<LockDescriptor, LockMode> mapToAssertLockHeld = Maps.newTreeMap(); SortedMap<LockDescriptor, LockMode> mapToAssertLockNotHeld = Maps.newTreeMap(); for (Map.Entry<Cell, byte[]> e : values.entrySet()) { if (Arrays.equals(e.getValue(), TransactionConstants.getValueForTimestamp(TransactionConstants.FAILED_COMMIT_TS))) { mapToAssertLockNotHeld.put(AtlasRowLockDescriptor.of(tableName, e.getKey().getRowName()), LockMode.READ);/*from ww w .ja va 2s . c o m*/ } else { mapToAssertLockHeld.put(AtlasRowLockDescriptor.of(tableName, e.getKey().getRowName()), LockMode.READ); } } try { if (!mapToAssertLockHeld.isEmpty()) { LockRequest request = LockRequest.builder(mapToAssertLockHeld).doNotBlock() .lockAsManyAsPossible().build(); LockRefreshToken lock = lockService.lockAnonymously(request); Validate.isTrue(lock == null, "these should already be held"); } if (!mapToAssertLockNotHeld.isEmpty()) { LockRequest request = LockRequest.builder(mapToAssertLockNotHeld).doNotBlock().build(); LockRefreshToken lock = lockService.lockAnonymously(request); Validate.isTrue(lock != null, "these should already be waited for"); } } catch (InterruptedException e) { throw Throwables.throwUncheckedException(e); } } super.put(tableName, values, timestamp); }
From source file:edu.umd.cfar.lamp.viper.util.Range.java
/** * Checks to see if some interval of this * intersects the specified interval./*from w w w . j a va 2 s . co m*/ * @param s the interval to test against * @return <code>true</code> if there is some overlap */ public boolean intersects(Interval s) { if (this.isEmpty() || s.isEmpty()) { return false; } SortedMap m = spans.subMap(s.getStart(), s.getEnd()); if (!m.isEmpty()) { return true; } else { m = spans.headMap(s.getStart()); Interval last = (Interval) m.get(m.lastKey()); return last.intersects(s); } }
From source file:edu.umd.cfar.lamp.viper.util.Range.java
/** * @see edu.umd.cfar.lamp.viper.util.IntervalIndexList#endOf(java.lang.Comparable) *//*from www. jav a 2 s . c o m*/ public Comparable endOf(Comparable c) { if (c == null) { return null; } Object o = spans.get(c); if (o == null) { SortedMap head = spans.headMap(c); if (head != null && !head.isEmpty()) { Comparable last = (Comparable) spans.get(head.lastKey()); if (last.compareTo(c) >= 0) { return last; } } return null; } else { return (Comparable) o; } }
From source file:edu.umd.cfar.lamp.viper.util.Range.java
/** * Subsumes the Instants in the Span into this Range. * @param start the first instant to add * @param stop the stop instant, exclusive * @return <code>true</code> iff the operation modified this Range *//*from w ww .j a v a 2 s. c om*/ public boolean add(Comparable start, Comparable stop) { Comparable old = (Comparable) spans.get(start); if (old != null && old.compareTo(stop) >= 0) { return false; } SortedMap head = spans.headMap(start); if (!head.isEmpty()) { Comparable oldStart = (Comparable) head.lastKey(); Comparable oldEnd = (Comparable) head.get(oldStart); if (oldEnd.compareTo(stop) >= 0) { return false; } else { if (oldEnd.compareTo(start) >= 0) { start = oldStart; spans.remove(oldStart); } } } SortedMap sub = spans.subMap(start, stop); if (!sub.isEmpty()) { Comparable oldStart = (Comparable) sub.lastKey(); Comparable oldEnd = (Comparable) sub.get(oldStart); if (oldStart.compareTo(start) == 0 && oldEnd.compareTo(stop) >= 0) { return false; } else if (oldEnd.compareTo(stop) > 0) { stop = oldEnd; } sub.clear(); } if (spans.containsKey(stop)) { stop = (Comparable) spans.remove(stop); } spans.put(start, stop); return true; }
From source file:edu.umd.cfar.lamp.viper.util.Range.java
/** * @see edu.umd.cfar.lamp.viper.util.IntervalIndexList#remove(java.lang.Comparable, java.lang.Comparable) *///from ww w. j a va2 s . c o m public boolean remove(Comparable start, Comparable end) { boolean someFound = false; SortedMap head = spans.headMap(start); if (!head.isEmpty()) { Comparable oldStart = (Comparable) head.lastKey(); Comparable oldEnd = (Comparable) head.get(oldStart); if (oldEnd.compareTo(start) > 0) { // if there is a span that goes into the span to // be removed, replace it. head.put(oldStart, start); someFound = true; double toCheck = oldEnd.compareTo(end); if (toCheck > 0) { // if the span to be removed is a strict subset // of some existing span, you also have // to add back the end. spans.put(end, oldEnd); return true; } else if (toCheck == 0) { return true; } } } SortedMap sub = spans.subMap(start, end); if (!sub.isEmpty()) { someFound = true; Comparable oldStart = (Comparable) sub.lastKey(); Comparable oldEnd = (Comparable) sub.get(oldStart); if (oldEnd.compareTo(end) > 0) { // if there is a span that starts during the // span to removed that goes past the end, // have to add back the difference. spans.put(end, oldEnd); } sub.clear(); } return someFound; }
From source file:hudson.plugins.jobConfigHistory.FileHistoryDaoTest.java
/** * Test of getJobHistory method, of class FileHistoryDao. *//*w w w . j ava2 s. com*/ @Test public void testGetJobHistoryNonExistent() { final SortedMap<String, HistoryDescr> result = sutWithUserAndNoDuplicateHistory .getJobHistory("JobDoesNotExist"); assertTrue(result.isEmpty()); }
From source file:module.workingCapital.presentationTier.action.WorkingCapitalAction.java
private ActionForward exportInfoToExcel(Set<WorkingCapitalProcess> processes, WorkingCapitalContext context, HttpServletResponse response) throws Exception { final Integer year = context.getWorkingCapitalYear().getYear(); SheetData<WorkingCapitalProcess> sheetData = new SheetData<WorkingCapitalProcess>(processes) { @Override// w w w. j a v a 2 s . co m protected void makeLine(WorkingCapitalProcess workingCapitalProcess) { if (workingCapitalProcess == null) { return; } final WorkingCapital workingCapital = workingCapitalProcess.getWorkingCapital(); final WorkingCapitalInitialization initialization = workingCapital .getWorkingCapitalInitialization(); final AccountingUnit accountingUnit = workingCapital.getAccountingUnit(); addCell(getLocalizedMessate("label.module.workingCapital.year"), year); addCell(getLocalizedMessate("label.module.workingCapital"), workingCapitalProcess.getWorkingCapital().getUnit().getPresentationName()); addCell(getLocalizedMessate("WorkingCapitalProcessState"), workingCapitalProcess.getPresentableAcquisitionProcessState().getLocalizedName()); addCell(getLocalizedMessate("label.module.workingCapital.unit.responsible"), getUnitResponsibles(workingCapital)); addCell(getLocalizedMessate("label.module.workingCapital.initialization.accountingUnit"), accountingUnit == null ? "" : accountingUnit.getName()); addCell(getLocalizedMessate("label.module.workingCapital.requestingDate"), initialization.getRequestCreation().toString("yyyy-MM-dd HH:mm:ss")); addCell(getLocalizedMessate("label.module.workingCapital.requester"), initialization.getRequestor().getName()); final Person movementResponsible = workingCapital.getMovementResponsible(); addCell(getLocalizedMessate("label.module.workingCapital.movementResponsible"), movementResponsible == null ? "" : movementResponsible.getName()); addCell(getLocalizedMessate("label.module.workingCapital.fiscalId"), initialization.getFiscalId()); addCell(getLocalizedMessate("label.module.workingCapital.internationalBankAccountNumber"), initialization.getInternationalBankAccountNumber()); addCell(getLocalizedMessate("label.module.workingCapital.fundAllocationId"), initialization.getFundAllocationId()); final Money requestedAnualValue = initialization.getRequestedAnualValue(); addCell(getLocalizedMessate("label.module.workingCapital.requestedAnualValue.requested"), requestedAnualValue); addCell(getLocalizedMessate("label.module.workingCapital.requestedMonthlyValue.requested"), requestedAnualValue.divideAndRound(new BigDecimal(6))); final Money authorizedAnualValue = initialization.getAuthorizedAnualValue(); addCell(getLocalizedMessate("label.module.workingCapital.authorizedAnualValue"), authorizedAnualValue == null ? "" : authorizedAnualValue); final Money maxAuthorizedAnualValue = initialization.getMaxAuthorizedAnualValue(); addCell(getLocalizedMessate("label.module.workingCapital.maxAuthorizedAnualValue"), maxAuthorizedAnualValue == null ? "" : maxAuthorizedAnualValue); final DateTime lastSubmission = initialization.getLastSubmission(); addCell(getLocalizedMessate("label.module.workingCapital.initialization.lastSubmission"), lastSubmission == null ? "" : lastSubmission.toString("yyyy-MM-dd")); final DateTime refundRequested = initialization.getRefundRequested(); addCell(getLocalizedMessate("label.module.workingCapital.initialization.refundRequested"), refundRequested == null ? "" : refundRequested.toString("yyyy-MM-dd")); final WorkingCapitalTransaction lastTransaction = workingCapital.getLastTransaction(); if (lastTransaction == null) { addCell(getLocalizedMessate("label.module.workingCapital.transaction.accumulatedValue"), Money.ZERO); addCell(getLocalizedMessate("label.module.workingCapital.transaction.balance"), Money.ZERO); addCell(getLocalizedMessate("label.module.workingCapital.transaction.debt"), Money.ZERO); } else { addCell(getLocalizedMessate("label.module.workingCapital.transaction.accumulatedValue"), lastTransaction.getAccumulatedValue()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.balance"), lastTransaction.getBalance()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.debt"), lastTransaction.getDebt()); } for (final AcquisitionClassification classification : WorkingCapitalSystem.getInstance() .getAcquisitionClassificationsSet()) { final String description = classification.getDescription(); final String pocCode = classification.getPocCode(); final String key = pocCode + " - " + description; final Money value = calculateValueForClassification(workingCapital, classification); addCell(key, value); } } private Money calculateValueForClassification(final WorkingCapital workingCapital, final AcquisitionClassification classification) { Money result = Money.ZERO; for (final WorkingCapitalTransaction transaction : workingCapital .getWorkingCapitalTransactionsSet()) { if (transaction.isAcquisition()) { final WorkingCapitalAcquisitionTransaction acquisitionTransaction = (WorkingCapitalAcquisitionTransaction) transaction; final WorkingCapitalAcquisition acquisition = acquisitionTransaction .getWorkingCapitalAcquisition(); final AcquisitionClassification acquisitionClassification = acquisition .getAcquisitionClassification(); if (acquisitionClassification == classification) { result = result.add(acquisition.getValueAllocatedToSupplier()); } } } return result; } private String getUnitResponsibles(final WorkingCapital workingCapital) { final StringBuilder builder = new StringBuilder(); final SortedMap<Person, Set<Authorization>> authorizations = workingCapital .getSortedAuthorizations(); if (!authorizations.isEmpty()) { for (final Entry<Person, Set<Authorization>> entry : authorizations.entrySet()) { if (builder.length() > 0) { builder.append("; "); } builder.append(entry.getKey().getName()); } } return builder.toString(); } }; final LocalDate currentLocalDate = new LocalDate(); final SpreadsheetBuilder builder = new SpreadsheetBuilder(); builder.addConverter(Money.class, new CellConverter() { @Override public Object convert(final Object source) { final Money money = (Money) source; return money == null ? null : new Double( money.getValue().round(new MathContext(2, RoundingMode.HALF_EVEN)).doubleValue()); } }); builder.addSheet(getLocalizedMessate("label.module.workingCapital") + " " + year + " - " + currentLocalDate.toString(), sheetData); final List<WorkingCapitalTransaction> transactions = new ArrayList<WorkingCapitalTransaction>(); for (final WorkingCapitalProcess process : processes) { final WorkingCapital workingCapital = process.getWorkingCapital(); transactions.addAll(workingCapital.getSortedWorkingCapitalTransactions()); } final SheetData<WorkingCapitalTransaction> transactionsSheet = new SheetData<WorkingCapitalTransaction>( transactions) { @Override protected void makeLine(WorkingCapitalTransaction transaction) { final WorkingCapital workingCapital = transaction.getWorkingCapital(); final WorkingCapitalProcess workingCapitalProcess = workingCapital.getWorkingCapitalProcess(); addCell(getLocalizedMessate("label.module.workingCapital.year"), year); addCell(getLocalizedMessate("label.module.workingCapital"), workingCapitalProcess.getWorkingCapital().getUnit().getPresentationName()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.number"), transaction.getNumber()); addCell(getLocalizedMessate("WorkingCapitalProcessState.CANCELED"), transaction.isCanceledOrRejected() ? getLocalizedMessate("label.yes") : getLocalizedMessate("label.no")); addCell(getLocalizedMessate("label.module.workingCapital.transaction.description") + " " + getLocalizedMessate("label.module.workingCapital.transaction.number"), transaction.getDescription()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.approval"), approvalLabel(transaction)); addCell(getLocalizedMessate("label.module.workingCapital.transaction.verification"), verificationLabel(transaction)); addCell(getLocalizedMessate("label.module.workingCapital.transaction.value"), transaction.getValue()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.accumulatedValue"), transaction.getAccumulatedValue()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.balance"), transaction.getBalance()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.debt"), transaction.getDebt()); if (transaction.isAcquisition()) { final WorkingCapitalAcquisitionTransaction acquisitionTx = (WorkingCapitalAcquisitionTransaction) transaction; final WorkingCapitalAcquisition acquisition = acquisitionTx.getWorkingCapitalAcquisition(); final AcquisitionClassification acquisitionClassification = acquisition .getAcquisitionClassification(); final String economicClassification = acquisitionClassification.getEconomicClassification(); final String pocCode = acquisitionClassification.getPocCode(); addCell(getLocalizedMessate( "label.module.workingCapital.configuration.acquisition.classifications.economicClassification"), economicClassification); addCell(getLocalizedMessate( "label.module.workingCapital.configuration.acquisition.classifications.pocCode"), pocCode); addCell(getLocalizedMessate( "label.module.workingCapital.configuration.acquisition.classifications.description"), acquisition.getDescription()); } } private Object verificationLabel(final WorkingCapitalTransaction transaction) { if (transaction.isAcquisition()) { final WorkingCapitalAcquisitionTransaction acquisition = (WorkingCapitalAcquisitionTransaction) transaction; if (acquisition.getWorkingCapitalAcquisition().getVerified() != null) { return getLocalizedMessate("label.verified"); } if (acquisition.getWorkingCapitalAcquisition().getNotVerified() != null) { return getLocalizedMessate("label.notVerified"); } } return "-"; } private String approvalLabel(final WorkingCapitalTransaction transaction) { if (transaction.isAcquisition()) { final WorkingCapitalAcquisitionTransaction acquisition = (WorkingCapitalAcquisitionTransaction) transaction; if (acquisition.getWorkingCapitalAcquisition().getApproved() != null) { return getLocalizedMessate("label.approved"); } if (acquisition.getWorkingCapitalAcquisition().getRejectedApproval() != null) { return getLocalizedMessate("label.rejected"); } } return "-"; } }; builder.addSheet(getLocalizedMessate("label.module.workingCapital.transactions"), transactionsSheet); return streamSpreadsheet(response, "FundosManeio_" + year + "-" + currentLocalDate.getDayOfMonth() + "-" + currentLocalDate.getMonthOfYear() + "-" + currentLocalDate.getYear(), builder); }
From source file:hudson.plugins.jobConfigHistory.FileHistoryDaoTest.java
/** * Test of getSystemHistory method, of class FileHistoryDao. *///from ww w .ja va 2 s . c om @Test public void testGetSystemHistoryNonExistent() { final SortedMap<String, HistoryDescr> result = sutWithUserAndNoDuplicateHistory .getSystemHistory("config-does-not-exist"); assertTrue(result.isEmpty()); }
From source file:com.activecq.tools.errorpagehandler.impl.ErrorPageHandlerImpl.java
/** * Find the full path to the most appropriate Error Page * * @param request/* w ww .j av a 2s . c o m*/ * @param errorResource * @return */ @Override public String findErrorPage(SlingHttpServletRequest request, Resource errorResource) { if (!isEnabled()) { return null; } Resource page = null; final ResourceResolver resourceResolver = errorResource.getResourceResolver(); // Get error page name to look for based on the error code/name final String pageName = getErrorPageName(request); // Try to find the closest real parent for the requested resource final Resource parent = findFirstRealParentOrSelf(errorResource); final SortedMap<String, String> errorPagesMap = getErrorPagesMap(resourceResolver); if (!errorPagesMap.isEmpty()) { // Get the best-matching Errors Path for this particular Request final String errorsPath = this.getErrorPagesPath(parent, errorPagesMap); if (StringUtils.isNotBlank(errorsPath)) { // Search for CQ Page for specific servlet named Page (404, 500, Throwable, etc.) SearchResult result = executeQuery(resourceResolver, pageName); List<String> errorPaths = filterResults(errorsPath, result); // Return the first existing match for (String errorPath : errorPaths) { page = getResource(resourceResolver, errorPath); if (page != null) { break; } } // No error-specific page could be found, use the "default" error page // for the Root content path if (page == null && StringUtils.isNotBlank(errorsPath)) { page = resourceResolver.resolve(errorsPath); } } } if (page == null || ResourceUtil.isNonExistingResource(page)) { // If no error page could be found if (this.hasSystemErrorPage()) { final String errorPage = applyExtension(this.getSystemErrorPagePath()); log.debug("Using default error page: {}", errorPage); return StringUtils.stripToNull(errorPage); } } else { final String errorPage = applyExtension(page.getPath()); log.debug("Using resolved error page: {}", errorPage); return StringUtils.stripToNull(errorPage); } return null; }