List of usage examples for java.util TreeMap keySet
public Set<K> keySet()
From source file:web.diva.server.model.PCAGenerator.java
/** * * * @return dataset.// w w w.j a v a 2s. com */ private XYDataset createDataset(TreeMap<Integer, PCAPoint> points, int[] subSelectionData, int[] selection, boolean zoom, DivaDataset divaDataset) { final XYSeriesCollection dataset = new XYSeriesCollection(); seriesList = new TreeMap<String, XYSeries>(); seriesList.put("#000000", new XYSeries("#000000")); seriesList.put("unGrouped", new XYSeries("LIGHT_GRAY")); for (Group g : divaDataset.getRowGroups()) { if (g.isActive() && !g.getName().equalsIgnoreCase("all")) { seriesList.put(g.getHashColor(), new XYSeries(g.getHashColor())); } } if (!zoom && (selection == null || selection.length == 0) && subSelectionData == null) { for (int key : points.keySet()) { PCAPoint point = points.get(key); if (seriesList.containsKey(point.getColor())) { seriesList.get(divaDataset.getGeneColorArr()[point.getGeneIndex()]).add(point.getX(), point.getY()); } else { seriesList.get("unGrouped").add(point.getX(), point.getY()); } } } else if (zoom) { selectionSet.clear(); for (int i : selection) { selectionSet.add(i); } for (int x : subSelectionData) { PCAPoint point = points.get(x); if (selectionSet.contains(point.getGeneIndex())) { if (seriesList.containsKey(point.getColor())) { seriesList.get(divaDataset.getGeneColorArr()[point.getGeneIndex()]).add(point.getX(), point.getY()); } else { seriesList.get("#000000").add(point.getX(), point.getY()); } } else { seriesList.get("unGrouped").add(point.getX(), point.getY()); } } } else if (subSelectionData != null) { selectionSet.clear(); for (int i : selection) { selectionSet.add(i); } for (int key : subSelectionData) { PCAPoint point = points.get(key); if (selectionSet.contains(point.getGeneIndex())) { if (seriesList.containsKey(divaDataset.getGeneColorArr()[point.getGeneIndex()])) { seriesList.get(divaDataset.getGeneColorArr()[point.getGeneIndex()]).add(point.getX(), point.getY()); } else { seriesList.get("#000000").add(point.getX(), point.getY()); } } else { seriesList.get("unGrouped").add(point.getX(), point.getY()); } } } else //selection without zoom { selectionSet.clear(); for (int i : selection) { selectionSet.add(i); } for (int key : points.keySet()) { PCAPoint point = points.get(key); if (selectionSet.contains(point.getGeneIndex())) { if (seriesList.containsKey(divaDataset.getGeneColorArr()[point.getGeneIndex()])) { seriesList.get(divaDataset.getGeneColorArr()[point.getGeneIndex()]).add(point.getX(), point.getY()); } else { seriesList.get("#000000").add(point.getX(), point.getY()); } } else { seriesList.get("unGrouped").add(point.getX(), point.getY()); } } } for (XYSeries ser : seriesList.values()) { dataset.addSeries(ser); } return dataset; }
From source file:org.opendatakit.database.data.ColumnDefinitionTest.java
@SuppressWarnings("unchecked") private void recursiveMatch(String parent, TreeMap<String, Object> value, Map<String, Object> xlsxValue) { for (String key : value.keySet()) { assertTrue("Investigating " + parent + "." + key, xlsxValue.containsKey(key)); Object ov = value.get(key); Object oxlsxv = xlsxValue.get(key); if (ov instanceof Map) { TreeMap<String, Object> rv = (TreeMap<String, Object>) ov; Map<String, Object> xlsrv = (Map<String, Object>) oxlsxv; List<String> ignoredKeys = new ArrayList<String>(); for (String rvkey : xlsrv.keySet()) { if (rvkey.startsWith("_")) { ignoredKeys.add(rvkey); }//from w w w . j ava 2 s . co m if (rvkey.equals("prompt_type_name")) { ignoredKeys.add(rvkey); } } for (String rvkey : ignoredKeys) { xlsrv.remove(rvkey); } assertEquals("Investigating " + parent + "." + key, rv.size(), xlsrv.size()); recursiveMatch(parent + "." + key, rv, xlsrv); } else { assertEquals("Investigating " + parent + "." + key, ov, oxlsxv); } } }
From source file:org.commoncrawl.service.listcrawler.CrawlHistoryManager.java
private static void syncAndValidateItems(TreeMap<URLFP, ProxyCrawlHistoryItem> items, CrawlHistoryManager logManager) throws IOException { // ok now sync the list final TreeMap<URLFP, ProxyCrawlHistoryItem> syncedItemList = new TreeMap<URLFP, ProxyCrawlHistoryItem>(); try {/*w w w . j a v a 2 s . c om*/ logManager.syncList(0L, Sets.newTreeSet(items.keySet()), new ItemUpdater() { @Override public void updateItemState(URLFP fingerprint, ProxyCrawlHistoryItem item) throws IOException { try { syncedItemList.put((URLFP) fingerprint.clone(), (ProxyCrawlHistoryItem) item.clone()); } catch (CloneNotSupportedException e) { e.printStackTrace(); } } }); } catch (IOException e) { LOG.error(CCStringUtils.stringifyException(e)); Assert.assertTrue(false); } // assert that the key set is equal Assert.assertEquals(items.keySet(), syncedItemList.keySet()); // ok now validate that the values are equal for (Map.Entry<URLFP, ProxyCrawlHistoryItem> item : items.entrySet()) { ProxyCrawlHistoryItem other = syncedItemList.get(item.getKey()); Assert.assertEquals(item.getValue(), other); } }
From source file:com.sfs.whichdoctor.analysis.GroupAnalysisDAOImpl.java
/** * Builds the order.//from w w w . j a va2 s.com * * @param referenceObjects the reference objects * @param groupClass the group class * * @return the tree map< string, integer> */ private TreeMap<String, Integer> buildOrder(final TreeMap<Integer, Object> referenceObjects, final String groupClass) { if (referenceObjects == null) { throw new NullPointerException("The reference objects map cannot be null"); } if (groupClass == null) { throw new NullPointerException("The group class string cannot be null"); } dataLogger.debug("Building order for " + groupClass + ", with a size of: " + referenceObjects.size()); TreeMap<String, Integer> orderMap = new TreeMap<String, Integer>(); for (Integer referenceGUID : referenceObjects.keySet()) { Object reference = referenceObjects.get(referenceGUID); String orderKey = GroupAnalysisBean.getOrderKey(reference, groupClass); orderMap.put(orderKey, referenceGUID); } return orderMap; }
From source file:org.kuali.ole.module.purap.document.web.struts.ReceivingBaseAction.java
/** * Builds and asks questions which require text input by the user for a payment request or a credit memo. * * @param mapping An ActionMapping * @param form An ActionForm * @param request The HttpServletRequest * @param response The HttpServletResponse * @param questionType A String used to distinguish which question is being asked * @param notePrefix A String explaining what action was taken, to be prepended to the note containing the reason, which gets * written to the document * @param operation A one-word String description of the action to be taken, to be substituted into the message. (Can be an * empty String for some messages.) * @param messageKey A (whole) key to the message which will appear on the question screen * @param questionsAndCallbacks A TreeMap associating the type of question to be asked and the type of callback which should * happen in that case * @param messagePrefix The most general part of a key to a message text to be retrieved from ConfigurationService, * Describes a collection of questions. * @param redirect An ActionForward to return to if done with questions * @return An ActionForward/* w w w . ja va 2s . c om*/ * @throws Exception */ protected ActionForward askQuestionWithInput(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String questionType, String notePrefix, String operation, String messageKey, TreeMap<String, ReceivingQuestionCallback> questionsAndCallbacks, String messagePrefix, ActionForward redirect) throws Exception { KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form; ReceivingDocument receivingDocument = (ReceivingDocument) kualiDocumentFormBase.getDocument(); String question = (String) request.getParameter(OLEConstants.QUESTION_INST_ATTRIBUTE_NAME); String reason = request.getParameter(OLEConstants.QUESTION_REASON_ATTRIBUTE_NAME); String noteText = ""; ConfigurationService kualiConfiguration = SpringContext.getBean(ConfigurationService.class); String firstQuestion = questionsAndCallbacks.firstKey(); ReceivingQuestionCallback callback = null; Iterator questions = questionsAndCallbacks.keySet().iterator(); String mapQuestion = null; String key = null; // Start in logic for confirming the close. if (question == null) { key = getQuestionProperty(messageKey, messagePrefix, kualiConfiguration, firstQuestion); String message = StringUtils.replace(key, "{0}", operation); // Ask question if not already asked. return this.performQuestionWithInput(mapping, form, request, response, firstQuestion, message, OLEConstants.CONFIRMATION_QUESTION, questionType, ""); } else { // find callback for this question while (questions.hasNext()) { mapQuestion = (String) questions.next(); if (StringUtils.equals(mapQuestion, question)) { callback = questionsAndCallbacks.get(mapQuestion); break; } } key = getQuestionProperty(messageKey, messagePrefix, kualiConfiguration, mapQuestion); Object buttonClicked = request.getParameter(OLEConstants.QUESTION_CLICKED_BUTTON); if (question.equals(mapQuestion) && buttonClicked.equals(ConfirmationQuestion.NO)) { // If 'No' is the button clicked, just reload the doc String nextQuestion = null; // ask another question if more left if (questions.hasNext()) { nextQuestion = (String) questions.next(); key = getQuestionProperty(messageKey, messagePrefix, kualiConfiguration, nextQuestion); return this.performQuestionWithInput(mapping, form, request, response, nextQuestion, key, OLEConstants.CONFIRMATION_QUESTION, questionType, ""); } else { return mapping.findForward(OLEConstants.MAPPING_BASIC); } } // Have to check length on value entered. String introNoteMessage = notePrefix + OLEConstants.BLANK_SPACE; // Build out full message. noteText = introNoteMessage + reason; int noteTextLength = noteText.length(); // Get note text max length from DD. int noteTextMaxLength = SpringContext.getBean(DataDictionaryService.class) .getAttributeMaxLength(Note.class, OLEConstants.NOTE_TEXT_PROPERTY_NAME).intValue(); if (StringUtils.isBlank(reason) || (noteTextLength > noteTextMaxLength)) { // Figure out exact number of characters that the user can enter. int reasonLimit = noteTextMaxLength - noteTextLength; if (reason == null) { // Prevent a NPE by setting the reason to a blank string. reason = ""; } return this.performQuestionWithInputAgainBecauseOfErrors(mapping, form, request, response, mapQuestion, key, OLEConstants.CONFIRMATION_QUESTION, questionType, "", reason, PurapKeyConstants.ERROR_PAYMENT_REQUEST_REASON_REQUIRED, OLEConstants.QUESTION_REASON_ATTRIBUTE_NAME, new Integer(reasonLimit).toString()); } } // make callback if (ObjectUtils.isNotNull(callback)) { ReceivingDocument refreshedReceivingDocument = callback.doPostQuestion(receivingDocument, noteText); kualiDocumentFormBase.setDocument(refreshedReceivingDocument); } String nextQuestion = null; // ask another question if more left if (questions.hasNext()) { nextQuestion = (String) questions.next(); key = getQuestionProperty(messageKey, messagePrefix, kualiConfiguration, nextQuestion); return this.performQuestionWithInput(mapping, form, request, response, nextQuestion, key, OLEConstants.CONFIRMATION_QUESTION, questionType, ""); } return redirect; }
From source file:com.bombardier.plugin.scheduling.TestScheduler.java
/** * Used to get a sub map from a whole map based on the closest number of * lines//from w ww .jav a 2s . c o m * * @param sortedByLines * the whole map * @param testLines * the number of lines * @return the sub map * @since 1.0 */ private SortedMap<Integer, Double> getSubMapForLines(TreeMap<Integer, Double> sortedByLines, int testLines) { SortedMap<Integer, Double> subMap = new TreeMap<Integer, Double>(); List<Integer> keyList = new ArrayList<Integer>(sortedByLines.keySet()); int closest = getClosestLineNum(keyList, testLines); List<List<Integer>> list = splitToFiveLists(keyList); for (List<Integer> subList : list) { if (subList.contains(closest)) { subMap = sortedByLines.subMap(subList.get(0), subList.get(subList.size() - 1)); break; } } return subMap; }
From source file:org.kuali.kfs.module.purap.document.web.struts.ReceivingBaseAction.java
/** * Builds and asks questions which require text input by the user for a payment request or a credit memo. * //from w w w . j a va2 s . co m * @param mapping An ActionMapping * @param form An ActionForm * @param request The HttpServletRequest * @param response The HttpServletResponse * @param questionType A String used to distinguish which question is being asked * @param notePrefix A String explaining what action was taken, to be prepended to the note containing the reason, which gets * written to the document * @param operation A one-word String description of the action to be taken, to be substituted into the message. (Can be an * empty String for some messages.) * @param messageKey A (whole) key to the message which will appear on the question screen * @param questionsAndCallbacks A TreeMap associating the type of question to be asked and the type of callback which should * happen in that case * @param messagePrefix The most general part of a key to a message text to be retrieved from ConfigurationService, * Describes a collection of questions. * @param redirect An ActionForward to return to if done with questions * @return An ActionForward * @throws Exception */ protected ActionForward askQuestionWithInput(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String questionType, String notePrefix, String operation, String messageKey, TreeMap<String, ReceivingQuestionCallback> questionsAndCallbacks, String messagePrefix, ActionForward redirect) throws Exception { KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form; ReceivingDocument receivingDocument = (ReceivingDocument) kualiDocumentFormBase.getDocument(); String question = (String) request.getParameter(KFSConstants.QUESTION_INST_ATTRIBUTE_NAME); String reason = request.getParameter(KFSConstants.QUESTION_REASON_ATTRIBUTE_NAME); String noteText = ""; ConfigurationService kualiConfiguration = SpringContext.getBean(ConfigurationService.class); String firstQuestion = questionsAndCallbacks.firstKey(); ReceivingQuestionCallback callback = null; Iterator questions = questionsAndCallbacks.keySet().iterator(); String mapQuestion = null; String key = null; // Start in logic for confirming the close. if (question == null) { key = getQuestionProperty(messageKey, messagePrefix, kualiConfiguration, firstQuestion); String message = StringUtils.replace(key, "{0}", operation); // Ask question if not already asked. return this.performQuestionWithInput(mapping, form, request, response, firstQuestion, message, KFSConstants.CONFIRMATION_QUESTION, questionType, ""); } else { // find callback for this question while (questions.hasNext()) { mapQuestion = (String) questions.next(); if (StringUtils.equals(mapQuestion, question)) { callback = questionsAndCallbacks.get(mapQuestion); break; } } key = getQuestionProperty(messageKey, messagePrefix, kualiConfiguration, mapQuestion); Object buttonClicked = request.getParameter(KFSConstants.QUESTION_CLICKED_BUTTON); if (question.equals(mapQuestion) && buttonClicked.equals(ConfirmationQuestion.NO)) { // If 'No' is the button clicked, just reload the doc String nextQuestion = null; // ask another question if more left if (questions.hasNext()) { nextQuestion = (String) questions.next(); key = getQuestionProperty(messageKey, messagePrefix, kualiConfiguration, nextQuestion); return this.performQuestionWithInput(mapping, form, request, response, nextQuestion, key, KFSConstants.CONFIRMATION_QUESTION, questionType, ""); } else { return mapping.findForward(KFSConstants.MAPPING_BASIC); } } // Have to check length on value entered. String introNoteMessage = notePrefix + KFSConstants.BLANK_SPACE; // Build out full message. noteText = introNoteMessage + reason; int noteTextLength = noteText.length(); // Get note text max length from DD. int noteTextMaxLength = SpringContext.getBean(DataDictionaryService.class) .getAttributeMaxLength(Note.class, KFSConstants.NOTE_TEXT_PROPERTY_NAME).intValue(); if (StringUtils.isBlank(reason) || (noteTextLength > noteTextMaxLength)) { // Figure out exact number of characters that the user can enter. int reasonLimit = noteTextMaxLength - noteTextLength; if (reason == null) { // Prevent a NPE by setting the reason to a blank string. reason = ""; } return this.performQuestionWithInputAgainBecauseOfErrors(mapping, form, request, response, mapQuestion, key, KFSConstants.CONFIRMATION_QUESTION, questionType, "", reason, PurapKeyConstants.ERROR_PAYMENT_REQUEST_REASON_REQUIRED, KFSConstants.QUESTION_REASON_ATTRIBUTE_NAME, new Integer(reasonLimit).toString()); } } // make callback if (ObjectUtils.isNotNull(callback)) { ReceivingDocument refreshedReceivingDocument = callback.doPostQuestion(receivingDocument, noteText); kualiDocumentFormBase.setDocument(refreshedReceivingDocument); } String nextQuestion = null; // ask another question if more left if (questions.hasNext()) { nextQuestion = (String) questions.next(); key = getQuestionProperty(messageKey, messagePrefix, kualiConfiguration, nextQuestion); return this.performQuestionWithInput(mapping, form, request, response, nextQuestion, key, KFSConstants.CONFIRMATION_QUESTION, questionType, ""); } return redirect; }
From source file:io.mapzone.arena.analytics.graph.ui.GraphPanel.java
@Override public void createContents(final Composite parent) { try {/*from ww w. j a v a2 s.c om*/ if (!featureLayer.isPresent()) { tk().createFlowText(parent, i18n.get("noFeatures")); return; } // this.parent = parent; parent.setLayout(FormLayoutFactory.defaults().create()); MdToolbar2 toolbar = tk().createToolbar(parent, SWT.TOP); new NodeStylerItem(toolbar); new EdgeStylerItem(toolbar); final TreeMap<String, GraphFunction> functions = Maps.newTreeMap(); for (Class<GraphFunction> cl : AVAILABLE_FUNCTIONS) { try { GraphFunction function = cl.newInstance(); functions.put(function.title(), function); } catch (Exception e) { throw new RuntimeException(e); } } final Composite functionContainer = tk().createComposite(parent, SWT.NONE); final ComboViewer combo = new ComboViewer(parent, SWT.SINGLE | SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY); combo.setContentProvider(new ArrayContentProvider()); combo.setInput(functions.keySet()); combo.addSelectionChangedListener(ev -> { String selected = SelectionAdapter.on(ev.getSelection()).first(String.class).get(); GraphFunction function = functions.get(selected); FormDataFactory.on(functionContainer).top(combo.getCombo(), 5).height(function.preferredHeight()) .left(0).right(100); UIUtils.disposeChildren(functionContainer); // create panel // Section section = tk().createSection( functionContainer, function.description(), ExpandableComposite.TREE_NODE, Section.SHORT_TITLE_BAR, Section.FOCUS_TITLE, SWT.BORDER ); // section.setBackground( UIUtils.getColor( 235, 235, 235) ); // ((Composite)section.getClient()).setLayout( FormLayoutFactory.defaults().create() ); IPanelSection section = tk().createPanelSection(functionContainer, function.description(), SWT.Expand, IPanelSection.EXPANDABLE); section.getControl().setBackground(UIUtils.getColor(235, 235, 235)); section.getBody().setBackground(UIUtils.getColor(235, 235, 235)); section.setExpanded(true); section.getBody().setLayout(FormLayoutFactory.defaults().create()); // graph.clear(); function.createContents(tk(), section.getBody(), graph); if (!section.isExpanded()) { section.setExpanded(true); } FormDataFactory.on(section.getBody()).fill(); // functionContainer.layout(); parent.layout(); }); // // mapContainer mapContainer = tk().createComposite(parent, SWT.NONE); mapContainer.setLayout(new FillLayout()); if (mapViewer != null) { mapViewer.dispose(); } createMapViewer(); // layout on(toolbar.getControl()).left(0, 3).right(100, -3).top(0, 5); final Label selectLabel = tk().createLabel(parent, i18n.get("selectFunction"), SWT.NONE); on(selectLabel).top(toolbar.getControl(), 8).left(1); on(combo.getCombo()).top(selectLabel, 2).left(1); on(functionContainer).top(combo.getCombo(), 5).height(0).left(0).right(100); on(mapContainer).fill().top(functionContainer, 5); } catch (Exception e) { StatusDispatcher.handleError("", e); } }
From source file:com.eucalyptus.tests.awssdk.S3ListMpuTests.java
@Test public void keyMarker() throws Exception { testInfo(this.getClass().getSimpleName() + " - keyMarker"); try {/* ww w. ja v a2 s . c o m*/ int numKeys = 3 + random.nextInt(3); // 3-5 keys int numUploads = 3 + random.nextInt(3); // 3-5 uploads print("Number of keys: " + numKeys); print("Number of uploads per key: " + numUploads); // Generate some mpus TreeMap<String, List<String>> keyUploadIdMap = initiateMpusForMultipleKeys(s3ClientA, accountA, numKeys, numUploads, new String()); // Starting with every key in the ascending order, list the mpus using that key as the key marker and verify that the results. for (String keyMarker : keyUploadIdMap.keySet()) { // Compute what the sorted mpus should look like NavigableMap<String, List<String>> tailMap = keyUploadIdMap.tailMap(keyMarker, false); // List mpus using the key marker and verify MultipartUploadListing listing = listMpu(s3ClientA, accountA, bucketName, keyMarker, null, null, null, null, false); assertTrue( "Expected " + (tailMap.size() * numUploads) + " mpu listings, but got " + listing.getMultipartUploads().size(), (tailMap.size() * numUploads) == listing.getMultipartUploads().size()); Iterator<MultipartUpload> mpuIterator = listing.getMultipartUploads().iterator(); for (Entry<String, List<String>> tailMapEntry : tailMap.entrySet()) { for (String uploadId : tailMapEntry.getValue()) { MultipartUpload mpu = mpuIterator.next(); assertTrue("Expected key to be " + tailMapEntry.getKey() + ", but got " + mpu.getKey(), mpu.getKey().equals(tailMapEntry.getKey())); assertTrue("Expected upload ID to be " + uploadId + ", but got " + mpu.getUploadId(), mpu.getUploadId().equals(uploadId)); verifyCommonElements(mpu); } } assertTrue("Expected mpu iterator to be empty", !mpuIterator.hasNext()); } } catch (AmazonServiceException ase) { printException(ase); assertThat(false, "Failed to run keyMarker"); } }
From source file:org.alfresco.repo.content.cleanup.ContentStoreCleaner.java
/** * /*w w w. j a va 2 s .c o m*/ * @param maxTimeExclusive the max orphan time (exclusive) * @param batchSize the maximum number of orphans to process * @return Returns the last processed orphan ID or <tt>null</tt> if nothing was processed */ private Long cleanBatch(final long maxTimeExclusive, final int batchSize) { // Get a bunch of cleanable URLs final TreeMap<Long, String> urlsById = new TreeMap<Long, String>(); ContentUrlHandler contentUrlHandler = new ContentUrlHandler() { @Override public void handle(Long id, String contentUrl, Long orphanTime) { urlsById.put(id, contentUrl); } }; // Get a bunch of cleanable URLs contentDataDAO.getContentUrlsOrphaned(contentUrlHandler, maxTimeExclusive, batchSize); // Shortcut, if necessary if (urlsById.size() == 0) { return null; } // Compile list of IDs and do a mass delete, recording the IDs to find the largest Long lastId = urlsById.lastKey(); List<Long> ids = new ArrayList<Long>(urlsById.keySet()); contentDataDAO.deleteContentUrls(ids); // No problems, so far (ALF-1998: contentStoreCleanerJob leads to foreign key exception) // Now attempt to physically delete the URLs for (Long id : ids) { String contentUrl = urlsById.get(id); // Handle failures boolean deleted = eagerContentStoreCleaner.deleteFromStores(contentUrl); if (!deleted) { switch (deletionFailureAction) { case KEEP_URL: // Keep the URL, but with an orphan time of 0 so that it is recorded contentDataDAO.createContentUrlOrphaned(contentUrl, new Date(0L)); case IGNORE: break; default: throw new IllegalStateException("Unknown deletion failure action: " + deletionFailureAction); } } } // Done return lastId; }