List of usage examples for java.util SortedMap get
V get(Object key);
From source file:org.wso2.carbon.ml.dataset.internal.DatabaseHandler.java
/** * Create the JSON string with summary statistics for a column. * * @param type Data-type of the column * @param graphFrequencies Bin frequencies of the column * @param missing Number of missing values in the column * @param unique Number of unique values in the column * @param descriptiveStats DescriptiveStats object of the column * @return JSON representation of the summary statistics of the column *///from ww w . j av a2 s . com private JSONArray createJson(String type, SortedMap<?, Integer> graphFrequencies, int missing, int unique, DescriptiveStatistics descriptiveStats) { JSONObject json = new JSONObject(); JSONArray freqs = new JSONArray(); Object[] categoryNames = graphFrequencies.keySet().toArray(); // Create an array with intervals/categories and their frequencies. for (int i = 0; i < graphFrequencies.size(); i++) { JSONArray temp = new JSONArray(); temp.put(categoryNames[i].toString()); temp.put(graphFrequencies.get(categoryNames[i])); freqs.put(temp); } // Put the statistics to a json object json.put("unique", unique); json.put("missing", missing); DecimalFormat decimalFormat = new DecimalFormat("#.###"); if (descriptiveStats.getN() != 0) { json.put("mean", decimalFormat.format(descriptiveStats.getMean())); json.put("median", decimalFormat.format(descriptiveStats.getPercentile(50))); json.put("std", decimalFormat.format(descriptiveStats.getStandardDeviation())); if (type.equalsIgnoreCase(FeatureType.NUMERICAL)) { json.put("skewness", decimalFormat.format(descriptiveStats.getSkewness())); } } json.put("values", freqs); json.put("bar", true); json.put("key", "Frequency"); JSONArray summaryStatArray = new JSONArray(); summaryStatArray.put(json); return summaryStatArray; }
From source file:com.aurel.track.item.history.HistoryLoaderBL.java
/** * Get the list of HistoryValues from the map of Map<Integer, Map<Integer, HistoryValues>> * @param allHistoryMap/*from w w w .jav a 2 s .co m*/ * @param workItemBeansMap * @param workItemID * @param locale * @param longEntriesSeparate * @return */ public static List<FlatHistoryBean> getFlatHistoryValuesList( SortedMap<Integer, Map<Integer, HistoryValues>> allHistoryMap, Map<Integer, TWorkItemBean> workItemBeansMap, Integer workItemID, Locale locale, boolean longEntriesSeparate, boolean withChildren) { List<FlatHistoryBean> historyList = new ArrayList<FlatHistoryBean>(); if (allHistoryMap != null) { Iterator<Integer> itrHistoryMap = allHistoryMap.keySet().iterator(); while (itrHistoryMap.hasNext()) { Integer transactionID = itrHistoryMap.next(); Map<Integer, HistoryValues> changesMap = allHistoryMap.get(transactionID); Set<Integer> changedFieldIDs = changesMap.keySet(); int type = getType(changedFieldIDs); HistoryValues histValues = null; List<HistoryEntry> historyEntries = new ArrayList<HistoryEntry>(); List<HistoryEntry> historyLongEntries = new ArrayList<HistoryEntry>(); Iterator<Integer> itrChanges = changedFieldIDs.iterator(); while (itrChanges.hasNext()) { Integer fieldID = itrChanges.next(); histValues = changesMap.get(fieldID); HistoryEntry historyEntry = new HistoryEntry(); historyEntry.setFieldLabel(histValues.getFieldName()); String newValue = histValues.getNewShowValue(); String oldValue = histValues.getOldShowValue(); //for flat history with children only the new values are shown but for date change //the old value will also be included in a parenthesis if (withChildren && (SystemFields.INTEGER_STARTDATE.equals(fieldID) || SystemFields.INTEGER_ENDDATE.equals(fieldID))) { if (oldValue != null && !"".equals(oldValue.trim())) { newValue = newValue + " (" + oldValue + ")"; } } boolean isLongField = isLong(fieldID); if (isLongField) { //if(!SystemFields.INTEGER_COMMENT.equals(fieldID)){ String diff = null; try { String newValueFormatted = ItemDetailBL.formatDescription(newValue, locale); String oldValueFormatted = ItemDetailBL.formatDescription(oldValue, locale); diff = HTMLDiff.makeDiff(newValueFormatted, oldValueFormatted, locale); diff = ItemDetailBL.formatDescription(diff, locale); } catch (Exception ex) { LOGGER.error(" can't create diff: " + ex.getMessage()); if (LOGGER.isDebugEnabled()) { LOGGER.error(ExceptionUtils.getStackTrace(ex)); } } historyEntry.setDiff(diff); //} } String changedText = null; if (type == HistoryBean.HISTORY_TYPE.ATTACHMENT) { changedText = "<strong>" + histValues.getFieldName() + "</strong> "; if (newValue != null && newValue.length() > 0) { changedText += "<span class=\"histNewValue\">" + histValues.getNewShowValue() + "</span>"; } else { changedText += "<span class=\"histOldValue\">" + histValues.getOldShowValue() + "</span>"; } } else { String tkey = "item.history.changeTextSimpleField"; if (isLongField) { tkey = "item.history.changeTextLongField"; } if (newValue != null && newValue.length() > 0 && oldValue != null && oldValue.length() > 0) { changedText = LocalizeUtil .getParametrizedString( tkey, new Object[] { histValues.getFieldName(), histValues.getOldShowValue(), histValues.getNewShowValue() }, locale); } else if (newValue != null && newValue.length() > 0) { tkey = tkey + ".oldValueNull"; changedText = LocalizeUtil.getParametrizedString(tkey, new Object[] { histValues.getFieldName(), histValues.getNewShowValue() }, locale); } else { tkey = tkey + ".newValueNull"; changedText = LocalizeUtil.getParametrizedString(tkey, new Object[] { histValues.getFieldName(), histValues.getOldShowValue() }, locale); } } historyEntry.setNewValue(newValue); historyEntry.setChangedText(changedText); historyEntry.setOldValue(oldValue); if (longEntriesSeparate && fieldID.intValue() == TFieldChangeBean.COMPOUND_HISTORY_FIELD) { historyEntry.setFieldLabel(null); } boolean fieldIsLong = isLong(fieldID); if (fieldIsLong) { historyEntry .setNewValue(ItemDetailBL.formatDescription(historyEntry.getNewValue(), locale)); } if (longEntriesSeparate && fieldIsLong) { //TODO whether the not pseudo field is of type long historyLongEntries.add(historyEntry); } else { //long fields and short fields are treated same: format the long field content already here (not in the jsp) historyEntries.add(historyEntry); } } if (histValues != null) { FlatHistoryBean flatHistoryBean = new FlatHistoryBean(); flatHistoryBean.setChangedByName(histValues.getChangedByName()); flatHistoryBean.setPersonID(histValues.getChangedByID()); flatHistoryBean.setLastEdit(histValues.getLastEdit()); flatHistoryBean.setHistoryEntries(historyEntries); flatHistoryBean.setHistoryLongEntries(historyLongEntries); flatHistoryBean.setType(type); flatHistoryBean.setIconName(getIconByType(type)); addWorkItemToFlatHistoryBean(flatHistoryBean, workItemBeansMap, workItemID, FlatHistoryBean.RENDER_TYPE.HISTORY_VALUES); historyList.add(flatHistoryBean); } } } if (historyList.size() > 0) { // sort all history beans chronologically Collections.sort(historyList, new HistoryComparator()); } return historyList; }
From source file:at.tuwien.ifs.somtoolbox.apps.viewer.controls.ClusteringControl.java
public void init() { maxCluster = state.growingLayer.getXSize() * state.growingLayer.getYSize(); spinnerNoCluster = new JSpinner(new SpinnerNumberModel(1, 1, maxCluster, 1)); spinnerNoCluster.addChangeListener(new ChangeListener() { @Override/* w ww. jav a 2 s .co m*/ public void stateChanged(ChangeEvent e) { numClusters = (Integer) ((JSpinner) e.getSource()).getValue(); SortedMap<Integer, ClusterElementsStorage> m = mapPane.getMap().getCurrentClusteringTree() .getAllClusteringElements(); if (m.containsKey(numClusters)) { st = m.get(numClusters).sticky; } else { st = false; } sticky.setSelected(st); redrawClustering(); } }); JPanel clusterPanel = UiUtils.makeBorderedPanel(new FlowLayout(FlowLayout.LEFT, 10, 0), "Clusters"); sticky.setToolTipText( "Marks this number of clusters as sticky for a certain leve; the next set of clusters will have a smaller boundary"); sticky.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { st = sticky.isSelected(); SortedMap<Integer, ClusterElementsStorage> m = mapPane.getMap().getCurrentClusteringTree() .getAllClusteringElements(); if (m.containsKey(numClusters)) { ClusterElementsStorage c = m.get(numClusters); c.sticky = st; // System.out.println("test"); // ((ClusterElementsStorageNode)m.get(numClusters)).sticky = st; redrawClustering(); } } }); colorCluster = new JCheckBox("colour", state.colorClusters); colorCluster.setToolTipText("Fill the clusters in colours"); colorCluster.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { state.colorClusters = colorCluster.isSelected(); // TODO: Palette anzeigen (?) redrawClustering(); } }); UiUtils.fillPanel(clusterPanel, new JLabel("#"), spinnerNoCluster, sticky, colorCluster); getContentPane().add(clusterPanel, c.nextRow()); dendogramPanel = UiUtils.makeBorderedPanel(new GridLayout(0, 1), "Dendogram"); getContentPane().add(dendogramPanel, c.nextRow()); JPanel numLabelPanel = UiUtils.makeBorderedPanel(new GridBagLayout(), "Labels"); GridBagConstraintsIFS gcLabels = new GridBagConstraintsIFS(); labelSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1)); labelSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { numLabels = (Integer) ((JSpinner) e.getSource()).getValue(); state.clusterWithLabels = numLabels; redrawClustering(); } }); this.showValues = new JCheckBox("values", state.labelsWithValues); this.showValues.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { state.labelsWithValues = showValues.isSelected(); redrawClustering(); } }); int start = new Double((1 - state.clusterByValue) * 100).intValue(); valueQe = new JSlider(0, 100, start); valueQe.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int byValue = ((JSlider) e.getSource()).getValue(); state.clusterByValue = 1 - byValue / 100; redrawClustering(); } }); numLabelPanel.add(new JLabel("# Labels"), gcLabels); numLabelPanel.add(labelSpinner, gcLabels.nextCol()); numLabelPanel.add(showValues, gcLabels.nextCol()); numLabelPanel.add(valueQe, gcLabels.nextRow().setGridWidth(3).setFill(GridBagConstraints.HORIZONTAL)); getContentPane().add(numLabelPanel, c.nextRow()); Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); labelTable.put(0, new JLabel("by Value")); labelTable.put(100, new JLabel("by Qe")); valueQe.setToolTipText("Method how to select representative labels - by QE, or the attribute values"); valueQe.setLabelTable(labelTable); valueQe.setPaintLabels(true); final JComboBox initialisationBox = new JComboBox(KMeans.InitType.values()); initialisationBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object o = mapPane.getMap().getClusteringTreeBuilder(); if (o instanceof KMeansTreeBuilder) { ((KMeansTreeBuilder) o).reInit((KMeans.InitType) initialisationBox.getSelectedItem()); // FIXME: is this call needed? mapPane.getMap().getCurrentClusteringTree().getAllClusteringElements(); redrawClustering(); } } }); getContentPane().add(UiUtils.fillPanel(kmeansInitialisationPanel, new JLabel("k-Means initialisation"), initialisationBox), c.nextRow()); JPanel borderPanel = new TitledCollapsiblePanel("Border", new GridLayout(1, 4), true); JSpinner borderSpinner = new JSpinner( new SpinnerNumberModel(ClusteringTree.INITIAL_BORDER_WIDTH_MAGNIFICATION_FACTOR, 0.1, 5, 0.1)); borderSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { state.clusterBorderWidthMagnificationFactor = ((Double) ((JSpinner) e.getSource()).getValue()) .floatValue(); redrawClustering(); } }); borderPanel.add(new JLabel("width")); borderPanel.add(borderSpinner); borderPanel.add(new JLabel("colour")); buttonColour = new JButton(""); buttonColour.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new ClusterBoderColorChooser(state.parentFrame, state.clusterBorderColour, ClusteringControl.this); } }); buttonColour.setBackground(state.clusterBorderColour); borderPanel.add(buttonColour); getContentPane().add(borderPanel, c.nextRow()); JPanel evaluationPanel = new TitledCollapsiblePanel("Cluster Evaluation", new GridLayout(3, 2), true); evaluationPanel.add(new JLabel("quality measure")); qualityMeasureButton = new JButton(); qualityMeasureButton.setText("ent/pur calc"); qualityMeasureButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("doing entropy here"); ClusteringTree clusteringTree = state.mapPNode.getClusteringTree(); if (clusteringTree == null) { // we have not clustered yet return; } // System.out.println(clusteringTree.getChildrenCount()); // FIXME put this in a method and call it on numcluster.change() SOMLibClassInformation classInfo = state.inputDataObjects.getClassInfo(); ArrayList<ClusterNode> clusters = clusteringTree.getNodesAtLevel(numClusters); System.out.println(clusters.size()); // EntropyMeasure.computeEntropy(clusters, classInfo); EntropyAndPurityCalculator eapc = new EntropyAndPurityCalculator(clusters, classInfo); // FIXME round first entropyLabel.setText(String.valueOf(eapc.getEntropy())); purityLabel.setText(String.valueOf(eapc.getPurity())); } }); evaluationPanel.add(qualityMeasureButton); GridBagConstraintsIFS gcEval = new GridBagConstraintsIFS(); evaluationPanel.add(new JLabel("entropy"), gcEval); evaluationPanel.add(new JLabel("purity"), gcEval.nextCol()); entropyLabel = new JLabel("n/a"); purityLabel = new JLabel("n/a"); evaluationPanel.add(entropyLabel, gcEval.nextRow()); evaluationPanel.add(purityLabel, gcEval.nextCol()); getContentPane().add(evaluationPanel, c.nextRow()); JPanel panelButtons = new JPanel(new GridLayout(1, 4)); JButton saveButton = new JButton("Save"); saveButton.setFont(smallFont); saveButton.setMargin(SMALL_INSETS); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser; if (state.fileChooser.getSelectedFile() != null) { fileChooser = new JFileChooser(state.fileChooser.getSelectedFile().getPath()); } else { fileChooser = new JFileChooser(); } fileChooser.addChoosableFileFilter(clusteringFilter); fileChooser.addChoosableFileFilter(xmlFilter); File filePath = ExportUtils.getFilePath(ClusteringControl.this, fileChooser, "Save Clustering and Labels"); if (filePath != null) { if (xmlFilter.accept(filePath)) { LabelXmlUtils.saveLabelsToFile(state.mapPNode, filePath); } else { try { FileOutputStream fos = new FileOutputStream(filePath); GZIPOutputStream gzipOs = new GZIPOutputStream(fos); PObjectOutputStream oos = new PObjectOutputStream(gzipOs); oos.writeObjectTree(mapPane.getMap().getCurrentClusteringTree()); oos.writeObjectTree(mapPane.getMap().getManualLabels()); oos.writeInt(state.clusterWithLabels); oos.writeBoolean(state.labelsWithValues); oos.writeDouble(state.clusterByValue); oos.writeObject(spinnerNoCluster.getValue()); oos.close(); } catch (Exception ex) { ex.printStackTrace(); } } // keep the selected path for future references state.fileChooser.setSelectedFile(filePath.getParentFile()); } } }); panelButtons.add(saveButton); JButton loadButton = new JButton("Load"); loadButton.setFont(smallFont); loadButton.setMargin(SMALL_INSETS); loadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = getFileChooser(); fileChooser.setName("Open Clustering"); fileChooser.addChoosableFileFilter(xmlFilter); fileChooser.addChoosableFileFilter(clusteringFilter); int returnVal = fileChooser.showDialog(ClusteringControl.this, "Open"); if (returnVal == JFileChooser.APPROVE_OPTION) { File filePath = fileChooser.getSelectedFile(); if (xmlFilter.accept(filePath)) { PNode restoredLabels = null; try { restoredLabels = LabelXmlUtils.restoreLabelsFromFile(fileChooser.getSelectedFile()); PNode manual = state.mapPNode.getManualLabels(); ArrayList<PNode> tmp = new ArrayList<PNode>(); for (ListIterator<?> iter = restoredLabels.getChildrenIterator(); iter.hasNext();) { PNode element = (PNode) iter.next(); tmp.add(element); } manual.addChildren(tmp); Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Successfully loaded cluster labels."); } catch (Exception e1) { e1.printStackTrace(); Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Error loading cluster labels: " + e1.getMessage()); } } else { try { FileInputStream fis = new FileInputStream(filePath); GZIPInputStream gzipIs = new GZIPInputStream(fis); ObjectInputStream ois = new ObjectInputStream(gzipIs); ClusteringTree tree = (ClusteringTree) ois.readObject(); PNode manual = (PNode) ois.readObject(); PNode all = mapPane.getMap().getManualLabels(); ArrayList<PNode> tmp = new ArrayList<PNode>(); for (ListIterator<?> iter = manual.getChildrenIterator(); iter.hasNext();) { PNode element = (PNode) iter.next(); tmp.add(element); } all.addChildren(tmp); state.clusterWithLabels = ois.readInt(); labelSpinner.setValue(state.clusterWithLabels); state.labelsWithValues = ois.readBoolean(); showValues.setSelected(state.labelsWithValues); state.clusterByValue = ois.readDouble(); valueQe.setValue(new Double((1 - state.clusterByValue) * 100).intValue()); mapPane.getMap().buildTree(tree); spinnerNoCluster.setValue(ois.readObject()); ois.close(); Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Successfully loaded clustering."); } catch (Exception ex) { ex.printStackTrace(); Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Error loading clustering: " + ex.getMessage()); } } // keep the selected path for future references state.fileChooser.setSelectedFile(filePath.getParentFile()); } } }); panelButtons.add(loadButton); JButton exportImages = new JButton("Export"); exportImages.setFont(smallFont); exportImages.setMargin(SMALL_INSETS); exportImages.setToolTipText("Export labels as images (not yet working)"); exportImages.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); if (CommonSOMViewerStateData.fileNamePrefix != null && !CommonSOMViewerStateData.fileNamePrefix.equals("")) { fileChooser.setCurrentDirectory(new File(CommonSOMViewerStateData.fileNamePrefix)); } else { fileChooser.setCurrentDirectory(state.getFileChooser().getCurrentDirectory()); } fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fileChooser.getSelectedFile() != null) { // reusing the dialog fileChooser.setSelectedFile(null); } fileChooser.setName("Choose path"); int returnVal = fileChooser.showDialog(ClusteringControl.this, "Choose path"); if (returnVal == JFileChooser.APPROVE_OPTION) { // save images String path = fileChooser.getSelectedFile().getAbsolutePath(); Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Writing label images to " + path); } } }); panelButtons.add(exportImages); JButton deleteManual = new JButton("Delete"); deleteManual.setFont(smallFont); deleteManual.setMargin(SMALL_INSETS); deleteManual.setToolTipText("Delete manually added labels."); deleteManual.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { state.mapPNode.getManualLabels().removeAllChildren(); Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Manual Labels deleted."); } }); panelButtons.add(deleteManual); c.anchor = GridBagConstraints.NORTH; this.getContentPane().add(panelButtons, c.nextRow()); this.setVisible(true); }
From source file:ubic.gemma.web.controller.common.description.bibref.BibliographicReferenceControllerImpl.java
@Override public ModelAndView showAllForExperiments(HttpServletRequest request, HttpServletResponse response) { Map<ExpressionExperiment, BibliographicReference> eeToBibRefs = bibliographicReferenceService .getAllExperimentLinkedReferences(); // map sorted in natural order of the keys SortedMap<CitationValueObject, Collection<ExpressionExperimentValueObject>> citationToEEs = new TreeMap<>(); for (Entry<ExpressionExperiment, BibliographicReference> entry : eeToBibRefs.entrySet()) { if (entry.getValue().getTitle() == null || entry.getValue().getTitle().isEmpty() || entry.getValue().getAuthorList() == null || entry.getValue().getAuthorList().isEmpty()) { continue; }/*w w w .j av a 2 s . c o m*/ CitationValueObject cvo = CitationValueObject.convert2CitationValueObject(entry.getValue()); if (!citationToEEs.containsKey(cvo)) { citationToEEs.put(cvo, new ArrayList<ExpressionExperimentValueObject>()); } ExpressionExperiment ee = entry.getKey(); ee.setBioAssays(null); ee.setAccession(null); ee.setExperimentalDesign(null); citationToEEs.get(cvo).add(new ExpressionExperimentValueObject(ee)); } return new ModelAndView("bibRefAllExperiments").addObject("citationToEEs", citationToEEs); }
From source file:org.kuali.kra.budget.external.budget.impl.BudgetAdjustmentClientBase.java
/** * This method sets the non personnel calculated direct cost. * @param accountingLines /*from w w w. j a v a 2 s. co m*/ * @return */ protected boolean setNonPersonnelCalculatedDirectCostAccountingLines(AwardBudgetDocument awardBudgetDocument, Map<String, ScaleTwoDecimal> accountingLines) { boolean complete = true; Budget currentBudget = awardBudgetDocument.getBudget(); AwardBudgetExt previousBudget = getPrevBudget(awardBudgetDocument); SortedMap<RateType, ScaleTwoDecimal> netExpense = getBudgetAdjustmentServiceHelper() .getNonPersonnelCalculatedDirectCost(currentBudget, previousBudget); SortedMap<RateType, List<ScaleTwoDecimal>> currentNonPersonnelCalcDirectCost = awardBudgetDocument .getAwardBudget().getNonPersonnelCalculatedExpenseTotals(); for (RateType rateType : netExpense.keySet()) { LOG.info("NonPersonnel calculated direct cost: " + rateType.getRateTypeCode() + "-" + rateType.getRateClassCode() + " = " + netExpense.get(rateType)); // check if rate class type is O instead if (!rateType.getRateClass().getRateClassTypeCode().equalsIgnoreCase("O")) { List<ScaleTwoDecimal> expenses = currentNonPersonnelCalcDirectCost.get(rateType); Details details = new Details(); details.setCurrentAmount(netExpense.get(rateType).toString()); // only need abs value of amount String financialObjectCode = getFinancialObjectCode(awardBudgetDocument, rateType.getRateClassCode(), rateType.getRateTypeCode()); if (ObjectUtils.isNull(financialObjectCode)) { complete &= false; } else { if (!accountingLines.containsKey(financialObjectCode)) { accountingLines.put(financialObjectCode, netExpense.get(rateType)); } else { accountingLines.put(financialObjectCode, accountingLines.get(financialObjectCode).add(netExpense.get(rateType))); } } } } return complete; }
From source file:org.apache.ctakes.ytex.kernel.FoldGeneratorImpl.java
@Override public SortedMap<String, SortedMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>>> generateRuns( SortedMap<String, SortedMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>>> labelToInstanceMap, int nFolds, int nMinPerClass, Integer nSeed, int nRuns) { // allocate map to return SortedMap<String, SortedMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>>> labelToInstanceFoldMap = new TreeMap<String, SortedMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>>>(); // initialize random seed Random r = new Random(nSeed != null ? nSeed : System.currentTimeMillis()); // iterate over labels for (Map.Entry<String, SortedMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>>> labelRun : labelToInstanceMap .entrySet()) {/*from w w w.j ava 2 s . c o m*/ String label = labelRun.getKey(); // extract the instance id - class map SortedMap<Long, String> instanceClassMap = labelRun.getValue().get(0).get(0).get(true); // allocate the run to fold map SortedMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>> runMap = new TreeMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>>(); labelToInstanceFoldMap.put(label, runMap); // iterate over runs for (int run = 1; run <= nRuns; run++) { // generate folds for run List<Set<Long>> folds = createFolds(nFolds, nMinPerClass, r, instanceClassMap); SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>> foldMap = new TreeMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>(); // add the fold map to the run map runMap.put(run, foldMap); // iterate over folds for (int trainFoldNum = 1; trainFoldNum <= folds.size(); trainFoldNum++) { // add train/test sets for the fold SortedMap<Boolean, SortedMap<Long, String>> trainTestMap = new TreeMap<Boolean, SortedMap<Long, String>>(); foldMap.put(trainFoldNum, trainTestMap); trainTestMap.put(true, new TreeMap<Long, String>()); trainTestMap.put(false, new TreeMap<Long, String>()); // populate the train/test sets Set<Long> testIds = folds.get(trainFoldNum - 1); // iterate over all instances for (Map.Entry<Long, String> instanceClass : instanceClassMap.entrySet()) { long instanceId = instanceClass.getKey(); String clazz = instanceClass.getValue(); // add the instance to the test set if it is in testIds, // else to the train set trainTestMap.get(!testIds.contains(instanceId)).put(instanceId, clazz); } } } } return labelToInstanceFoldMap; }
From source file:com.aurel.track.fieldType.bulkSetters.CustomMultipleSelectBulkSetter.java
/** * Sets the workItemBean's attribute depending on the value and bulkRelation * @param workItemBean/* ww w. j a v a2 s . c om*/ * @param fieldID * @param parameterCode * @param bulkTranformContext * @param selectContext * @param value * @return ErrorData if an error is found */ @Override public ErrorData setWorkItemAttribute(TWorkItemBean workItemBean, Integer fieldID, Integer parameterCode, BulkTranformContext bulkTranformContext, SelectContext selectContext, Object value) { if (getRelation() == BulkRelations.SET_NULL || getRelation() == BulkRelations.SET_TO) { return super.setWorkItemAttribute(workItemBean, fieldID, parameterCode, bulkTranformContext, selectContext, value); } Object originalValue = workItemBean.getAttribute(fieldID, parameterCode); Object[] originalSelections = null; if (originalValue != null) { try { //multiple values are loaded in the workItem as Object[], not as Integer[] !!! originalSelections = (Object[]) originalValue; } catch (Exception e) { LOGGER.info( "Getting the original object array value for " + value + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } Set<Integer> originalSet = new HashSet<Integer>(); if (originalSelections != null && originalSelections.length > 0) { for (int i = 0; i < originalSelections.length; i++) { try { originalSet.add((Integer) originalSelections[i]); } catch (Exception e) { LOGGER.info("Transforming the original object value " + originalSelections[i] + " to Integer failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } } Integer[] newValue = null; SortedMap<Integer, Integer[]> valueMap = (SortedMap<Integer, Integer[]>) value; Map<Integer, Map<Integer, Map<Integer, Integer>>> fieldToProjectToIssueTypeToListMap = bulkTranformContext .getFieldToProjectToIssueTypeToListMap(); if (fieldToProjectToIssueTypeToListMap != null) { Map<Integer, Map<Integer, Integer>> projectToIssueTypeToListMap = fieldToProjectToIssueTypeToListMap .get(fieldID); if (projectToIssueTypeToListMap != null) { Integer projectID = workItemBean.getProjectID(); Map<Integer, Integer> issueTypeToListMap = projectToIssueTypeToListMap.get(projectID); if (issueTypeToListMap != null) { Integer issueTypeID = workItemBean.getListTypeID(); Integer listID = issueTypeToListMap.get(issueTypeID); if (listID != null) { newValue = valueMap.get(listID); } } } } Set<Integer> bulkSelectionsSet = GeneralUtils.createSetFromIntegerArr(newValue); switch (getRelation()) { case BulkRelations.ADD_ITEMS: originalSet.addAll(bulkSelectionsSet); workItemBean.setAttribute(fieldID, parameterCode, GeneralUtils.createIntegerArrFromCollection(originalSet)); break; case BulkRelations.REMOVE_ITEMS: originalSet.removeAll(bulkSelectionsSet); workItemBean.setAttribute(fieldID, parameterCode, GeneralUtils.createIntegerArrFromCollection(originalSet)); break; default: break; } return null; }
From source file:org.apereo.portal.events.aggr.JpaBaseAggregationDaoTest.java
/** * Populate date & time dimensions in an interval range executing a callback for each pair *///from ww w. j a v a 2 s. c o m public final <RT> List<RT> populateDateTimeDimensions(final DateTime start, final DateTime end, final Function<Tuple<DateDimension, TimeDimension>, RT> newDimensionHandler) { return this.executeInTransaction(new Callable<List<RT>>() { @Override public List<RT> call() throws Exception { final List<RT> results = new LinkedList<RT>(); final SortedMap<LocalTime, TimeDimension> times = new TreeMap<LocalTime, TimeDimension>(); final SortedMap<DateMidnight, DateDimension> dates = new TreeMap<DateMidnight, DateDimension>(); DateTime nextDateTime = start.minuteOfDay().roundFloorCopy(); while (nextDateTime.isBefore(end)) { //get/create TimeDimension final LocalTime localTime = nextDateTime.toLocalTime(); TimeDimension td = times.get(localTime); if (td == null) { td = timeDimensionDao.createTimeDimension(localTime); times.put(localTime, td); } //get/create DateDimension final DateMidnight dateMidnight = nextDateTime.toDateMidnight(); DateDimension dd = dates.get(dateMidnight); if (dd == null) { dd = dateDimensionDao.createDateDimension(dateMidnight, 0, null); dates.put(dateMidnight, dd); } //Let callback do work if (newDimensionHandler != null) { final RT result = newDimensionHandler .apply(new Tuple<DateDimension, TimeDimension>(dd, td)); if (result != null) { results.add(result); } } nextDateTime = nextDateTime.plusMinutes(1); } return results; } }); }
From source file:org.onebusaway.admin.service.bundle.hastus.HastusGtfsFactory.java
private Integer getScheduledTimeForTimepoint(RouteStopSequenceItem item, Map<String, Integer> timepointPositions, SortedMap<Integer, Integer> arrivalTimesByTimepointPosition) { String timepoint = item.getTimePoint(); if (timepoint == null || timepoint.length() == 0) return null; /**//from w ww. java 2 s . c om * There seem to be plenty of timepoint ids mentioned in the GIS route shape * data that aren't in the schedule files. Just silently ignore. */ Integer position = timepointPositions.get(timepoint); if (position == null) return null; return arrivalTimesByTimepointPosition.get(position); }
From source file:com.aurel.track.item.history.HistoryLoaderBL.java
/** * Get the HistoryValues map for a list of of historyTransactions and the corresponding fieldChangeBeanList * @param workItemIDs//from www. j av a2 s. c o m * @param filterFieldID if null do not filter by it * @param includeField not null: if true include this field, if false exclude this field * @param filterHistoryPersonID if null do not filter by it * @param fromDate * @param toDate * @param locale * @param isISO * @param longTextIsPlain * @param excludeHidden exclude the fields not visible by current user * @param loggedPersonID * @return */ public static Map<Integer, SortedMap<Integer, Map<Integer, HistoryValues>>> getWorkItemsHistory( List<THistoryTransactionBean> historyTransactionBeanList, List<TFieldChangeBean> fieldChangeBeanList, Integer[] filterFieldIDs, List<Integer> filterHistoryPersonIDs, Locale locale, boolean isISO, LONG_TEXT_TYPE longTextIsPlain, boolean excludeHidden, Integer loggedPersonID) { Date start = null; Date loadingHistoryData = null; Date populatingHistoryData = null; if (LOGGER.isDebugEnabled()) { start = new Date(); } Map<Integer, Map<Integer, Map<Integer, Integer>>> fieldRestrictions = null; Map<Integer, TWorkItemBean> workItemBeansMap = null; Set<Integer> itemIDSet = new HashSet<Integer>(); if (historyTransactionBeanList != null) { for (THistoryTransactionBean historyTransactionBean : historyTransactionBeanList) { Integer workItemID = historyTransactionBean.getWorkItem(); itemIDSet.add(workItemID); } } List<TWorkItemBean> workItemBeansList = ItemBL .loadByWorkItemKeys(GeneralUtils.createIntArrFromSet(itemIDSet)); LocalLookupContainer localLookupContainer = ItemBL.getItemHierarchyContainer(workItemBeansList); if (excludeHidden) { workItemBeansMap = GeneralUtils.createMapFromList(workItemBeansList); Map<Integer, Set<Integer>> projectToIssueTypesMap = AccessBeans .getProjectToIssueTypesMap(workItemBeansList); List<Integer> fieldIDs = null; if (filterFieldIDs != null && filterFieldIDs.length > 0) { fieldIDs = GeneralUtils.createIntegerListFromIntegerArr(filterFieldIDs); } fieldRestrictions = AccessBeans.getFieldRestrictions(loggedPersonID, projectToIssueTypesMap, fieldIDs, false); if (fieldRestrictions != null) { //whether the Common field from history should be restricted or not. This is a conservative restriction: //if any field which is restricted has not explicit history set (i.e. it might appear in Common changes) then the Common field is hidden Set<Integer> restrictedFieldsInAnyContext = new HashSet<Integer>(); for (Map<Integer, Map<Integer, Integer>> projectFieldRestrictions : fieldRestrictions.values()) { if (projectFieldRestrictions != null) { for (Map<Integer, Integer> itemTypeFieldRestrictions : projectFieldRestrictions.values()) { if (itemTypeFieldRestrictions != null) { for (Integer fieldID : itemTypeFieldRestrictions.keySet()) { restrictedFieldsInAnyContext.add(fieldID); } } } } } if (!restrictedFieldsInAnyContext.isEmpty()) { LOGGER.debug("Field restrictions found for person " + loggedPersonID + " for " + restrictedFieldsInAnyContext.size() + " fields"); Map<Integer, Map<Integer, Map<Integer, TFieldConfigBean>>> projectsIssueTypesFieldConfigsMap = FieldRuntimeBL .loadFieldConfigsInContextsAndTargetProjectAndIssueType(projectToIssueTypesMap, restrictedFieldsInAnyContext, locale, null, null); for (Map.Entry<Integer, Map<Integer, Map<Integer, Integer>>> projectFieldRestrictionsEntry : fieldRestrictions .entrySet()) { Integer projectID = projectFieldRestrictionsEntry.getKey(); Map<Integer, Map<Integer, Integer>> projectFieldRestrictions = projectFieldRestrictionsEntry .getValue(); Map<Integer, Map<Integer, TFieldConfigBean>> projectFieldConfigs = projectsIssueTypesFieldConfigsMap .get(projectID); if (projectFieldConfigs != null && projectFieldRestrictions != null) { for (Map.Entry<Integer, Map<Integer, Integer>> itemTypeFieldRestrictionsEntry : projectFieldRestrictions .entrySet()) { Integer itemType = itemTypeFieldRestrictionsEntry.getKey(); Map<Integer, Integer> itemTypeFieldRestrictions = itemTypeFieldRestrictionsEntry .getValue(); Map<Integer, TFieldConfigBean> itemTypeFieldConfigs = projectFieldConfigs .get(itemType); if (itemTypeFieldConfigs != null && itemTypeFieldRestrictions != null) { for (Integer fieldID : itemTypeFieldRestrictions.keySet()) { TFieldConfigBean fieldConfigBean = itemTypeFieldConfigs.get(fieldID); if (fieldConfigBean != null && !fieldConfigBean.isHistoryString()) { LOGGER.debug("The restricted field " + fieldConfigBean.getLabel() + " (" + fieldID + ") has no explict history so the Commons history field is also disabled"); itemTypeFieldRestrictions.put(TFieldChangeBean.COMPOUND_HISTORY_FIELD, TRoleFieldBean.ACCESSFLAG.NOACCESS); break; } } } } } } } } } Map<Integer, TFieldBean> fieldsMap = new HashMap<Integer, TFieldBean>(1); Map<Integer, String> fieldConfigLabelsMap = new HashMap<Integer, String>(1); if (isISO) { fieldsMap = GeneralUtils.createMapFromList(FieldBL.loadAll()); } else { fieldConfigLabelsMap = LocalizeUtil.getLocalizedFieldConfigLables(FieldConfigBL.loadDefault(), locale); } /*List<THistoryTransactionBean> historyTransactionBeanList = HistoryTransactionBL.getByWorkItemsAndFields( workItemIDs, filterFieldIDs, includeField, filterHistoryPersonIDs, fromDate, toDate);*/ addPersonNamesToHistoryTransactionBeans(historyTransactionBeanList); Map<Integer, THistoryTransactionBean> historyTransactionBeanMap = GeneralUtils .createMapFromList(historyTransactionBeanList); /*List<TFieldChangeBean> fieldChangeBeanList = FieldChangeBL.getByWorkItemsAndFields(workItemIDs, filterFieldIDs, includeField, filterHistoryPersonIDs, fromDate, toDate);*/ if (LOGGER.isDebugEnabled() && start != null) { loadingHistoryData = new Date(); LOGGER.debug("Loading the history values from database for " + " ReportBeanWithHistory lasted " + Long.toString(loadingHistoryData.getTime() - start.getTime()) + " ms"); } Map<Integer, Map<Integer, Map<String, Object>>> workItemsFieldChangeBeansMap = getFieldChangeBeansByWorkItemAndTransactionAndMergedField( historyTransactionBeanMap, fieldChangeBeanList); Map<Integer, SortedMap<Integer, Map<Integer, HistoryValues>>> workItemsHistoryValuesMap = new HashMap<Integer, SortedMap<Integer, Map<Integer, HistoryValues>>>(); Set<Integer> pseudoHistoryFields = getPseudoHistoryFields(); for (Map.Entry<Integer, Map<Integer, Map<String, Object>>> entry : workItemsFieldChangeBeansMap .entrySet()) { Integer workItemID = entry.getKey(); Map<Integer, Map<String, Object>> workItemFieldChangeBeansMap = entry.getValue(); Map<Integer, Integer> issueTypeFieldRestrictions = null; Integer projectID = null; Integer issueTypeID = null; if (fieldRestrictions != null && workItemBeansMap != null) { TWorkItemBean workItemBean = workItemBeansMap.get(workItemID); if (workItemBean != null) { projectID = workItemBean.getProjectID(); issueTypeID = workItemBean.getListTypeID(); Map<Integer, Map<Integer, Integer>> projectFieldRestrictions = fieldRestrictions.get(projectID); if (projectFieldRestrictions != null) { issueTypeFieldRestrictions = projectFieldRestrictions.get(issueTypeID); } } } for (Map.Entry<Integer, Map<String, Object>> itemEntry : workItemFieldChangeBeansMap.entrySet()) { Integer historyTransactionID = itemEntry.getKey(); Map<String, Object> transactionFieldChangeBeansMap = itemEntry.getValue(); Iterator<String> mergeKeysIterator = transactionFieldChangeBeansMap.keySet().iterator(); Map<String, Object> newValuesHistoryMap = new HashMap<String, Object>(); Map<String, Object> oldValuesHistoryMap = new HashMap<String, Object>(); while (mergeKeysIterator.hasNext()) { String mergeKey = mergeKeysIterator.next(); Integer[] parts = MergeUtil.getParts(mergeKey); Integer fieldKey = parts[0]; if (issueTypeFieldRestrictions != null && issueTypeFieldRestrictions.containsKey(fieldKey)) { LOGGER.debug("Field " + fieldKey + " is hidden for person " + loggedPersonID + " in project " + projectID + " and issueType " + issueTypeID); continue; } Integer parameterCode = parts[1]; if (parameterCode == null || parameterCode.intValue() == 1) { //execute for simple fields and one times for the composite fields (not for each part) IFieldTypeRT fieldTypeRT = null; if (pseudoHistoryFields.contains(fieldKey)) { //load the Compound and Attachment fields the same as Description (longText) fieldTypeRT = FieldTypeManager.getFieldTypeRT(SystemFields.INTEGER_DESCRIPTION); } else { fieldTypeRT = FieldTypeManager.getFieldTypeRT(fieldKey); } if (fieldTypeRT == null) { LOGGER.warn("Fieldtype unknown for field " + fieldKey); continue; } fieldTypeRT.processHistoryLoad(fieldKey, null, transactionFieldChangeBeansMap, newValuesHistoryMap, oldValuesHistoryMap); SortedMap<Integer, Map<Integer, HistoryValues>> workItemHistoryValuesMap = workItemsHistoryValuesMap .get(workItemID); if (workItemHistoryValuesMap == null) { workItemHistoryValuesMap = new TreeMap<Integer, Map<Integer, HistoryValues>>(); workItemsHistoryValuesMap.put(workItemID, workItemHistoryValuesMap); } Map<Integer, HistoryValues> historyTransactionMap = workItemHistoryValuesMap .get(historyTransactionID); if (historyTransactionMap == null) { historyTransactionMap = new TreeMap<Integer, HistoryValues>(); workItemHistoryValuesMap.put(historyTransactionID, historyTransactionMap); } HistoryValues historyValues = initHistoryValues( historyTransactionBeanMap.get(historyTransactionID)); historyValues.setDate(fieldTypeRT.getValueType() == ValueType.DATE || fieldTypeRT.getValueType() == ValueType.DATETIME); historyValues.setObjectID(getFirstFieldChangeID(fieldKey, parameterCode, transactionFieldChangeBeansMap.get(mergeKey))); historyValues.setTimesEdited( getTimesEdited(fieldKey, transactionFieldChangeBeansMap.get(mergeKey))); historyValues.setTransactionID(historyTransactionID); historyValues.setFieldID(fieldKey); historyValues.setLongField(fieldTypeRT.isLong()); if (isISO) { TFieldBean fieldBean = fieldsMap.get(fieldKey); if (fieldBean != null) { historyValues.setFieldName(fieldBean.getName()); } else { if (pseudoHistoryFields.contains(fieldKey)) { historyValues .setFieldName(LocalizeUtil.getLocalizedTextFromApplicationResources( getHistoryFieldKey(fieldKey), Locale.ENGLISH)); } } } else { String fieldConfigLabel = fieldConfigLabelsMap.get(fieldKey); if (fieldConfigLabel != null) { historyValues.setFieldName(fieldConfigLabel); } else { if (pseudoHistoryFields.contains(fieldKey)) { historyValues .setFieldName(LocalizeUtil.getLocalizedTextFromApplicationResources( getHistoryFieldKey(fieldKey), locale)); } } } Object newValue = getAttribute(newValuesHistoryMap, fieldKey, fieldTypeRT); Object oldValue = getAttribute(oldValuesHistoryMap, fieldKey, fieldTypeRT); historyValues.setNewValue(newValue); historyValues.setOldValue(oldValue); if (fieldTypeRT.isLong() && (longTextIsPlain == LONG_TEXT_TYPE.ISPLAIN || longTextIsPlain == LONG_TEXT_TYPE.ISFULLHTML)) { if (longTextIsPlain == LONG_TEXT_TYPE.ISPLAIN) { try { historyValues .setNewShowValue(Html2Text.getNewInstance().convert((String) newValue)); } catch (Exception e) { LOGGER.info("Transforming the new HTML value to plain text for workItemID " + workItemID + " and field " + fieldKey + " failed with " + e); } try { historyValues .setOldShowValue(Html2Text.getNewInstance().convert((String) oldValue)); } catch (Exception e) { LOGGER.info("Transforming the old HTML value to plain text for workItemID " + workItemID + " and field " + fieldKey + " failed with " + e); } } else { //leave the full HTML as it is historyValues.setNewShowValue((String) newValue); historyValues.setOldShowValue((String) oldValue); } //historyValues.setFieldName(""); } else { String newShowValue; String oldShowValue; if (isISO) { newShowValue = fieldTypeRT.getShowISOValue(fieldKey, null, newValue, workItemID, localLookupContainer, locale); oldShowValue = fieldTypeRT.getShowISOValue(fieldKey, null, oldValue, workItemID, localLookupContainer, locale); } else { //item hierarchy container may be null because changing the //fields depending on that (wbs or project specific ID) is not historized newShowValue = fieldTypeRT.getShowValue(fieldKey, null, newValue, workItemID, null, locale); oldShowValue = fieldTypeRT.getShowValue(fieldKey, null, oldValue, workItemID, null, locale); } historyValues.setNewShowValue(newShowValue); historyValues.setOldShowValue(oldShowValue); } historyTransactionMap.put(fieldKey, historyValues); } } } } if (LOGGER.isDebugEnabled() && loadingHistoryData != null) { populatingHistoryData = new Date(); LOGGER.debug("Populating the history values for " + " ReportBeanWithHistory lasted " + Long.toString(populatingHistoryData.getTime() - loadingHistoryData.getTime()) + " ms"); } return workItemsHistoryValuesMap; }