List of usage examples for java.util SortedMap keySet
Set<K> keySet();
From source file:org.jahia.services.render.scripting.bundle.BundleScriptResolver.java
/** * Returns view scripts for the specified module bundle which match the specified path. * * @param module the module bundle to perform lookup in * @param pathPrefix the resource path prefix to match * @return a set of matching view scripts ordered by the extension (script type) *///w w w . j a va2s. c o m private Set<ViewResourceInfo> findBundleScripts(String module, String pathPrefix) { final SortedMap<String, ViewResourceInfo> allBundleScripts = availableScripts.get(module); if (allBundleScripts == null || allBundleScripts.isEmpty()) { return Collections.emptySet(); } // get all the ViewResourceInfos which path is greater than or equal to the given prefix final SortedMap<String, ViewResourceInfo> viewInfosWithPathGTEThanPrefix = allBundleScripts .tailMap(pathPrefix); // if the tail map is empty, we won't find the path prefix in the available scripts so return an empty set if (viewInfosWithPathGTEThanPrefix.isEmpty()) { return Collections.emptySet(); } // check if the first key contains the prefix. If not, the prefix will not match any entries so return an empty set if (!viewInfosWithPathGTEThanPrefix.firstKey().startsWith(pathPrefix)) { return Collections.emptySet(); } else { SortedSet<ViewResourceInfo> sortedScripts = new TreeSet<ViewResourceInfo>(scriptExtensionComparator); for (String path : viewInfosWithPathGTEThanPrefix.keySet()) { // we should have only few values to look at if (path.startsWith(pathPrefix)) { sortedScripts.add(viewInfosWithPathGTEThanPrefix.get(path)); } else { // as soon as the path doesn't start with the given prefix anymore, we won't have a match in the remaining so return return sortedScripts; } } return sortedScripts; } }
From source file:com.streamsets.pipeline.lib.jdbc.JdbcMultiRowRecordWriter.java
@SuppressWarnings("unchecked") private void processPartition(Connection connection, Multimap<Long, Record> partitions, Long partitionKey, List<OnRecordErrorException> errorRecords) throws SQLException, OnRecordErrorException { Collection<Record> partition = partitions.get(partitionKey); // Fetch the base insert query for this partition. SortedMap<String, String> columnsToParameters = getFilteredColumnsToParameters(getColumnsToParameters(), partition.iterator().next()); // put all the records in a queue for consumption LinkedList<Record> queue = new LinkedList<>(partition); // compute number of rows per batch if (columnsToParameters.isEmpty()) { throw new OnRecordErrorException(Errors.JDBCDEST_22); }/*from ww w. j a v a2 s.c o m*/ int maxRowsPerBatch = maxPrepStmtParameters / columnsToParameters.size(); PreparedStatement statement = null; // parameters are indexed starting with 1 int paramIdx = 1; int rowCount = 0; while (!queue.isEmpty()) { // we're at the start of a batch. if (statement == null) { // instantiate the new statement statement = generatePreparedStatement(columnsToParameters, // the next batch will have either the max number of records, or however many are left. Math.min(maxRowsPerBatch, queue.size()), getTableName(), connection); } // process the next record into the current statement Record record = queue.removeFirst(); for (String column : columnsToParameters.keySet()) { Field field = record.get(getColumnsToFields().get(column)); Field.Type fieldType = field.getType(); Object value = field.getValue(); try { switch (fieldType) { case LIST: List<Object> unpackedList = unpackList((List<Field>) value); Array array = connection.createArrayOf(getSQLTypeName(fieldType), unpackedList.toArray()); statement.setArray(paramIdx, array); break; case DATE: case DATETIME: // Java Date types are not accepted by JDBC drivers, so we need to convert to java.sql.Date java.util.Date date = field.getValueAsDatetime(); statement.setObject(paramIdx, new java.sql.Date(date.getTime())); break; default: statement.setObject(paramIdx, value, getColumnType(column)); break; } } catch (SQLException e) { LOG.error(Errors.JDBCDEST_23.getMessage(), column, fieldType.toString(), e); throw new OnRecordErrorException(record, Errors.JDBCDEST_23, column, fieldType.toString()); } ++paramIdx; } rowCount++; // check if we've filled up the current batch if (rowCount == maxRowsPerBatch) { // time to execute the current batch statement.addBatch(); statement.executeBatch(); statement.close(); statement = null; // reset our counters rowCount = 0; paramIdx = 1; } } // check if there are any records left. this should occur whenever there isn't *exactly* maxRowsPerBatch records in // this partition. if (statement != null) { statement.addBatch(); statement.executeBatch(); statement.close(); } }
From source file:freemarker.ext.dump.DumpDirectiveTest.java
private void testObjectDump(String varName, Map<String, Object> dataModel, Map<String, Object> expectedDump) { Map<String, Object> dump = getDump(varName, dataModel); assertEquals(expectedDump, dump);/*w w w . ja va2 s .c om*/ // Test the sorting of the properties @SuppressWarnings("unchecked") Map<String, Object> expectedVarDump = (Map<String, Object>) expectedDump.get(varName); @SuppressWarnings("unchecked") Map<String, Object> expectedValueDump = (Map<String, Object>) expectedVarDump.get(Key.VALUE.toString()); @SuppressWarnings("unchecked") SortedMap<String, Object> expectedPropertyDump = (SortedMap<String, Object>) expectedValueDump .get(Key.PROPERTIES.toString()); List<String> expectedPropertyDumpKeys = new ArrayList<String>(expectedPropertyDump.keySet()); @SuppressWarnings("unchecked") Map<String, Object> actualVarDump = (Map<String, Object>) dump.get(varName); @SuppressWarnings("unchecked") Map<String, Object> actualValueDump = (Map<String, Object>) actualVarDump.get(Key.VALUE.toString()); @SuppressWarnings("unchecked") SortedMap<String, Object> actualPropertyDump = (SortedMap<String, Object>) actualValueDump .get(Key.PROPERTIES.toString()); List<String> actualPropertyDumpKeys = new ArrayList<String>(actualPropertyDump.keySet()); assertEquals(expectedPropertyDumpKeys, actualPropertyDumpKeys); }
From source file:org.kuali.coeus.common.budget.impl.calculator.BudgetCalculationServiceImpl.java
protected SortedMap<BudgetCategoryType, List<CostElement>> categorizeObjectCodesByCategory(Budget budget) { SortedMap<CostElement, List<ScaleTwoDecimal>> objectCodeTotals = budget.getObjectCodeTotals(); SortedMap<BudgetCategoryType, List<CostElement>> objectCodeListByBudgetCategoryType = new TreeMap<>(); for (CostElement objectCode : objectCodeTotals.keySet()) { objectCode.refreshReferenceObject("budgetCategory"); if (objectCode.getBudgetCategory() != null) { objectCode.getBudgetCategory().refreshReferenceObject("budgetCategoryType"); objectCode.setBudgetCategoryTypeCode(objectCode.getBudgetCategory().getBudgetCategoryTypeCode()); }/* w ww . jav a2s . co m*/ if (!objectCodeListByBudgetCategoryType .containsKey(objectCode.getBudgetCategory().getBudgetCategoryType())) { List<CostElement> filteredObjectCodes = filterObjectCodesByBudgetCategoryType( objectCodeTotals.keySet(), objectCode.getBudgetCategoryTypeCode()); objectCodeListByBudgetCategoryType.put(objectCode.getBudgetCategory().getBudgetCategoryType(), filteredObjectCodes); } } return objectCodeListByBudgetCategoryType; }
From source file:com.alkacon.opencms.counter.CmsCounterDialog.java
/** * This function compares the list from the dialog with the list from the database and * update the list from the database with the values from the dialog.<p> * /*from w w w .j a v a 2 s . co m*/ * @param counterList the list from the dialog * * @throws Exception if an Exception occurred. */ private void updateCounterValues(SortedMap counterList) throws Exception { if (m_manager == null) { m_manager = getCounterManager(); } // get the counters from the database TreeMap map = m_manager.getCounters(); Iterator iteratork = map.keySet().iterator(); Iterator iterator = map.values().iterator(); // for each entry check if its changed or deleted int o_value; int new_value; String o_key; while (iterator.hasNext() && iteratork.hasNext()) { o_value = getIntValue(iterator.next()); o_key = (String) iteratork.next(); if (counterList.containsKey(o_key)) { // the value exits new_value = getIntValue(counterList.get(o_key)); if (o_value != new_value) { if ((o_value < new_value) || (o_value > new_value && m_overwrite)) { m_manager.setCounter(o_key, new_value); } counterList.remove(o_key); } else { counterList.remove(o_key); } } else { // the value is deleted m_manager.deleteCounter(o_key); } } // now the new values is adding to the database if (!counterList.isEmpty()) { iteratork = counterList.keySet().iterator(); iterator = counterList.values().iterator(); while (iterator.hasNext() && iteratork.hasNext()) { o_value = getIntValue(iterator.next()); o_key = (String) iteratork.next(); m_manager.setCounter(o_key, o_value); } } }
From source file:org.omnaest.utils.table.TableTest.java
@Test public void testToMap() throws Exception { Table<String> table = this.filledTable(3, 4); {//w w w . jav a2s. co m final SortedMap<String, String[]> sortedMap = table.to().sortedMap(1); assertNotNull(sortedMap); assertEquals(3, sortedMap.size()); assertEquals(Arrays.asList("0:1", "1:1", "2:1"), ListUtils.valueOf(sortedMap.keySet())); assertArrayEquals(new String[] { "1:0", "1:1", "1:2", "1:3" }, sortedMap.get("1:1")); } { final SortedMap<String, String> sortedMap = table.to().sortedMap(1, 3); assertNotNull(sortedMap); assertEquals(3, sortedMap.size()); assertEquals(Arrays.asList("0:1", "1:1", "2:1"), ListUtils.valueOf(sortedMap.keySet())); assertEquals("1:3", sortedMap.get("1:1")); } }
From source file:org.archive.crawler.frontier.WorkQueueFrontier.java
/** * This method compiles a human readable report on the status of the frontier * at the time of the call.//from www .java 2s .c om * @param name Name of report. * @param writer Where to write to. */ @Override public synchronized void reportTo(PrintWriter writer) { int allCount = allQueues.size(); int inProcessCount = inProcessQueues.size(); int readyCount = readyClassQueues.size(); int snoozedCount = getSnoozedCount(); int activeCount = inProcessCount + readyCount + snoozedCount; int inactiveCount = getTotalInactiveQueues(); int retiredCount = getRetiredQueues().size(); int exhaustedCount = allCount - activeCount - inactiveCount - retiredCount; writer.print("Frontier report - "); writer.print(ArchiveUtils.get12DigitDate()); writer.print("\n"); writer.print(" Job being crawled: "); writer.print(controller.getMetadata().getJobName()); writer.print("\n"); writer.print("\n -----===== STATS =====-----\n"); writer.print(" Discovered: "); writer.print(Long.toString(discoveredUriCount())); writer.print("\n"); writer.print(" Queued: "); writer.print(Long.toString(queuedUriCount())); writer.print("\n"); writer.print(" Finished: "); writer.print(Long.toString(finishedUriCount())); writer.print("\n"); writer.print(" Successfully: "); writer.print(Long.toString(succeededFetchCount())); writer.print("\n"); writer.print(" Failed: "); writer.print(Long.toString(failedFetchCount())); writer.print("\n"); writer.print(" Disregarded: "); writer.print(Long.toString(disregardedUriCount())); writer.print("\n"); writer.print("\n -----===== QUEUES =====-----\n"); writer.print(" Already included size: "); writer.print(Long.toString(uriUniqFilter.count())); writer.print("\n"); writer.print(" pending: "); writer.print(Long.toString(uriUniqFilter.pending())); writer.print("\n"); writer.print("\n All class queues map size: "); writer.print(Long.toString(allCount)); writer.print("\n"); writer.print(" Active queues: "); writer.print(activeCount); writer.print("\n"); writer.print(" In-process: "); writer.print(inProcessCount); writer.print("\n"); writer.print(" Ready: "); writer.print(readyCount); writer.print("\n"); writer.print(" Snoozed: "); writer.print(snoozedCount); writer.print("\n"); writer.print(" Inactive queues: "); writer.print(inactiveCount); writer.print(" ("); Map<Integer, Queue<String>> inactives = getInactiveQueuesByPrecedence(); boolean betwixt = false; for (Integer k : inactives.keySet()) { if (betwixt) { writer.print("; "); } writer.print("p"); writer.print(k); writer.print(": "); writer.print(inactives.get(k).size()); betwixt = true; } writer.print(")\n"); writer.print(" Retired queues: "); writer.print(retiredCount); writer.print("\n"); writer.print(" Exhausted queues: "); writer.print(exhaustedCount); writer.print("\n"); State last = lastReachedState; writer.print("\n Last state: " + last); writer.print("\n -----===== MANAGER THREAD =====-----\n"); ToeThread.reportThread(managerThread, writer); writer.print("\n -----===== " + largestQueues.size() + " LONGEST QUEUES =====-----\n"); appendQueueReports(writer, "LONGEST", largestQueues.getEntriesDescending().iterator(), largestQueues.size(), largestQueues.size()); writer.print("\n -----===== IN-PROCESS QUEUES =====-----\n"); Collection<WorkQueue> inProcess = inProcessQueues; ArrayList<WorkQueue> copy = extractSome(inProcess, maxQueuesPerReportCategory); appendQueueReports(writer, "IN-PROCESS", copy.iterator(), copy.size(), maxQueuesPerReportCategory); writer.print("\n -----===== READY QUEUES =====-----\n"); appendQueueReports(writer, "READY", this.readyClassQueues.iterator(), this.readyClassQueues.size(), maxQueuesPerReportCategory); writer.print("\n -----===== SNOOZED QUEUES =====-----\n"); Object[] objs = snoozedClassQueues.toArray(); DelayedWorkQueue[] qs = Arrays.copyOf(objs, objs.length, DelayedWorkQueue[].class); Arrays.sort(qs); appendQueueReports(writer, "SNOOZED", new ObjectArrayIterator(qs), getSnoozedCount(), maxQueuesPerReportCategory); writer.print("\n -----===== INACTIVE QUEUES =====-----\n"); SortedMap<Integer, Queue<String>> sortedInactives = getInactiveQueuesByPrecedence(); for (Integer prec : sortedInactives.keySet()) { Queue<String> inactiveQueues = sortedInactives.get(prec); appendQueueReports(writer, "INACTIVE-p" + prec, inactiveQueues.iterator(), inactiveQueues.size(), maxQueuesPerReportCategory); } writer.print("\n -----===== RETIRED QUEUES =====-----\n"); appendQueueReports(writer, "RETIRED", getRetiredQueues().iterator(), getRetiredQueues().size(), maxQueuesPerReportCategory); writer.flush(); }
From source file:com.palantir.atlasdb.transaction.impl.SnapshotTransaction.java
protected <T> ClosableIterator<RowResult<T>> postFilterIterator(final String tableName, RangeRequest range, int preFilterBatchSize, final Function<Value, T> transformer) { final BatchSizeIncreasingRangeIterator results = new BatchSizeIncreasingRangeIterator(tableName, range, preFilterBatchSize);//from w w w.j a v a 2s .com Iterator<Iterator<RowResult<T>>> batchedPostfiltered = new AbstractIterator<Iterator<RowResult<T>>>() { @Override protected Iterator<RowResult<T>> computeNext() { List<RowResult<Value>> batch = results.getBatch(); if (batch.isEmpty()) { return endOfData(); } SortedMap<Cell, T> postFilter = postFilterRows(tableName, batch, transformer); results.markNumRowsNotDeleted(Cells.getRows(postFilter.keySet()).size()); return Cells.createRowView(postFilter.entrySet()); } }; final Iterator<RowResult<T>> rows = Iterators.concat(batchedPostfiltered); return new ForwardingClosableIterator<RowResult<T>>() { @Override protected ClosableIterator<RowResult<T>> delegate() { return ClosableIterators.wrap(rows); } @Override public void close() { if (results != null) { results.close(); } } }; }
From source file:org.apache.ctakes.ytex.kernel.metric.ConceptSimilarityServiceImpl.java
/** * load cui-tui for the specified corpus from the MRSTY table *//*ww w . java2 s . c om*/ public void initCuiTuiMapFromCorpus() { // don't duplicate tui strings to save memory SortedMap<String, String> tuiMap = new TreeMap<String, String>(); Map<String, Set<String>> tmpTuiCuiMap = new HashMap<String, Set<String>>(); List<Object[]> listCuiTui = this.classifierEvaluationDao.getCorpusCuiTuis(this.getCorpusName(), this.getConceptGraphName(), this.getConceptSetName()); for (Object[] cuiTui : listCuiTui) { String cui = (String) cuiTui[0]; String tui = (String) cuiTui[1]; addCuiTuiToMap(tmpTuiCuiMap, tuiMap, cui, tui); } // map of tui - bitset index SortedMap<String, Integer> mapTuiIndex = new TreeMap<String, Integer>(); // list of tuis corresponding to bitset indices List<String> tmpTuiList = new ArrayList<String>(tuiMap.size()); int index = 0; for (String tui : tuiMap.keySet()) { mapTuiIndex.put(tui, index++); tmpTuiList.add(tui); } this.tuiList = Collections.unmodifiableList(tmpTuiList); // convert list of cuis into bitsets // Map<String, BitSet> tmpCuiTuiBitsetMap = new HashMap<String, // BitSet>(); ImmutableMap.Builder<String, BitSet> cuiTuiBitsetMapBuilder = new ImmutableMap.Builder<String, BitSet>(); for (Map.Entry<String, Set<String>> cuiTuiMapEntry : tmpTuiCuiMap.entrySet()) { // tmpCuiTuiBitsetMap.put(cuiTuiMapEntry.getKey(), // tuiListToBitset(cuiTuiMapEntry.getValue(), mapTuiIndex)); cuiTuiBitsetMapBuilder.put(cuiTuiMapEntry.getKey(), tuiListToBitset(cuiTuiMapEntry.getValue(), mapTuiIndex)); } // this.cuiTuiMap = Collections.unmodifiableMap(tmpCuiTuiBitsetMap); this.cuiTuiMap = cuiTuiBitsetMapBuilder.build(); }
From source file:org.apache.atlas.hive.hook.HiveHook.java
private void handleExternalTables(final HiveMetaStoreBridge dgiBridge, final HiveEventContext event, final LinkedHashMap<Type, Referenceable> tables) throws HiveException, MalformedURLException { List<Referenceable> entities = new ArrayList<>(); final WriteEntity hiveEntity = (WriteEntity) getEntityByType(event.getOutputs(), Type.TABLE); Table hiveTable = hiveEntity == null ? null : hiveEntity.getTable(); //Refresh to get the correct location if (hiveTable != null) { hiveTable = dgiBridge.hiveClient.getTable(hiveTable.getDbName(), hiveTable.getTableName()); }/*from w ww. ja va2s.co m*/ if (hiveTable != null && TableType.EXTERNAL_TABLE.equals(hiveTable.getTableType())) { LOG.info("Registering external table process {} ", event.getQueryStr()); final String location = lower(hiveTable.getDataLocation().toString()); final ReadEntity dfsEntity = new ReadEntity(); dfsEntity.setTyp(Type.DFS_DIR); dfsEntity.setD(new Path(location)); SortedMap<ReadEntity, Referenceable> hiveInputsMap = new TreeMap<ReadEntity, Referenceable>( entityComparator) { { put(dfsEntity, dgiBridge.fillHDFSDataSet(location)); } }; SortedMap<WriteEntity, Referenceable> hiveOutputsMap = new TreeMap<WriteEntity, Referenceable>( entityComparator) { { put(hiveEntity, tables.get(Type.TABLE)); } }; SortedSet<ReadEntity> sortedIps = new TreeSet<>(entityComparator); sortedIps.addAll(hiveInputsMap.keySet()); SortedSet<WriteEntity> sortedOps = new TreeSet<>(entityComparator); sortedOps.addAll(hiveOutputsMap.keySet()); Referenceable processReferenceable = getProcessReferenceable(dgiBridge, event, sortedIps, sortedOps, hiveInputsMap, hiveOutputsMap); entities.addAll(tables.values()); entities.add(processReferenceable); event.addMessage(new HookNotification.EntityUpdateRequest(event.getUser(), entities)); } }