List of usage examples for java.util SortedMap get
V get(Object key);
From source file:org.cloudata.core.client.TabletLocationCache.java
protected TabletInfo findFromCache(String tableName, TreeMap<Row.Key, TabletInfo> cache, Row.Key cacheRowKey, Row.Key dataRowKey) {//from w w w .j a va 2 s.co m cacheLock.obtainReadLock(); try { if (cache.containsKey(cacheRowKey)) { TabletInfo tabletInfo = cache.get(cacheRowKey); if (tabletInfo.belongRowRange(cacheRowKey)) { return tabletInfo; } else { return null; } } SortedMap<Row.Key, TabletInfo> tailMap = cache.tailMap(cacheRowKey); if (tailMap.isEmpty()) { return null; } Row.Key tailFirst = tailMap.firstKey(); TabletInfo tabletInfo = tailMap.get(tailFirst); if (tableName.equals(tabletInfo.getTableName()) && tabletInfo.belongRowRange(dataRowKey)) { return tabletInfo; } else { return null; } } finally { cacheLock.releaseReadLock(); } }
From source file:org.opencms.workplace.editors.CmsWorkplaceEditorManager.java
/** * Returns the default editor URI for the current resource type.<p> * // w w w . j a va2s. c om * @param context the request context * @param resourceType the current resource type * @param userAgent the user agent String that identifies the browser * @return a valid default editor URI for the resource type or null, if no editor matches */ protected String getDefaultEditorUri(CmsRequestContext context, String resourceType, String userAgent) { SortedMap filteredEditors = filterEditorsForResourceType(resourceType); while (filteredEditors.size() > 0) { // get the configuration with the lowest key value from the map Float key = (Float) filteredEditors.firstKey(); CmsWorkplaceEditorConfiguration conf = (CmsWorkplaceEditorConfiguration) filteredEditors.get(key); // match the found configuration with the current users browser if (conf.matchesBrowser(userAgent)) { return conf.getEditorUri(); } filteredEditors.remove(key); } if (context == null) { // this is just so that all parameters are used, signature should be identical to getEditorUri(...) return null; } // no valid default editor found return null; }
From source file:com.aurel.track.report.dashboard.StatusOverTimeGraph.java
/** * Increment the value in the corresponding map * @param yearToPeriodToEntityIDToEntityCountMap * @param year/* ww w .j av a2s .c om*/ * @param period * @param entityID */ private static void setCount( SortedMap<Integer, SortedMap<Integer, Map<Integer, Integer>>> yearToPeriodToEntityIDToEntityCountMap, Integer year, Integer period, Integer entityID, int value) { if (yearToPeriodToEntityIDToEntityCountMap == null || year == null || period == null || entityID == null) { return; } SortedMap<Integer, Map<Integer, Integer>> periodToEntityIDToWorkItemNumbersMap = yearToPeriodToEntityIDToEntityCountMap .get(year); if (periodToEntityIDToWorkItemNumbersMap == null) { yearToPeriodToEntityIDToEntityCountMap.put(year, new TreeMap()); periodToEntityIDToWorkItemNumbersMap = yearToPeriodToEntityIDToEntityCountMap.get(year); } Map<Integer, Integer> entityIDToWorkItemNumbersMap = periodToEntityIDToWorkItemNumbersMap.get(period); if (entityIDToWorkItemNumbersMap == null) { periodToEntityIDToWorkItemNumbersMap.put(period, new HashMap()); entityIDToWorkItemNumbersMap = periodToEntityIDToWorkItemNumbersMap.get(period); } Integer previousValue = entityIDToWorkItemNumbersMap.get(entityID); if (previousValue == null) { entityIDToWorkItemNumbersMap.put(entityID, new Integer(value)); } else { entityIDToWorkItemNumbersMap.put(entityID, new Integer(previousValue.intValue() + value)); } }
From source file:org.libreplan.web.common.components.finders.OrdersMultipleFiltersFinder.java
private List<FilterPair> fillWithFirstTenFiltersCriterions() { SortedMap<CriterionType, List<Criterion>> mapCriterions = getMapCriterions(); Iterator<CriterionType> iteratorCriterionType = mapCriterions.keySet().iterator(); while (iteratorCriterionType.hasNext() && getListMatching().size() < 10) { CriterionType type = iteratorCriterionType.next(); for (int i = 0; getListMatching().size() < 10 && i < mapCriterions.get(type).size(); i++) { Criterion criterion = mapCriterions.get(type).get(i); addCriterion(type, criterion); }//from w ww. ja v a 2 s . c o m } return getListMatching(); }
From source file:org.alfresco.extension.bulkimport.source.fs.DirectoryAnalyser.java
private void categoriseFile(final Map<String, SortedMap<BigDecimal, Pair<File, File>>> categorisedFiles, final File file) { if (file != null) { if (file.canRead()) { final String fileName = file.getName(); final String parentName = getParentName(metadataLoader, fileName); final boolean isMetadata = isMetadataFile(metadataLoader, fileName); final BigDecimal versionNumber = getVersionNumber(fileName); SortedMap<BigDecimal, Pair<File, File>> versions = categorisedFiles.get(parentName); // Find the item if (versions == null) { versions = new TreeMap<>(); categorisedFiles.put(parentName, versions); }//from w ww.j av a 2s. c o m // Find the version within the item Pair<File, File> version = versions.get(versionNumber); if (version == null) { version = new Pair<>(null, null); } // Categorise the incoming file in that version of the item if (isMetadata) { version = new Pair<>(version.getFirst(), file); } else { version = new Pair<>(file, version.getSecond()); } versions.put(versionNumber, version); if (file.isDirectory()) { importStatus.incrementSourceCounter(COUNTER_NAME_DIRECTORIES_SCANNED); } else { importStatus.incrementSourceCounter(COUNTER_NAME_FILES_SCANNED); } } else { if (warn(log)) warn(log, "Skipping '" + getFileName(file) + "' as Alfresco does not have permission to read it."); importStatus.incrementSourceCounter(COUNTER_NAME_UNREADABLE_ENTRIES); } } }
From source file:org.codehaus.plexus.archiver.jar.JarArchiver.java
/** * try to guess the name of the given file. * <p/>/* w w w . jav a 2 s . c om*/ * <p>If this jar has a classpath attribute in its manifest, we * can assume that it will only require an index of jars listed * there. try to find which classpath entry is most likely the * one the given file name points to.</p> * <p/> * <p>In the absence of a classpath attribute, assume the other * files will be placed inside the same directory as this jar and * use their basename.</p> * <p/> * <p>if there is a classpath and the given file doesn't match any * of its entries, return null.</p> * * @param fileName . * @param classpath . * @return The guessed name */ protected static String findJarName(String fileName, String[] classpath) { if (classpath == null) { return new File(fileName).getName(); } fileName = fileName.replace(File.separatorChar, '/'); SortedMap<String, String> matches = new TreeMap<String, String>(new Comparator<String>() { // longest match comes first public int compare(String o1, String o2) { if ((o1 != null) && (o2 != null)) { return o2.length() - o1.length(); } return 0; } }); for (String aClasspath : classpath) { if (fileName.endsWith(aClasspath)) { matches.put(aClasspath, aClasspath); } else { int slash = aClasspath.indexOf("/"); String candidate = aClasspath; while (slash > -1) { candidate = candidate.substring(slash + 1); if (fileName.endsWith(candidate)) { matches.put(candidate, aClasspath); break; } slash = candidate.indexOf("/"); } } } return matches.size() == 0 ? null : matches.get(matches.firstKey()); }
From source file:br.eti.ranieri.opcoesweb.importacao.offline.ImportadorOffline.java
private void calcularBlackScholes(List<CotacaoBDI> cotacoes, ConfiguracaoImportacao configuracaoImportacao) throws Exception { if (cotacoes == null) return;//from www .ja v a 2 s . c o m // Organiza as cotacoes por data e acao. As cotacoes da // acao e das opcoes ficam, por enquanto, na mesma lista SortedMap<LocalDate, Map<Acao, List<CotacaoBDI>>> diaAcaoOpcoes = new TreeMap<LocalDate, Map<Acao, List<CotacaoBDI>>>(); for (CotacaoBDI cotacao : cotacoes) { LocalDate data = cotacao.getDataPregao(); Map<Acao, List<CotacaoBDI>> cotacoesPorAcao = new HashMap<Acao, List<CotacaoBDI>>(); if (diaAcaoOpcoes.containsKey(data)) { cotacoesPorAcao = diaAcaoOpcoes.get(data); } else { diaAcaoOpcoes.put(data, cotacoesPorAcao); } Acao acao = null; if (cotacao.getCodigoNegociacao().startsWith("PETR")) { acao = Acao.PETROBRAS; } else if (cotacao.getCodigoNegociacao().startsWith("VALE")) { acao = Acao.VALE; } else { log.error("Codigo de negociacao [{}] nao esta " + "vinculada a VALE e nem a PETROBRAS.", cotacao.getCodigoNegociacao()); continue; } List<CotacaoBDI> cotacoesAcaoOpcoes = new ArrayList<CotacaoBDI>(); if (cotacoesPorAcao.containsKey(acao)) { cotacoesAcaoOpcoes = cotacoesPorAcao.get(acao); } else { cotacoesPorAcao.put(acao, cotacoesAcaoOpcoes); } cotacoesAcaoOpcoes.add(cotacao); } // Agora separa, para cada dia e para cada acao, as // cotacoes da acao, das opcoes que vencem este mes // e das opcoes que vencem no proximo mes. // // Para cada dia e para cada acao, calcula o Black&Scholes // em cada dupla acao e lista de opcoes for (LocalDate data : diaAcaoOpcoes.keySet()) { Serie serieAtualOpcoes = Serie.getSerieAtualPorData(data); Serie proximaSerieOpcoes = Serie.getProximaSeriePorData(data); Double selic = taxaSelic.getSelic(data); for (Acao acao : diaAcaoOpcoes.get(data).keySet()) { CotacaoBDI cotacaoAcao = null; List<CotacaoBDI> cotacoesOpcoesSerie1 = new ArrayList<CotacaoBDI>(); List<CotacaoBDI> cotacoesOpcoesSerie2 = new ArrayList<CotacaoBDI>(); for (CotacaoBDI cotacao : diaAcaoOpcoes.get(data).get(acao)) { if (CodigoBDI.LOTE_PADRAO.equals(cotacao.getCodigoBdi()) && TipoMercadoBDI.MERCADO_A_VISTA.equals(cotacao.getTipoMercado())) { if (cotacaoAcao != null) log.error("Sobrescreveu cotacao [{}] com [{}].", cotacaoAcao, cotacao); cotacaoAcao = cotacao; } else if (CodigoBDI.OPCOES_DE_COMPRA.equals(cotacao.getCodigoBdi()) && TipoMercadoBDI.OPCOES_DE_COMPRA.equals(cotacao.getTipoMercado())) { if (serieAtualOpcoes.isSerieDaOpcao(cotacao.getCodigoNegociacao())) { cotacoesOpcoesSerie1.add(cotacao); } else if (proximaSerieOpcoes.isSerieDaOpcao(cotacao.getCodigoNegociacao())) { cotacoesOpcoesSerie2.add(cotacao); } } } if (cotacaoAcao == null) { log.error("Nao foi encontrada cotacao de " + "acao [{}] no dia [{}].", acao.getCodigo(), data); continue; } if (cotacoesOpcoesSerie1.size() == 0) { log.error("Nao foram encontradas cotacoes de opcoes " + "de [{}] no dia [{}] para vencer neste mes.", acao.getCodigo(), data); continue; } if (cotacoesOpcoesSerie2.size() == 0) { log.error("Nao foram encontradas cotacoes de opcoes " + "de [{}] no dia [{}] para vencer proximo mes.", acao.getCodigo(), data); continue; } CotacaoBDI opcaoTeorica1 = new CotacaoBDI(data, // CodigoBDI.OPCOES_DE_COMPRA, // TipoMercadoBDI.OPCOES_DE_COMPRA, // "Teorica", 0, 0, 0, // cotacaoAcao.getFechamento(), // cotacoesOpcoesSerie1.iterator().next().getDataVencimento()); CotacaoBDI opcaoTeorica2 = new CotacaoBDI(data, // CodigoBDI.OPCOES_DE_COMPRA, // TipoMercadoBDI.OPCOES_DE_COMPRA, // "Teorica", 0, 0, 0, // cotacaoAcao.getFechamento(), // cotacoesOpcoesSerie2.iterator().next().getDataVencimento()); Integer opcoesPorDia = configuracaoImportacao.getQuantidadeOpcoesPorAcaoPorDia(); CotacaoAcaoOpcoes cotacao = blackScholes.calcularIndices(cotacaoAcao, serieAtualOpcoes, cotacoesOpcoesSerie1, opcaoTeorica1, proximaSerieOpcoes, cotacoesOpcoesSerie2, opcaoTeorica2, opcoesPorDia, selic); persistencia.incluirCotacaoHistorica(data, acao, cotacao); } } }
From source file:co.rsk.peg.BridgeStorageProviderTest.java
@Test public void createSaveAndRecreateInstanceWithTxsWaitingForConfirmations() throws IOException { BtcTransaction tx1 = createTransaction(); BtcTransaction tx2 = createTransaction(); BtcTransaction tx3 = createTransaction(); Sha3Hash hash1 = PegTestUtils.createHash3(); Sha3Hash hash2 = PegTestUtils.createHash3(); Sha3Hash hash3 = PegTestUtils.createHash3(); Repository repository = new RepositoryImpl(); Repository track = repository.startTracking(); BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR); provider0.getRskTxsWaitingForConfirmations().put(hash1, tx1); provider0.getRskTxsWaitingForConfirmations().put(hash2, tx2); provider0.getRskTxsWaitingForConfirmations().put(hash3, tx3); provider0.save();//from w w w. ja v a 2 s . co m track.commit(); track = repository.startTracking(); BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR); SortedMap<Sha3Hash, BtcTransaction> confirmations = provider.getRskTxsWaitingForConfirmations(); Assert.assertNotNull(confirmations); Assert.assertTrue(confirmations.containsKey(hash1)); Assert.assertTrue(confirmations.containsKey(hash2)); Assert.assertTrue(confirmations.containsKey(hash3)); Assert.assertEquals(tx1.getHash(), confirmations.get(hash1).getHash()); Assert.assertEquals(tx2.getHash(), confirmations.get(hash2).getHash()); Assert.assertEquals(tx3.getHash(), confirmations.get(hash3).getHash()); }
From source file:org.codehaus.mojo.license.LicenseMap.java
public SortedMap<MavenProject, String[]> toDependencyMap() { SortedMap<MavenProject, Set<String>> tmp = new TreeMap<MavenProject, Set<String>>( ArtifactHelper.getProjectComparator()); for (Map.Entry<String, SortedSet<MavenProject>> entry : entrySet()) { String license = entry.getKey(); SortedSet<MavenProject> set = entry.getValue(); for (MavenProject p : set) { Set<String> list = tmp.get(p); if (list == null) { list = new HashSet<String>(); tmp.put(p, list);/*from ww w. ja va 2 s . c o m*/ } list.add(license); } } SortedMap<MavenProject, String[]> result = new TreeMap<MavenProject, String[]>( ArtifactHelper.getProjectComparator()); for (Map.Entry<MavenProject, Set<String>> entry : tmp.entrySet()) { List<String> value = new ArrayList<String>(entry.getValue()); Collections.sort(value); result.put(entry.getKey(), value.toArray(new String[value.size()])); } tmp.clear(); return result; }
From source file:co.rsk.peg.BridgeStorageProviderTest.java
@Test public void createSaveAndRecreateInstanceWithTxsWaitingForBroadcasting() throws IOException { BtcTransaction tx1 = createTransaction(); BtcTransaction tx2 = createTransaction(); BtcTransaction tx3 = createTransaction(); Sha3Hash hash1 = PegTestUtils.createHash3(); Sha3Hash hash2 = PegTestUtils.createHash3(); Sha3Hash hash3 = PegTestUtils.createHash3(); Repository repository = new RepositoryImpl(); Repository track = repository.startTracking(); BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR); provider0.getRskTxsWaitingForBroadcasting().put(hash1, Pair.of(tx1, new Long(1))); provider0.getRskTxsWaitingForBroadcasting().put(hash2, Pair.of(tx2, new Long(2))); provider0.getRskTxsWaitingForBroadcasting().put(hash3, Pair.of(tx3, new Long(3))); provider0.save();/*from w w w. ja va 2 s.c o m*/ track.commit(); track = repository.startTracking(); BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR); SortedMap<Sha3Hash, Pair<BtcTransaction, Long>> broadcasting = provider.getRskTxsWaitingForBroadcasting(); Assert.assertNotNull(broadcasting); Assert.assertTrue(broadcasting.containsKey(hash1)); Assert.assertTrue(broadcasting.containsKey(hash2)); Assert.assertTrue(broadcasting.containsKey(hash3)); Assert.assertEquals(tx1.getHash(), broadcasting.get(hash1).getLeft().getHash()); Assert.assertEquals(tx2.getHash(), broadcasting.get(hash2).getLeft().getHash()); Assert.assertEquals(tx3.getHash(), broadcasting.get(hash3).getLeft().getHash()); Assert.assertEquals(1, broadcasting.get(hash1).getRight().intValue()); Assert.assertEquals(2, broadcasting.get(hash2).getRight().intValue()); Assert.assertEquals(3, broadcasting.get(hash3).getRight().intValue()); }