List of usage examples for java.util SortedMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:org.apache.falcon.resource.proxy.ExtensionManagerProxy.java
private void scheduleEntities(SortedMap<EntityType, List<String>> entityMap, HttpServletRequest request, String coloExpr) throws FalconException { HttpServletRequest bufferedRequest = new BufferedRequest(request); for (Map.Entry<EntityType, List<String>> entityTypeEntry : entityMap.entrySet()) { for (final String entityName : entityTypeEntry.getValue()) { entityProxyUtil.proxySchedule(entityTypeEntry.getKey().name(), entityName, coloExpr, Boolean.FALSE, "", bufferedRequest); }//from w ww . j a v a 2s . co m } }
From source file:com.bombardier.plugin.scheduling.TestScheduler.java
/** * Used to calculate average execution time per byte * //from w ww . j a va 2 s . c o m * @param map * the map containing data about execution time * @return * @since 1.0 */ private double getAveragePerByte(SortedMap<Long, Double> map) { double avg = 0; for (Entry<Long, Double> entry : map.entrySet()) { avg = Math.round(((avg + (entry.getValue() / entry.getKey())) / 2) * 100000.0) / 100000.0; } return avg; }
From source file:org.apache.falcon.resource.proxy.ExtensionManagerProxy.java
private void resumeEntities(SortedMap<EntityType, List<String>> entityNameMap, String coloExpr, final HttpServletRequest request) throws FalconException { HttpServletRequest bufferedRequest = new BufferedRequest(request); for (Map.Entry<EntityType, List<String>> entityTypeEntry : entityNameMap.entrySet()) { for (final String entityName : entityTypeEntry.getValue()) { entityProxyUtil.proxyResume(entityTypeEntry.getKey().name(), entityName, coloExpr, bufferedRequest); }//from ww w.j a v a 2 s . c o m } }
From source file:org.apache.falcon.resource.proxy.ExtensionManagerProxy.java
private void suspendEntities(SortedMap<EntityType, List<String>> entityNameMap, String coloExpr, final HttpServletRequest request) throws FalconException { HttpServletRequest bufferedRequest = new BufferedRequest(request); for (Map.Entry<EntityType, List<String>> entityTypeEntry : entityNameMap.entrySet()) { for (final String entityName : entityTypeEntry.getValue()) { entityProxyUtil.proxySuspend(entityTypeEntry.getKey().name(), entityName, coloExpr, bufferedRequest);/*from w w w . jav a 2 s . c o m*/ } } }
From source file:com.bombardier.plugin.scheduling.TestScheduler.java
/** * Used to calculate the average execution time per line of code. * //from w w w . ja v a 2 s. c o m * @param map * the map containing data about execution time. * @return * @since 1.0 */ private double getAveragePerLine(SortedMap<Integer, Double> map) { double avg = 0; for (Entry<Integer, Double> entry : map.entrySet()) { avg = Math.round(((avg + (entry.getValue() / entry.getKey())) / 2) * 100.0) / 100.0; } return avg; }
From source file:com.moded.extendedchoiceparameter.ExtendedChoiceParameterDefinition.java
private List<String> getRole(String role_level) { List<String> assignedRoles = new ArrayList<String>(); try {/*from ww w .j a v a 2 s. c om*/ // get logged-in user id String userId = User.current().getId(); // get assigned role(s) AuthorizationStrategy authStrategy = Hudson.getInstance().getAuthorizationStrategy(); User user = Hudson.getInstance().getUser(userId); if (authStrategy instanceof RoleBasedAuthorizationStrategy) { RoleBasedAuthorizationStrategy roleBasedAuthStrategy = (RoleBasedAuthorizationStrategy) authStrategy; SortedMap<Role, Set<String>> globalRoles = roleBasedAuthStrategy.getGrantedRoles(role_level); for (Map.Entry<Role, Set<String>> entry : globalRoles.entrySet()) { Set<String> set = entry.getValue(); if (set.contains(userId)) { String role = entry.getKey().getName(); assignedRoles.add(role); } } } } catch (Exception e) { } finally { return assignedRoles; } }
From source file:org.jasig.schedassist.web.VisibleScheduleTag.java
/** * Render a single week./*from w w w .ja va 2 s . com*/ * * @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); } } }
From source file:org.elasticsoftware.elasticactors.cluster.LocalActorSystemInstance.java
/** * Distribute the shards over the list of physical nodes * * @param nodes//from www. j a v a2s .co m */ public void distributeShards(List<PhysicalNode> nodes, ShardDistributionStrategy strategy) throws Exception { final boolean initializing = initialized.compareAndSet(false, true); // see if this was the first time, if so we need to initialize the ActorSystem if (initializing) { logger.info(format("Initializing ActorSystem [%s]", getName())); } NodeSelector nodeSelector = nodeSelectorFactory.create(nodes); // fetch all writelocks final Lock[] writeLocks = new Lock[shardLocks.length]; for (int j = 0; j < shardLocks.length; j++) { writeLocks[j] = shardLocks[j].writeLock(); } // store the id's of the new local shard in order to generate the events later final List<Integer> newLocalShards = new ArrayList<>(shards.length); // this is for reporting the number of shards per node final List<String> nodeCount = new ArrayList<>(shards.length); // assume we are stable until the resharding process tells us otherwise boolean stable = true; try { for (Lock writeLock : writeLocks) { writeLock.lock(); } for (int i = 0; i < configuration.getNumberOfShards(); i++) { ShardKey shardKey = new ShardKey(configuration.getName(), i); PhysicalNode node = nodeSelector.getPrimary(shardKey.toString()); nodeCount.add(node.getId()); if (node.isLocal()) { // this instance should start owning the shard now final ActorShard currentShard = shards[i]; if (currentShard == null || !currentShard.getOwningNode().isLocal()) { String owningNodeId = currentShard != null ? currentShard.getOwningNode().getId() : "<No Node>"; logger.info(format("I will own %s", shardKey.toString())); // destroy the current remote shard instance if (currentShard != null) { currentShard.destroy(); } // create a new local shard and swap it LocalActorShard newShard = new LocalActorShard(node, this, i, shardAdapters[i].myRef, localMessageQueueFactory, shardActorCacheManager); shards[i] = newShard; try { // register with the strategy to wait for shard to be released strategy.registerWaitForRelease(newShard, node); } catch (Exception e) { logger.error(format( "IMPORTANT: waiting on release of shard %s from node %s failed, ElasticActors cluster is unstable. Please check all nodes", shardKey, owningNodeId), e); stable = false; } finally { // add it to the new local shards newLocalShards.add(i); // initialize // newShard.init(); // start owning the scheduler shard (this will start sending messages, but everything is blocked so it should be no problem) scheduler.registerShard(newShard.getKey()); } } else { // we own the shard already, no change needed logger.info(format("I already own %s", shardKey.toString())); } } else { // the shard will be managed by another node final ActorShard currentShard = shards[i]; if (currentShard == null || currentShard.getOwningNode().isLocal()) { logger.info(format("%s will own %s", node, shardKey)); try { // destroy the current local shard instance if (currentShard != null) { // stop owning the scheduler shard scheduler.unregisterShard(currentShard.getKey()); currentShard.destroy(); strategy.signalRelease(currentShard, node); } } catch (Exception e) { logger.error(format( "IMPORTANT: signalling release of shard %s to node %s failed, ElasticActors cluster is unstable. Please check all nodes", shardKey, node), e); stable = false; } finally { // create a new remote shard and swap it RemoteActorShard newShard = new RemoteActorShard(node, this, i, shardAdapters[i].myRef, remoteMessageQueueFactory); shards[i] = newShard; // initialize newShard.init(); } } else { // shard was already remote logger.info(format("%s will own %s", node, shardKey)); } } } // now we have released all local shards, wait for the new local shards to become available if (!strategy.waitForReleasedShards(10, TimeUnit.SECONDS)) { // timeout while waiting for the shards stable = false; } } finally { // unlock all for (Lock writeLock : writeLocks) { writeLock.unlock(); } this.stable.set(stable); } // This needs to happen after we initialize the shards as services expect the system to be initialized and // should be allowed to send messages to shards if (initializing) { // initialize the services Set<String> serviceActors = configuration.getServices(); if (serviceActors != null && !serviceActors.isEmpty()) { // initialize the service actors in the context for (String elasticActorEntry : serviceActors) { localNodeAdapter.sendMessage(null, localNodeAdapter.myRef, new ActivateActorMessage(getName(), elasticActorEntry, ActorType.SERVICE)); } } } // print out the shard distribution here Map<String, Long> collect = nodeCount.stream().collect(groupingBy(Function.identity(), counting())); SortedMap<String, Long> sortedNodes = new TreeMap<>(collect); logger.info("Cluster shard mapping summary:"); for (Map.Entry<String, Long> entry : sortedNodes.entrySet()) { logger.info(format("\t%s has %d shards assigned", entry.getKey(), entry.getValue())); } // now we need to generate the events for the new local shards (if any) logger.info(format("Generating ACTOR_SHARD_INITIALIZED events for %d new shards", newLocalShards.size())); for (Integer newLocalShard : newLocalShards) { this.actorSystemEventListenerService.generateEvents(shardAdapters[newLocalShard], ACTOR_SHARD_INITIALIZED); } }
From source file:org.apache.felix.webconsole.internal.compendium.ConfigManager.java
private void printOptionsForm(PrintWriter printWriter, SortedMap inputOptions, String formId, String submitMethod, String submitLabel) { SortedSet tempSet = new TreeSet(); for (Iterator entryIter = inputOptions.entrySet().iterator(); entryIter.hasNext();) { Entry tempEntry = (Entry) entryIter.next(); tempSet.add(tempEntry.getValue().toString() + Character.MAX_VALUE + tempEntry.getKey().toString()); }//from w w w . j ava2 s .c om printWriter.println( "<select class='select' name='pid' id='" + formId + "' onChange='" + submitMethod + "();'>"); for (Iterator treeIter = tempSet.iterator(); treeIter.hasNext();) { String nextEntry = (String) treeIter.next(); int specChar = nextEntry.indexOf(Character.MAX_VALUE); String partialEntry = nextEntry.substring(0, specChar); String entryKey = nextEntry.substring(specChar + STRING_FORWARD); printWriter.print("<option value='" + entryKey + "'>"); printWriter.print(partialEntry); printWriter.println("</option>"); } printWriter.println("</select>"); printWriter.println(" "); printWriter.println("<input class='submit' type='button' value='" + submitLabel + "' onClick='" + submitMethod + "();' />"); }
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//ww w . j ava2s . c om 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); }