List of usage examples for java.lang Float Float
@Deprecated(since = "9") public Float(String s) throws NumberFormatException
From source file:TypeConversionHelper.java
/** * Convert a byte[] into an instance of our value class. * @param buf byte array to be converted * @return converted Float array as object *//*from w w w .java 2 s. c om*/ public static Object getFloatObjectArrayFromByteArray(byte[] buf) { float[] d = (float[]) getFloatArrayFromByteArray(buf); Float[] a = new Float[d.length]; for (int i = 0; i < a.length; i++) { a[i] = new Float(d[i]); } return a; }
From source file:net.sf.json.TestJSONObject.java
public void testFromBean_use_wrappers() { JSONObject json = JSONObject.fromObject(Boolean.TRUE); assertTrue(json.isEmpty());//from w ww . jav a 2 s .com json = JSONObject.fromObject(new Byte(Byte.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Short(Short.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Integer(Integer.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Long(Long.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Float(Float.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Double(Double.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Character('A')); assertTrue(json.isEmpty()); }
From source file:edu.snu.leader.discrete.simulator.SimulatorLauncherGUI.java
/** * Create the frame./*from w ww.j a v a 2 s.com*/ */ public SimulatorLauncherGUI() { NumberFormat countFormat = NumberFormat.getNumberInstance(); countFormat.setParseIntegerOnly(true); NumberFormat doubleFormat = NumberFormat.getNumberInstance(); doubleFormat.setMinimumIntegerDigits(1); doubleFormat.setMaximumFractionDigits(10); setTitle("Simulator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 515, 340); setResizable(false); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); tabbedPane = new JTabbedPane(JTabbedPane.TOP); contentPane.add(tabbedPane, BorderLayout.CENTER); JPanel panelTab1 = new JPanel(); tabbedPane.addTab("Simulator", null, panelTab1, null); JPanel panelAgentCount = new JPanel(); panelTab1.add(panelAgentCount); JLabel lblNewLabel = new JLabel("Agent Count"); panelAgentCount.add(lblNewLabel); sliderAgent = new JSlider(); panelAgentCount.add(sliderAgent); sliderAgent.setValue(10); sliderAgent.setSnapToTicks(true); sliderAgent.setPaintTicks(true); sliderAgent.setPaintLabels(true); sliderAgent.setMinorTickSpacing(10); sliderAgent.setMajorTickSpacing(10); sliderAgent.setMinimum(10); sliderAgent.setMaximum(70); sliderAgent.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { Integer spinnerValue = (Integer) spinnerMaxEaten.getValue(); if (spinnerValue > sliderAgent.getValue()) { spinnerValue = sliderAgent.getValue(); } spinnerMaxEaten.setModel(new SpinnerNumberModel(spinnerValue, new Integer(0), new Integer(sliderAgent.getValue()), new Integer(1))); JFormattedTextField tfMaxEaten = ((JSpinner.DefaultEditor) spinnerMaxEaten.getEditor()) .getTextField(); tfMaxEaten.setEditable(false); } }); JPanel panelCommType = new JPanel(); panelTab1.add(panelCommType); JLabel lblNewLabel_1 = new JLabel("Communication Type"); panelCommType.add(lblNewLabel_1); comboBoxCommType = new JComboBox<String>(); panelCommType.add(comboBoxCommType); comboBoxCommType .setModel(new DefaultComboBoxModel<String>(new String[] { "Global", "Topological", "Metric" })); comboBoxCommType.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { String item = (String) comboBoxCommType.getSelectedItem(); if (item.equals("Topological")) { panelNearestNeighborCount.setVisible(true); panelMaxLocationRadius.setVisible(false); } else if (item.equals("Metric")) { panelNearestNeighborCount.setVisible(false); panelMaxLocationRadius.setVisible(true); } else if (item.equals("Global")) { panelNearestNeighborCount.setVisible(false); panelMaxLocationRadius.setVisible(false); } } }); JPanel panelDestinationRadius = new JPanel(); panelTab1.add(panelDestinationRadius); JLabel lblDestinationRadius = new JLabel("Destination Radius"); panelDestinationRadius.add(lblDestinationRadius); frmtdtxtfldDestinationRadius = new JFormattedTextField(doubleFormat); frmtdtxtfldDestinationRadius.setColumns(4); frmtdtxtfldDestinationRadius.setValue((Number) 10); panelDestinationRadius.add(frmtdtxtfldDestinationRadius); JPanel panelResultsOutput = new JPanel(); panelTab1.add(panelResultsOutput); JLabel lblResultsOutput = new JLabel("Results Output"); panelResultsOutput.add(lblResultsOutput); final JCheckBox chckbxEskridge = new JCheckBox("Eskridge"); panelResultsOutput.add(chckbxEskridge); final JCheckBox chckbxConflict = new JCheckBox("Conflict"); panelResultsOutput.add(chckbxConflict); final JCheckBox chckbxPosition = new JCheckBox("Position"); panelResultsOutput.add(chckbxPosition); final JCheckBox chckbxPredationResults = new JCheckBox("Predation"); panelResultsOutput.add(chckbxPredationResults); JPanel panelMisc = new JPanel(); panelTab1.add(panelMisc); JLabel lblNewLabel_3 = new JLabel("Misc"); panelMisc.add(lblNewLabel_3); chckbxGraphical = new JCheckBox("Graphical?"); chckbxGraphical.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (chckbxGraphical.isSelected()) { frmtdtxtfldRunCount.setValue((Number) 1); frmtdtxtfldRunCount.setEnabled(false); chckbxEskridge.setSelected(false); chckbxEskridge.setEnabled(false); String agentBuilder = (String) comboBoxAgentBuilder.getSelectedItem(); if (agentBuilder.equals("Default")) { comboBoxAgentBuilder.setSelectedIndex(1); } } else { chckbxEskridge.setEnabled(true); frmtdtxtfldRunCount.setEnabled(true); } } }); panelMisc.add(chckbxGraphical); chckbxRandomSeed = new JCheckBox("Random Seed?"); panelMisc.add(chckbxRandomSeed); chckbxPredationEnable = new JCheckBox("Predation?"); chckbxPredationEnable.setSelected(true); chckbxPredationEnable.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (chckbxPredationEnable.isSelected()) { panelPredationStuff.setVisible(true); panelPredationBoxes.setVisible(true); panelPredationConstant.setVisible(true); panelNonMoversSurvive.setVisible(true); } else { panelPredationStuff.setVisible(false); panelPredationBoxes.setVisible(false); panelPredationConstant.setVisible(false); panelNonMoversSurvive.setVisible(false); } } }); panelMisc.add(chckbxPredationEnable); JPanel panelCounts = new JPanel(); panelTab1.add(panelCounts); JLabel lblNewLabel_4 = new JLabel("Run Count"); panelCounts.add(lblNewLabel_4); frmtdtxtfldRunCount = new JFormattedTextField(countFormat); frmtdtxtfldRunCount.setToolTipText("The number of runs. Each run has a different random seed."); panelCounts.add(frmtdtxtfldRunCount); frmtdtxtfldRunCount.setColumns(4); frmtdtxtfldRunCount.setValue((Number) 1); JLabel lblNewLabel_5 = new JLabel("Sim Count"); panelCounts.add(lblNewLabel_5); frmtdtxtfldSimCount = new JFormattedTextField(countFormat); frmtdtxtfldSimCount .setToolTipText("The number of simulations per run. Each simulation uses the same random seed."); frmtdtxtfldSimCount.setColumns(4); frmtdtxtfldSimCount.setValue((Number) 1); panelCounts.add(frmtdtxtfldSimCount); JLabel lblNewLabel_6 = new JLabel("Max Time Steps"); panelCounts.add(lblNewLabel_6); frmtdtxtfldMaxTimeSteps = new JFormattedTextField(countFormat); frmtdtxtfldMaxTimeSteps.setToolTipText("The max number of time steps per simulation."); frmtdtxtfldMaxTimeSteps.setColumns(6); frmtdtxtfldMaxTimeSteps.setValue((Number) 20000); panelCounts.add(frmtdtxtfldMaxTimeSteps); ////////Panel tab 2 JPanel panelTab2 = new JPanel(); tabbedPane.addTab("Parameters", null, panelTab2, null); JPanel panelDecisionCalculator = new JPanel(); panelTab2.add(panelDecisionCalculator); JLabel lblDecisionCalculator = new JLabel("Decision Calculator"); panelDecisionCalculator.add(lblDecisionCalculator); final JComboBox<String> comboBoxDecisionCalculator = new JComboBox<String>(); panelDecisionCalculator.add(comboBoxDecisionCalculator); comboBoxDecisionCalculator.setModel( new DefaultComboBoxModel<String>(new String[] { "Default", "Conflict", "Conflict Uninformed" })); JPanel panelAgentBuilder = new JPanel(); panelTab2.add(panelAgentBuilder); JLabel lblAgentBuilder = new JLabel("Agent Builder"); panelAgentBuilder.add(lblAgentBuilder); comboBoxAgentBuilder = new JComboBox<String>(); panelAgentBuilder.add(comboBoxAgentBuilder); comboBoxAgentBuilder.setModel(new DefaultComboBoxModel<String>(new String[] { "Default", "Simple Angular", "Personality Simple Angular", "Simple Angular Uninformed" })); comboBoxAgentBuilder.setSelectedIndex(1); comboBoxAgentBuilder.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (chckbxGraphical.isSelected()) { String agentBuilder = (String) comboBoxAgentBuilder.getSelectedItem(); if (agentBuilder.equals("Default")) { comboBoxAgentBuilder.setSelectedIndex(1); } } } }); JPanel panelModel = new JPanel(); panelTab2.add(panelModel); JLabel lblModel = new JLabel("Model"); panelModel.add(lblModel); comboBoxModel = new JComboBox<String>(); panelModel.add(comboBoxModel); comboBoxModel.setModel(new DefaultComboBoxModel<String>(new String[] { "Sueur", "Gautrais" })); comboBoxModel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { String item = (String) comboBoxModel.getSelectedItem(); if (item.equals("Sueur")) { panelSueurValues.setVisible(true); panelGautraisValues.setVisible(false); } else if (item.equals("Gautrais")) { panelSueurValues.setVisible(false); panelGautraisValues.setVisible(true); } } }); JPanel panelEnvironment = new JPanel(); panelTab2.add(panelEnvironment); JLabel lblEnvironment = new JLabel("Environment"); panelEnvironment.add(lblEnvironment); comboBoxEnvironment = new JComboBox<String>(); comboBoxEnvironment.setModel( new DefaultComboBoxModel<String>(new String[] { "Minimum", "Medium", "Maximum", "Uninformed" })); comboBoxEnvironment.setSelectedIndex(1); comboBoxEnvironment.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { String item = (String) comboBoxEnvironment.getSelectedItem(); if (!item.equals("Uninformed")) { comboBoxDecisionCalculator.setEnabled(true); comboBoxAgentBuilder.setEnabled(true); } if (item.equals("Medium")) { panelAngle.setVisible(true); panelDistance.setVisible(true); panelPercentage.setVisible(true); panelNumberOfDestinations.setVisible(false); panelInformedCount.setVisible(false); } else if (item.equals("Minimum")) { panelAngle.setVisible(false); panelDistance.setVisible(false); panelPercentage.setVisible(true); panelNumberOfDestinations.setVisible(false); panelInformedCount.setVisible(false); } else if (item.equals("Maximum")) { panelAngle.setVisible(false); panelDistance.setVisible(false); panelPercentage.setVisible(true); panelNumberOfDestinations.setVisible(false); panelInformedCount.setVisible(false); } else if (item.equals("Uninformed")) { panelAngle.setVisible(true); panelDistance.setVisible(true); panelPercentage.setVisible(true); panelNumberOfDestinations.setVisible(false); panelInformedCount.setVisible(true); comboBoxDecisionCalculator.setSelectedIndex(2); comboBoxDecisionCalculator.setEnabled(false); comboBoxAgentBuilder.setSelectedIndex(3); comboBoxAgentBuilder.setEnabled(false); } } }); panelEnvironment.add(comboBoxEnvironment); JPanel panelDefaultConflict = new JPanel(); panelTab2.add(panelDefaultConflict); JLabel lblDefaultConflict = new JLabel("Default Conflict"); panelDefaultConflict.add(lblDefaultConflict); final JSpinner spinnerDefaultConflict = new JSpinner(); panelDefaultConflict.add(spinnerDefaultConflict); spinnerDefaultConflict.setModel( new SpinnerNumberModel(new Float(0.9f), new Float(0.1f), new Float(0.91f), new Float(0.05))); JFormattedTextField tfSpinnerConflict = ((JSpinner.DefaultEditor) spinnerDefaultConflict.getEditor()) .getTextField(); tfSpinnerConflict.setEditable(false); JPanel panelCancelationThreshold = new JPanel(); panelTab2.add(panelCancelationThreshold); JLabel lblCancelationThreshold = new JLabel("Cancelation Threshold"); panelCancelationThreshold.add(lblCancelationThreshold); final JSpinner spinnerCancelationThreshold = new JSpinner(); panelCancelationThreshold.add(spinnerCancelationThreshold); spinnerCancelationThreshold.setModel( new SpinnerNumberModel(new Float(1.0f), new Float(0.0f), new Float(1.01f), new Float(0.05))); JFormattedTextField tfCancelationThreshold = ((JSpinner.DefaultEditor) spinnerCancelationThreshold .getEditor()).getTextField(); tfCancelationThreshold.setEditable(false); JPanel panelStopAnywhere = new JPanel(); panelTab2.add(panelStopAnywhere); final JCheckBox chckbxStopAnywhere = new JCheckBox("Stop Anywhere?"); panelStopAnywhere.add(chckbxStopAnywhere); panelNearestNeighborCount = new JPanel(); panelNearestNeighborCount.setVisible(false); panelTab2.add(panelNearestNeighborCount); JLabel lblNearestNeighborCount = new JLabel("Nearest Neighbor Count"); panelNearestNeighborCount.add(lblNearestNeighborCount); frmtdtxtfldNearestNeighborCount = new JFormattedTextField(countFormat); panelNearestNeighborCount.add(frmtdtxtfldNearestNeighborCount); frmtdtxtfldNearestNeighborCount.setColumns(3); frmtdtxtfldNearestNeighborCount.setValue((Number) 10); panelMaxLocationRadius = new JPanel(); panelMaxLocationRadius.setVisible(false); panelTab2.add(panelMaxLocationRadius); JLabel lblMaxLocationRadius = new JLabel("Max Location Radius"); panelMaxLocationRadius.add(lblMaxLocationRadius); frmtdtxtfldMaxLocationRadius = new JFormattedTextField(doubleFormat); panelMaxLocationRadius.add(frmtdtxtfldMaxLocationRadius); frmtdtxtfldMaxLocationRadius.setColumns(5); frmtdtxtfldMaxLocationRadius.setValue((Number) 10.0); panelPredationBoxes = new JPanel(); panelTab2.add(panelPredationBoxes); final JCheckBox chckbxUsePredationThreshold = new JCheckBox("Use Predation Threshold"); panelPredationBoxes.add(chckbxUsePredationThreshold); final JCheckBox chckbxPopulationIndependent = new JCheckBox("Population Independent"); chckbxPopulationIndependent.setSelected(true); panelPredationBoxes.add(chckbxPopulationIndependent); chckbxPopulationIndependent.setToolTipText( "Select this to allow predation to be independent of population size. Max predation for 10 agents will be the same as for 50 agents. "); panelPredationStuff = new JPanel(); panelTab2.add(panelPredationStuff); JLabel lblPredationMinimum = new JLabel("Predation Minimum"); panelPredationStuff.add(lblPredationMinimum); frmtdtxtfldPredationMinimum = new JFormattedTextField(doubleFormat); frmtdtxtfldPredationMinimum.setColumns(4); frmtdtxtfldPredationMinimum.setValue((Number) 0.0); panelPredationStuff.add(frmtdtxtfldPredationMinimum); JLabel lblPredationThreshold = new JLabel("Predation Threshold"); panelPredationStuff.add(lblPredationThreshold); final JSpinner spinnerPredationThreshold = new JSpinner(); panelPredationStuff.add(spinnerPredationThreshold); spinnerPredationThreshold.setModel( new SpinnerNumberModel(new Float(1.0f), new Float(0.0f), new Float(1.01f), new Float(0.05))); JFormattedTextField tfPredationThreshold = ((JSpinner.DefaultEditor) spinnerPredationThreshold.getEditor()) .getTextField(); tfPredationThreshold.setEditable(false); JLabel lblMaxEaten = new JLabel("Max Eaten"); panelPredationStuff.add(lblMaxEaten); spinnerMaxEaten = new JSpinner(); spinnerMaxEaten.setToolTipText("The max number eaten per time step."); panelPredationStuff.add(spinnerMaxEaten); spinnerMaxEaten.setModel(new SpinnerNumberModel(new Integer(10), new Integer(0), new Integer(sliderAgent.getValue()), new Integer(1))); JFormattedTextField tfMaxEaten = ((JSpinner.DefaultEditor) spinnerMaxEaten.getEditor()).getTextField(); tfMaxEaten.setEditable(false); panelPredationConstant = new JPanel(); panelTab2.add(panelPredationConstant); JLabel lblPredationConstant = new JLabel("Predation Constant"); panelPredationConstant.add(lblPredationConstant); frmtdtxtfldPredationConstant = new JFormattedTextField(doubleFormat); panelPredationConstant.add(frmtdtxtfldPredationConstant); frmtdtxtfldPredationConstant.setToolTipText("Value should be positive. Recommended values are near 0.001"); frmtdtxtfldPredationConstant.setColumns(4); frmtdtxtfldPredationConstant.setValue((Number) 0.001); panelNonMoversSurvive = new JPanel(); panelTab2.add(panelNonMoversSurvive); final JCheckBox chckbxNonMoversSurvive = new JCheckBox("Non-movers Survive?"); chckbxNonMoversSurvive.setSelected(false); panelNonMoversSurvive.add(chckbxNonMoversSurvive); ////////Tab 3 JPanel panelTab3 = new JPanel(); tabbedPane.addTab("Environment", null, panelTab3, null); panelTab3.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); panelSueurValues = new JPanel(); panelTab3.add(panelSueurValues); panelSueurValues.setLayout(new BoxLayout(panelSueurValues, BoxLayout.Y_AXIS)); JLabel lblSueurValues = new JLabel("Sueur Values"); lblSueurValues.setHorizontalAlignment(SwingConstants.TRAILING); lblSueurValues.setAlignmentX(Component.CENTER_ALIGNMENT); panelSueurValues.add(lblSueurValues); JPanel panelAlpha = new JPanel(); FlowLayout flowLayout = (FlowLayout) panelAlpha.getLayout(); flowLayout.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelAlpha); JLabel lblAlpha = new JLabel("alpha"); lblAlpha.setHorizontalAlignment(SwingConstants.CENTER); panelAlpha.add(lblAlpha); final JFormattedTextField frmtdtxtfldAlpha = new JFormattedTextField(doubleFormat); frmtdtxtfldAlpha.setHorizontalAlignment(SwingConstants.TRAILING); lblAlpha.setLabelFor(frmtdtxtfldAlpha); panelAlpha.add(frmtdtxtfldAlpha); frmtdtxtfldAlpha.setColumns(6); frmtdtxtfldAlpha.setValue((Number) 0.006161429); JPanel panelAlphaC = new JPanel(); FlowLayout flowLayout_2 = (FlowLayout) panelAlphaC.getLayout(); flowLayout_2.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelAlphaC); JLabel lblAlphaC = new JLabel("alpha c"); panelAlphaC.add(lblAlphaC); final JFormattedTextField frmtdtxtfldAlphaC = new JFormattedTextField(doubleFormat); frmtdtxtfldAlphaC.setHorizontalAlignment(SwingConstants.TRAILING); lblAlphaC.setLabelFor(frmtdtxtfldAlphaC); panelAlphaC.add(frmtdtxtfldAlphaC); frmtdtxtfldAlphaC.setColumns(6); frmtdtxtfldAlphaC.setValue((Number) 0.009); JPanel panelBeta = new JPanel(); FlowLayout flowLayout_1 = (FlowLayout) panelBeta.getLayout(); flowLayout_1.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelBeta); JLabel lblBeta = new JLabel("beta"); panelBeta.add(lblBeta); final JFormattedTextField frmtdtxtfldBeta = new JFormattedTextField(doubleFormat); frmtdtxtfldBeta.setHorizontalAlignment(SwingConstants.TRAILING); panelBeta.add(frmtdtxtfldBeta); frmtdtxtfldBeta.setColumns(6); frmtdtxtfldBeta.setValue((Number) 0.013422819); JPanel panelBetaC = new JPanel(); FlowLayout flowLayout_14 = (FlowLayout) panelBetaC.getLayout(); flowLayout_14.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelBetaC); JLabel lblBetaC = new JLabel("beta c"); panelBetaC.add(lblBetaC); final JFormattedTextField frmtdtxtfldBetaC = new JFormattedTextField(doubleFormat); frmtdtxtfldBetaC.setHorizontalAlignment(SwingConstants.TRAILING); panelBetaC.add(frmtdtxtfldBetaC); frmtdtxtfldBetaC.setColumns(6); frmtdtxtfldBetaC.setValue((Number) (-0.009)); JPanel panelS = new JPanel(); FlowLayout flowLayout_3 = (FlowLayout) panelS.getLayout(); flowLayout_3.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelS); JLabel lblS = new JLabel("S"); panelS.add(lblS); final JFormattedTextField frmtdtxtfldS = new JFormattedTextField(countFormat); frmtdtxtfldS.setHorizontalAlignment(SwingConstants.TRAILING); panelS.add(frmtdtxtfldS); frmtdtxtfldS.setColumns(6); frmtdtxtfldS.setValue((Number) 2); JPanel panelQ = new JPanel(); FlowLayout flowLayout_4 = (FlowLayout) panelQ.getLayout(); flowLayout_4.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelQ); JLabel lblQ = new JLabel("q"); panelQ.add(lblQ); final JFormattedTextField frmtdtxtfldQ = new JFormattedTextField(doubleFormat); frmtdtxtfldQ.setHorizontalAlignment(SwingConstants.TRAILING); panelQ.add(frmtdtxtfldQ); frmtdtxtfldQ.setColumns(6); frmtdtxtfldQ.setValue((Number) 2.3); panelGautraisValues = new JPanel(); panelGautraisValues.setVisible(false); panelTab3.add(panelGautraisValues); panelGautraisValues.setLayout(new BoxLayout(panelGautraisValues, BoxLayout.Y_AXIS)); JLabel label = new JLabel("Gautrais Values"); label.setAlignmentX(Component.CENTER_ALIGNMENT); panelGautraisValues.add(label); JPanel panelTauO = new JPanel(); FlowLayout flowLayout_5 = (FlowLayout) panelTauO.getLayout(); flowLayout_5.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelTauO); JLabel lblTauO = new JLabel("tau o"); panelTauO.add(lblTauO); final JFormattedTextField frmtdtxtfldTaoO = new JFormattedTextField(doubleFormat); frmtdtxtfldTaoO.setHorizontalAlignment(SwingConstants.TRAILING); panelTauO.add(frmtdtxtfldTaoO); frmtdtxtfldTaoO.setColumns(4); frmtdtxtfldTaoO.setValue((Number) 1290); JPanel panelGammaC = new JPanel(); FlowLayout flowLayout_6 = (FlowLayout) panelGammaC.getLayout(); flowLayout_6.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelGammaC); JLabel lblGammaC = new JLabel("gamma c"); panelGammaC.add(lblGammaC); final JFormattedTextField frmtdtxtfldGammaC = new JFormattedTextField(doubleFormat); frmtdtxtfldGammaC.setHorizontalAlignment(SwingConstants.TRAILING); panelGammaC.add(frmtdtxtfldGammaC); frmtdtxtfldGammaC.setColumns(4); frmtdtxtfldGammaC.setValue((Number) 2.0); JPanel panelEpsilonC = new JPanel(); FlowLayout flowLayout_7 = (FlowLayout) panelEpsilonC.getLayout(); flowLayout_7.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelEpsilonC); JLabel lblEpsilonC = new JLabel("epsilon c"); panelEpsilonC.add(lblEpsilonC); final JFormattedTextField frmtdtxtfldEpsilonC = new JFormattedTextField(doubleFormat); frmtdtxtfldEpsilonC.setHorizontalAlignment(SwingConstants.TRAILING); panelEpsilonC.add(frmtdtxtfldEpsilonC); frmtdtxtfldEpsilonC.setColumns(4); frmtdtxtfldEpsilonC.setValue((Number) 2.3); JPanel panelAlphaF = new JPanel(); FlowLayout flowLayout_8 = (FlowLayout) panelAlphaF.getLayout(); flowLayout_8.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelAlphaF); JLabel lblAlphaF = new JLabel("alpha f"); panelAlphaF.add(lblAlphaF); final JFormattedTextField frmtdtxtfldAlphaF = new JFormattedTextField(doubleFormat); frmtdtxtfldAlphaF.setHorizontalAlignment(SwingConstants.TRAILING); panelAlphaF.add(frmtdtxtfldAlphaF); frmtdtxtfldAlphaF.setColumns(4); frmtdtxtfldAlphaF.setValue((Number) 162.3); JPanel panelBetaF = new JPanel(); FlowLayout flowLayout_9 = (FlowLayout) panelBetaF.getLayout(); flowLayout_9.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelBetaF); JLabel lblBetaF = new JLabel("beta f"); panelBetaF.add(lblBetaF); final JFormattedTextField frmtdtxtfldBetaF = new JFormattedTextField(doubleFormat); frmtdtxtfldBetaF.setHorizontalAlignment(SwingConstants.TRAILING); panelBetaF.add(frmtdtxtfldBetaF); frmtdtxtfldBetaF.setColumns(4); frmtdtxtfldBetaF.setValue((Number) 75.4); JPanel panelEnvironmentVariables = new JPanel(); panelTab3.add(panelEnvironmentVariables); panelEnvironmentVariables.setLayout(new BoxLayout(panelEnvironmentVariables, BoxLayout.Y_AXIS)); JLabel lblEnvironmentVariables = new JLabel("Environment Variables"); lblEnvironmentVariables.setAlignmentX(Component.CENTER_ALIGNMENT); panelEnvironmentVariables.add(lblEnvironmentVariables); panelAngle = new JPanel(); FlowLayout flowLayout_10 = (FlowLayout) panelAngle.getLayout(); flowLayout_10.setAlignment(FlowLayout.RIGHT); panelEnvironmentVariables.add(panelAngle); JLabel lblAngle = new JLabel("Angle"); panelAngle.add(lblAngle); final JFormattedTextField frmtdtxtfldAngle = new JFormattedTextField(doubleFormat); frmtdtxtfldAngle.setHorizontalAlignment(SwingConstants.TRAILING); frmtdtxtfldAngle.setToolTipText("Angle between destinations"); panelAngle.add(frmtdtxtfldAngle); frmtdtxtfldAngle.setColumns(3); frmtdtxtfldAngle.setValue((Number) 72.00); panelNumberOfDestinations = new JPanel(); FlowLayout flowLayout_13 = (FlowLayout) panelNumberOfDestinations.getLayout(); flowLayout_13.setAlignment(FlowLayout.RIGHT); panelNumberOfDestinations.setVisible(false); panelEnvironmentVariables.add(panelNumberOfDestinations); JLabel lblNumberOfDestinations = new JLabel("Number of Destinations"); panelNumberOfDestinations.add(lblNumberOfDestinations); JFormattedTextField frmtdtxtfldNumberOfDestinations = new JFormattedTextField(countFormat); frmtdtxtfldNumberOfDestinations.setHorizontalAlignment(SwingConstants.TRAILING); panelNumberOfDestinations.add(frmtdtxtfldNumberOfDestinations); frmtdtxtfldNumberOfDestinations.setColumns(3); frmtdtxtfldNumberOfDestinations.setValue((Number) 2); panelDistance = new JPanel(); FlowLayout flowLayout_11 = (FlowLayout) panelDistance.getLayout(); flowLayout_11.setAlignment(FlowLayout.RIGHT); panelEnvironmentVariables.add(panelDistance); JLabel lblDistance = new JLabel("Distance"); panelDistance.add(lblDistance); frmtdtxtfldDistance = new JFormattedTextField(doubleFormat); frmtdtxtfldDistance.setHorizontalAlignment(SwingConstants.TRAILING); frmtdtxtfldDistance.setToolTipText("Distance the destination is from origin (0,0)"); panelDistance.add(frmtdtxtfldDistance); frmtdtxtfldDistance.setColumns(3); frmtdtxtfldDistance.setValue((Number) 150.0); panelPercentage = new JPanel(); FlowLayout flowLayout_12 = (FlowLayout) panelPercentage.getLayout(); flowLayout_12.setAlignment(FlowLayout.RIGHT); panelEnvironmentVariables.add(panelPercentage); JLabel lblPercentage = new JLabel("Percentage"); panelPercentage.add(lblPercentage); frmtdtxtfldPercentage = new JFormattedTextField(doubleFormat); frmtdtxtfldPercentage.setHorizontalAlignment(SwingConstants.TRAILING); frmtdtxtfldPercentage.setToolTipText( "The percentage moving to one of the two destinations ( The other gets 1 - percentage)."); panelPercentage.add(frmtdtxtfldPercentage); frmtdtxtfldPercentage.setColumns(3); frmtdtxtfldPercentage.setValue((Number) 0.500); panelInformedCount = new JPanel(); panelEnvironmentVariables.add(panelInformedCount); JLabel lblInformedCount = new JLabel("Informed Count"); panelInformedCount.add(lblInformedCount); final JFormattedTextField frmtdtxtfldInformedCount = new JFormattedTextField(countFormat); frmtdtxtfldInformedCount.setHorizontalAlignment(SwingConstants.TRAILING); frmtdtxtfldInformedCount.setColumns(3); frmtdtxtfldInformedCount.setToolTipText( "The number of agents moving toward a preferred destination. This number is duplicated on the southern pole as well."); frmtdtxtfldInformedCount.setValue((Number) 4); panelInformedCount.setVisible(false); panelInformedCount.add(frmtdtxtfldInformedCount); JPanel panelStartButtons = new JPanel(); JButton btnStartSimulation = new JButton("Create Simulator Instance"); btnStartSimulation.setToolTipText("Creates a new simulator instance from the settings provided."); btnStartSimulation.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean isReady = true; ErrorPacketContainer errorPacketContainer = new ErrorPacketContainer(); if (jframeErrorMessages != null && jframeErrorMessages.isVisible()) { jframeErrorMessages.dispose(); } frmtdtxtfldRunCount.setBackground(Color.WHITE); frmtdtxtfldSimCount.setBackground(Color.WHITE); frmtdtxtfldMaxTimeSteps.setBackground(Color.WHITE); frmtdtxtfldPredationMinimum.setBackground(Color.WHITE); frmtdtxtfldPredationConstant.setBackground(Color.WHITE); frmtdtxtfldNearestNeighborCount.setBackground(Color.WHITE); frmtdtxtfldMaxLocationRadius.setBackground(Color.WHITE); frmtdtxtfldPercentage.setBackground(Color.WHITE); frmtdtxtfldDistance.setBackground(Color.WHITE); frmtdtxtfldDestinationRadius.setBackground(Color.WHITE); frmtdtxtfldAngle.setBackground(Color.WHITE); frmtdtxtfldInformedCount.setBackground(Color.WHITE); StringBuilder errorMessages = new StringBuilder(); if (((Number) frmtdtxtfldRunCount.getValue()).intValue() <= 0) { errorMessages.append("Run Count must be positive\n"); frmtdtxtfldRunCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Run Count must be positive", frmtdtxtfldRunCount, 0); isReady = false; } if (((Number) frmtdtxtfldSimCount.getValue()).intValue() <= 0) { errorMessages.append("Sim Count must be positive\n"); frmtdtxtfldSimCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Sim Count must be positive", frmtdtxtfldSimCount, 0); isReady = false; } if (((Number) frmtdtxtfldMaxTimeSteps.getValue()).intValue() <= 0) { errorMessages.append("Max Time Steps must be positive\n"); frmtdtxtfldMaxTimeSteps.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Max Time Steps must be positive", frmtdtxtfldMaxTimeSteps, 0); isReady = false; } if (((Number) frmtdtxtfldPredationMinimum.getValue()).doubleValue() < 0 && chckbxPredationEnable.isSelected()) { errorMessages.append("Predation Minimum must be positive\n"); frmtdtxtfldPredationMinimum.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Predation Minimum must be positive", frmtdtxtfldPredationMinimum, 1); isReady = false; } if (((Number) frmtdtxtfldPredationConstant.getValue()).doubleValue() <= 0 && chckbxPredationEnable.isSelected()) { errorMessages.append("Predation Constant must be positive\n"); frmtdtxtfldPredationConstant.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Predation Constant must be positive", frmtdtxtfldPredationConstant, 1); isReady = false; } if (((Number) frmtdtxtfldNearestNeighborCount.getValue()).intValue() < 0 && panelNearestNeighborCount.isVisible()) { errorMessages.append("Nearest Neighbor Count must be positive\n"); frmtdtxtfldNearestNeighborCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Nearest Neighbor Count must be positive", frmtdtxtfldNearestNeighborCount, 1); isReady = false; } if (((Number) frmtdtxtfldMaxLocationRadius.getValue()).doubleValue() < 0 && panelMaxLocationRadius.isVisible()) { errorMessages.append("Max Location Radius must be positive\n"); frmtdtxtfldMaxLocationRadius.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Max Location Radius must be positive", frmtdtxtfldMaxLocationRadius, 1); isReady = false; } if ((((Number) frmtdtxtfldPercentage.getValue()).doubleValue() < 0.0 || ((Number) frmtdtxtfldPercentage.getValue()).doubleValue() > 1.0) && panelPercentage.isVisible()) { errorMessages.append( "Percentage needs to be greater than or equal to 0 and less than or equal to 1\n"); frmtdtxtfldPercentage.setBackground(Color.YELLOW); errorPacketContainer.addPacket( "Percentage needs to be greater than or equal to 0 and less than or equal to 1", frmtdtxtfldPercentage, 2); isReady = false; } if (((Number) frmtdtxtfldDistance.getValue()).doubleValue() <= 0 && frmtdtxtfldDistance.isVisible()) { errorMessages.append("Distance must be positive\n"); frmtdtxtfldDistance.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Distance must be positive", frmtdtxtfldDistance, 2); isReady = false; } if (((Number) frmtdtxtfldDestinationRadius.getValue()).doubleValue() <= 0) { errorMessages.append("Destination Radius must be positive\n"); frmtdtxtfldDestinationRadius.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Destination Radius must be positive", frmtdtxtfldDestinationRadius, 0); isReady = false; } if (((Number) frmtdtxtfldAngle.getValue()).doubleValue() < 0) { errorMessages.append("Angle must be positive or zero\n"); frmtdtxtfldAngle.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Angle must be positive", frmtdtxtfldAngle, 2); isReady = false; } if (((Number) frmtdtxtfldInformedCount.getValue()).intValue() <= 0) { errorMessages.append("Informed Count must be positive\n"); frmtdtxtfldInformedCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Informed Count must be positive", frmtdtxtfldInformedCount, 2); isReady = false; } else if (((Number) frmtdtxtfldInformedCount.getValue()).intValue() * 2 > sliderAgent.getValue()) { errorMessages.append("Informed Count should at most be half the count of total agents\n"); frmtdtxtfldInformedCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket( "Informed Count should at most be half the count of total agents", frmtdtxtfldInformedCount, 2); isReady = false; } if (!isReady) { jframeErrorMessages = createJFrameErrorMessages(errorPacketContainer, tabbedPane); jframeErrorMessages.setVisible(true); } else { _simulatorProperties = new Properties(); _simulatorProperties.put("run-count", String.valueOf(frmtdtxtfldRunCount.getValue())); _simulatorProperties.put("simulation-count", String.valueOf(frmtdtxtfldSimCount.getValue())); _simulatorProperties.put("max-simulation-time-steps", String.valueOf(frmtdtxtfldMaxTimeSteps.getValue())); _simulatorProperties.put("random-seed", String.valueOf(1)); // Doesn't change _simulatorProperties.put("individual-count", String.valueOf(sliderAgent.getValue())); _simulatorProperties.put("run-graphical", String.valueOf(chckbxGraphical.isSelected())); _simulatorProperties.put("pre-calculate-probabilities", String.valueOf(false)); // Doesn't change _simulatorProperties.put("use-random-random-seed", String.valueOf(chckbxRandomSeed.isSelected())); _simulatorProperties.put("can-multiple-initiate", String.valueOf(true)); // Doesn't change _simulatorProperties.put("eskridge-results", String.valueOf(chckbxEskridge.isSelected())); _simulatorProperties.put("conflict-results", String.valueOf(chckbxConflict.isSelected())); _simulatorProperties.put("position-results", String.valueOf(chckbxPosition.isSelected())); _simulatorProperties.put("predation-results", String.valueOf(chckbxPredationResults.isSelected())); _simulatorProperties.put("communication-type", String.valueOf(comboBoxCommType.getSelectedItem()).toLowerCase()); _simulatorProperties.put("nearest-neighbor-count", String.valueOf(frmtdtxtfldNearestNeighborCount.getValue())); _simulatorProperties.put("max-location-radius", String.valueOf(frmtdtxtfldMaxLocationRadius.getValue())); _simulatorProperties.put("destination-size-radius", String.valueOf(frmtdtxtfldDestinationRadius.getValue())); _simulatorProperties.put("max-agents-eaten-per-step", String.valueOf(spinnerMaxEaten.getValue())); _simulatorProperties.put("enable-predator", String.valueOf(chckbxPredationEnable.isSelected())); _simulatorProperties.put("predation-probability-minimum", String.valueOf(frmtdtxtfldPredationMinimum.getValue())); _simulatorProperties.put("predation-multiplier", String.valueOf(frmtdtxtfldPredationConstant.getValue())); _simulatorProperties.put("use-predation-threshold", String.valueOf(chckbxUsePredationThreshold.isSelected())); _simulatorProperties.put("predation-threshold", String.valueOf(spinnerPredationThreshold.getValue())); _simulatorProperties.put("predation-by-population", String.valueOf(chckbxPopulationIndependent.isSelected())); _simulatorProperties.put("count-non-movers-as-survivors", String.valueOf(chckbxNonMoversSurvive.isSelected())); _simulatorProperties.put("stop-at-any-destination", String.valueOf(chckbxStopAnywhere.isSelected())); _simulatorProperties.put("adhesion-time-limit", String.valueOf(frmtdtxtfldMaxTimeSteps.getValue())); _simulatorProperties.put("alpha", String.valueOf(frmtdtxtfldAlpha.getValue())); _simulatorProperties.put("alpha-c", String.valueOf(frmtdtxtfldAlphaC.getValue())); _simulatorProperties.put("beta", String.valueOf(frmtdtxtfldBeta.getValue())); _simulatorProperties.put("beta-c", String.valueOf(frmtdtxtfldBetaC.getValue())); _simulatorProperties.put("S", String.valueOf(frmtdtxtfldS.getValue())); _simulatorProperties.put("q", String.valueOf(frmtdtxtfldQ.getValue())); _simulatorProperties.put("lambda", String.valueOf(0.2)); _simulatorProperties.put("tau-o", String.valueOf(frmtdtxtfldTaoO.getValue())); _simulatorProperties.put("gamma-c", String.valueOf(frmtdtxtfldGammaC.getValue())); _simulatorProperties.put("epsilon-c", String.valueOf(frmtdtxtfldEpsilonC.getValue())); _simulatorProperties.put("alpha-f", String.valueOf(frmtdtxtfldAlphaF.getValue())); _simulatorProperties.put("beta-f", String.valueOf(frmtdtxtfldBetaF.getValue())); _simulatorProperties.put("default-conflict-value", String.valueOf(spinnerDefaultConflict.getValue())); _simulatorProperties.put("cancellation-threshold", String.valueOf(spinnerCancelationThreshold.getValue())); StringBuilder sbAgentBuilder = new StringBuilder(); sbAgentBuilder.append("edu.snu.leader.discrete.simulator.Sueur"); sbAgentBuilder.append(comboBoxAgentBuilder.getSelectedItem().toString().replace(" ", "")); sbAgentBuilder.append("AgentBuilder"); _simulatorProperties.put("agent-builder", String.valueOf(sbAgentBuilder.toString())); StringBuilder sbDecisionCalculator = new StringBuilder(); sbDecisionCalculator.append("edu.snu.leader.discrete.simulator."); sbDecisionCalculator.append(comboBoxModel.getSelectedItem()); // sbDecisionCalculator.append(comboBoxDecisionCalculator.getSelectedItem()); sbDecisionCalculator .append(comboBoxDecisionCalculator.getSelectedItem().toString().replace(" ", "")); sbDecisionCalculator.append("DecisionCalculator"); _simulatorProperties.put("decision-calculator", String.valueOf(sbDecisionCalculator.toString())); StringBuilder sbLocationsFile = new StringBuilder(); sbLocationsFile.append("cfg/sim/locations/metric/valid-metric-loc-"); sbLocationsFile.append(String.format("%03d", sliderAgent.getValue())); sbLocationsFile.append("-seed-00001.dat"); _simulatorProperties.put("locations-file", String.valueOf(sbLocationsFile.toString())); //create destination file DestinationBuilder db = new DestinationBuilder(sliderAgent.getValue(), 1L); StringBuilder sbDestinationsFile = new StringBuilder(); sbDestinationsFile.append("cfg/sim/destinations/destinations-"); switch (comboBoxEnvironment.getSelectedItem().toString()) { case ("Minimum"): sbDestinationsFile.append("diffdis-" + sliderAgent.getValue()); sbDestinationsFile.append("-per-" + frmtdtxtfldPercentage.getValue()); sbDestinationsFile.append("-seed-1.dat"); db.generateDifferentDistance(((Number) frmtdtxtfldPercentage.getValue()).doubleValue(), 200, 100, 75); break; case ("Medium"): sbDestinationsFile.append("split-" + sliderAgent.getValue()); sbDestinationsFile.append("-dis-" + frmtdtxtfldDistance.getValue()); sbDestinationsFile.append("-ang-" + String.format("%.2f", ((Number) frmtdtxtfldAngle.getValue()).doubleValue())); sbDestinationsFile.append("-per-" + String.format("%.3f", ((Number) frmtdtxtfldPercentage.getValue()).doubleValue())); sbDestinationsFile.append("-seed-1.dat"); db.generateSplitNorth(((Number) frmtdtxtfldDistance.getValue()).doubleValue(), ((Number) frmtdtxtfldAngle.getValue()).doubleValue(), ((Number) frmtdtxtfldPercentage.getValue()).doubleValue()); break; case ("Maximum"): sbDestinationsFile.append("poles-" + sliderAgent.getValue()); sbDestinationsFile.append("-per-" + frmtdtxtfldPercentage.getValue()); sbDestinationsFile.append("-seed-1.dat"); db.generatePoles(50, 100, ((Number) frmtdtxtfldPercentage.getValue()).doubleValue()); break; case ("Uninformed"): sbDestinationsFile.append("split-poles-" + frmtdtxtfldInformedCount.getValue()); sbDestinationsFile.append("-dis-" + String.format("%.1f", ((Number) frmtdtxtfldDistance.getValue()).doubleValue())); sbDestinationsFile.append("-ang-" + String.format("%.2f", ((Number) frmtdtxtfldAngle.getValue()).doubleValue())); sbDestinationsFile.append("-per-" + String.format("%.3f", ((Number) frmtdtxtfldPercentage.getValue()).doubleValue())); sbDestinationsFile.append("-seed-1.dat"); db.generateSplitPoles(((Number) frmtdtxtfldDistance.getValue()).doubleValue(), ((Number) frmtdtxtfldAngle.getValue()).doubleValue(), ((Number) frmtdtxtfldPercentage.getValue()).doubleValue(), ((Number) frmtdtxtfldInformedCount.getValue()).intValue()); break; default: //Should never happen break; } _simulatorProperties.put("destinations-file", String.valueOf(sbDestinationsFile.toString())); _simulatorProperties.put("live-delay", String.valueOf(15)); //Doesn't change _simulatorProperties.put("results-dir", "results"); //Doesn't change new Thread(new Runnable() { public void run() { try { runSimulation(); } catch (Exception e) { e.printStackTrace(); } } }).start(); } } }); panelStartButtons.add(btnStartSimulation); JButton btnStartSimulationFrom = new JButton("Run Simulation from Properties File"); btnStartSimulationFrom .setToolTipText("Runs the simulator with the values provided in the properties file."); btnStartSimulationFrom.setEnabled(false); panelStartButtons.add(btnStartSimulationFrom); panelTab3.add(panelStartButtons); }
From source file:ctlogger.CTlogger.java
private static boolean getData(boolean newfile) { ArrayList<String> data; long appendTime = 0; if (debug)/*from ww w. ja v a 2 s . co m*/ System.err.println("CTlogger fetch: " + loggerFileName); try { // logger file header parse if (newfile || (br == null)) { // new file br = new BufferedReader(new FileReader(new File(loggerFileName))); // Channel names if (HeaderLine == null) HeaderLine = br.readLine(); chanNames = new ArrayList<String>(Arrays.asList(HeaderLine.replace("\"", "").split(","))); // Optionally skip lines for (int i = 0; i < skipLines; i++) br.readLine(); // CTwriter setup String sourceFolder = CTrootfolder + File.separator + SourceName; ctw = new CTwriter(sourceFolder, trimTime); if (appendMode) { ctreader = new CTreader(CTrootfolder); // JPW, change from sourceFolder to SourceName (ie, not full path) appendTime = (long) (ctreader.newTime(SourceName) * 1000); // convert sec to msec if (debug) System.err.println("appending past time: " + appendTime); } ctw.setDebug(debug); if (autoflush > 0) ctw.autoFlush(autoflush * 1000); // auto flush to zip once per interval (msec) of data System.err .println("autoflush: " + autoflush + ", blockMode: " + blockMode + ", zipmode: " + zipmode); ctw.setBlockMode(blockMode, zipmode); // blockMode doesn't work well, should flush(blockDur), but then interpolates intermediate timestamps // ctw.setZipMode(zipmode); // compress none-most, 0-9, 10=zip.gz ctw.setGZipMode(gzipmode); ctw.autoSegment(100); // MJM 12/2/16 // parsable time formats sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf2 = new SimpleDateFormat("MM/dd/yyyy HH:mm"); sdf3 = new SimpleDateFormat("yyyy/MM/dd'T'HH:mm:ss"); } // parse data lines long otime = 0; String line; int lineCount = 0; int idxTime = 0; if (leadingID != null) idxTime = 1; // skootch int idxFirstChan = idxTime + 1; if (storeTime) idxFirstChan = idxTime; long oldTime = 0; long adjTime = 0; while ((line = br.readLine()) != null) { line = line.replace("\"", ""); // remove extra quote chars line = line.replace(".txt", ""); // strip trailing ".txt" line = line.replace("NAN", nanVal); // replace "NAN" with legal number data = new ArrayList<String>(Arrays.asList(line.split(","))); long time = 0; // first-pass: see if time is integer seconds or msec try { long tsec = Long.parseLong(data.get(idxTime)); if (tsec > 1e10) time = tsec; // msec else time = 1000 * tsec; // sec -> msec } catch (Exception e0) { // System.err.println("unparsed as long: "+line); try { time = sdf1.parse(data.get(idxTime)).getTime(); // primary date format } catch (ParseException e1) { try { time = sdf2.parse(data.get(idxTime)).getTime(); // alternate date format } catch (ParseException e2) { try { time = sdf3.parse(data.get(idxTime)).getTime(); // alternate date format } catch (ParseException e3) { errPrint("Exception, ignored: " + e3 + ", line: " + line); continue; } } } } if (time < 0) { errPrint("illegal timestamp, ignored: " + data.get(0)); continue; } if (time <= otime && noBackwards) { errPrint("backwards-going time, ignored: " + data.get(0)); // warning continue; } if (time <= appendTime) { // errPrint("skipping past existing time: "+time+" < "+appendTime); // debug continue; // skip past existing data } System.err.println( "timestr: " + data.get(idxTime) + ", time: " + time + ", time2str: " + new Date(time)); if (time == oldTime) { adjTime++; // prevent time dupes } else { oldTime = time; adjTime = time; } lineCount++; otime = time; if (debug) System.err.println("getData time: " + time + ", data(0): " + data.get(0)); ctw.setTime(adjTime); if (leadingID != null) { if (!data.get(0).equals(leadingID)) { errPrint("Error, leading ID mismatch. Expected: " + leadingID + ", got: " + data.get(0)); continue; } } // write CT data (skip ID & optionally Time) // System.err.println("data.size: "+data.size()+", chanNames.size: "+chanNames.size()); int firstChanName = 0; // if(HeaderLine != null) firstChanName=1; // mjm 10/2015: why skip first? causes overflow on chanNames j // System.err.println("--------idxFirstChan: "+idxFirstChan+", data.size: "+data.size()+", chanNames.size: "+chanNames.size()); // for(int i=idxFirstChan, j=0; i<data.size(); i++,j++) { for (int i = idxFirstChan, j = firstChanName; i < data.size(); i++, j++) { // if first-chanName (Time) column is labelled // System.err.println("i: "+i+", j: "+j+", chanNames[j]: "+chanNames.get(j)+", data.get[i]: "+data.get(i)); if (blockMode) ctw.putData(chanNames.get(j) + ".f32", new Float(data.get(i))); // if(blockMode) ctw.addData(chanNames.get(j), new Float(data.get(i))); else ctw.putData(chanNames.get(j), data.get(i)); // if(i>100) break; // MJM foo debug, problem with huge number of columns (chans) } // ctw.flush(); } ctw.flush(); // clean up after last line read this pass if (newfile) { br.close(); br = null; } // close if newfile mode if (lineCount > 0 || firstrun) System.err.println("CTlogger processed " + loggerFileName + ", lines: " + lineCount); firstrun = false; // if(debug) System.err.println("getData at EOF"); } catch (Exception e) { errPrint("CTlogger exception: " + e); e.printStackTrace(); return true; // something went wrong } return false; // OK }
From source file:coolmap.application.io.internal.coolmapobject.InternalCoolMapObjectIO.java
public static VNode createNodeFromJSON(JSONObject object) throws Exception { String id = object.getString(IOTerm.ATTR_NODE_ID); String name = object.getString(IOTerm.ATTR_NODE_NAME); Double defaultViewMultiplier = object.optDouble(IOTerm.ATTR_NODE_VIEWMULTIPLIER_DEFAULT, -1); if (defaultViewMultiplier == null || defaultViewMultiplier < 0) { defaultViewMultiplier = 1.0;/*from w w w . j a v a 2s . c om*/ } Double currentViewMultiplier = object.optDouble(IOTerm.ATTR_NODE_VIEWMULTIPLIER, -1); if (currentViewMultiplier == null || currentViewMultiplier < 0) { currentViewMultiplier = defaultViewMultiplier; } boolean isExpanded = object.optInt(IOTerm.ATTR_NODE_ISEXPANDED, 0) == 1 ? true : false; String colorString = object.optString(IOTerm.ATTR_NODE_COLOR); Color viewColor; if (colorString == null) { viewColor = null; } else { try { viewColor = new Color(Integer.parseInt(colorString)); } catch (Exception e) { viewColor = null; } } // System.out.println(object); String contologyID = object.optString(IOTerm.ATTR_NODE_ONTOLOGYID); COntology ontology = CoolMapMaster.getCOntologyByID(contologyID); //This part may need to be refactored: nodes only need to associate with ontology ID // System.out.println("ontology to be loaded:" + contologyID + " " + ontology); //set view heights VNode node = new VNode(name, ontology, id); node.setViewColor(viewColor); node.setDefaultViewMultiplier(defaultViewMultiplier.floatValue()); node.setViewMultiplier(currentViewMultiplier.floatValue()); node.setExpanded(isExpanded); Float viewHeight = new Float(object.optDouble(IOTerm.ATTR_NODE_VIEWHEIGHT, -1)); node.setViewHeight(viewHeight == -1 ? null : viewHeight); return node; }
From source file:kilim.analysis.BasicBlock.java
void interpret() { Value v, v1, v2, v3, v4;/*from www . ja va 2 s. c o m*/ Frame frame = startFrame.dup(); if (isCatchHandler()) { // When an exception is thrown, the stack is cleared // and the thrown exception is pushed into the stack frame.clearStack(); frame.push(Value.make(startPos, caughtExceptionType)); } else if (hasFlag(IS_SUBROUTINE)) { // The target of a JSR instruction has a JVM-internal // return address which we model with a type of its // own frame.push(Value.make(startPos, D_RETURN_ADDRESS)); } String componentType = null; @SuppressWarnings("unused") boolean canThrowException = false; boolean propagateFrame = true; int i = 0; try { for (i = startPos; i <= endPos; i++) { AbstractInsnNode ain = getInstruction(i); int opcode = ain.getOpcode(); int val, var; switch (opcode) { case -1: // linenumbernode, framenode, etc. continue; case NOP: break; case ACONST_NULL: frame.push(Value.make(i, D_NULL)); break; case ICONST_M1: case ICONST_0: case ICONST_1: case ICONST_2: case ICONST_3: case ICONST_4: case ICONST_5: frame.push(Value.make(i, D_INT, new Integer(opcode - ICONST_0))); break; case LCONST_0: case LCONST_1: frame.push(Value.make(i, D_LONG, new Long(opcode - LCONST_0))); break; case ILOAD: case LLOAD: case FLOAD: case DLOAD: case ALOAD: var = ((VarInsnNode) ain).var; v = frame.getLocal(var, opcode); frame.push(v); break; case FCONST_0: case FCONST_1: case FCONST_2: frame.push(Value.make(i, D_FLOAT, new Float(opcode - FCONST_0))); break; case DCONST_0: case DCONST_1: frame.push(Value.make(i, D_DOUBLE, new Double(opcode - DCONST_0))); break; case BIPUSH: val = ((IntInsnNode) ain).operand; frame.push(Value.make(i, D_BYTE, new Integer(val))); break; case SIPUSH: val = ((IntInsnNode) ain).operand; frame.push(Value.make(i, D_SHORT, new Integer(val))); break; case LDC: Object cval = ((LdcInsnNode) ain).cst; frame.push(Value.make(i, TypeDesc.getTypeDesc(cval), cval)); break; case IALOAD: case LALOAD: case FALOAD: case DALOAD: case AALOAD: case BALOAD: case CALOAD: case SALOAD: canThrowException = true; frame.popWord(); // pop index v = frame.popWord(); // array ref frame.push(Value.make(i, TypeDesc.getComponentType(v.getTypeDesc()))); // push // component // of // array break; case ISTORE: case LSTORE: case FSTORE: case DSTORE: case ASTORE: v1 = frame.pop(); var = ((VarInsnNode) ain).var; frame.setLocal(var, v1); break; case IASTORE: case LASTORE: case FASTORE: case DASTORE: case AASTORE: case BASTORE: case CASTORE: case SASTORE: canThrowException = true; frame.popn(3); break; case POP: frame.popWord(); break; case POP2: if (frame.pop().isCategory1()) { frame.popWord(); } break; case DUP: // ... w => ... w w v = frame.popWord(); frame.push(v); frame.push(v); break; case DUP_X1: // Insert top word beneath the next word // .. w2 w1 => .. w1 w2 w1 v1 = frame.popWord(); v2 = frame.popWord(); frame.push(v1); frame.push(v2); frame.push(v1); break; case DUP_X2: // Insert top word beneath the next two words (or dword) v1 = frame.popWord(); v2 = frame.pop(); if (v2.isCategory1()) { v3 = frame.pop(); if (v3.isCategory1()) { // w3,w2,w1 => w1,w3,w2,w1 frame.push(v1); frame.push(v3); frame.push(v2); frame.push(v1); break; } } else { // dw2,w1 => w1,dw2,w1 frame.push(v1); frame.push(v2); frame.push(v1); break; } throw new InternalError("Illegal use of DUP_X2"); case DUP2: // duplicate top two words (or dword) v1 = frame.pop(); if (v1.isCategory1()) { v2 = frame.pop(); if (v2.isCategory1()) { // w2,w1 => w2,w1,w2,w1 frame.push(v2); frame.push(v1); frame.push(v2); frame.push(v1); break; } } else { // dw1 => dw1,dw1 frame.push(v1); frame.push(v1); break; } throw new InternalError("Illegal use of DUP2"); case DUP2_X1: // insert two words (or dword) beneath next word v1 = frame.pop(); if (v1.isCategory1()) { v2 = frame.pop(); if (v2.isCategory1()) { v3 = frame.popWord(); // w3,w2,w1 => w2,w1,w3,w2,w1 frame.push(v2); frame.push(v1); frame.push(v3); frame.push(v2); frame.push(v1); break; } } else { // TypeDesc.isDoubleWord(t1) // w2,dw1 => dw1,w2,dw1 v2 = frame.popWord(); frame.push(v1); frame.push(v2); frame.push(v1); break; } throw new InternalError("Illegal use of DUP2_X1"); case DUP2_X2: // insert two words (or dword) beneath next two words (or // dword) v1 = frame.pop(); if (v1.isCategory1()) { v2 = frame.pop(); if (v2.isCategory1()) { v3 = frame.pop(); if (v3.isCategory1()) { v4 = frame.pop(); if (v4.isCategory1()) { // w4,w3,w2,w1 => w2,w1,w4,w3,w2,w1 frame.push(v2); frame.push(v1); frame.push(v4); frame.push(v3); frame.push(v2); frame.push(v1); break; } } else { // TypeDesc.isDoubleWord(t3) // dw3,w2,w1 => w2,w1,dw3,w2,w1 frame.push(v2); frame.push(v1); frame.push(v3); frame.push(v2); frame.push(v1); break; } } } else { // TypeDesc.isDoubleWord(t1) v2 = frame.pop(); if (v2.isCategory1()) { v3 = frame.pop(); if (v3.isCategory1()) { // w3,w2,dw1 => dw1,w3,w2,dw1 frame.push(v1); frame.push(v3); frame.push(v2); frame.push(v1); break; } } else { // dw2,dw1 => dw1,dw2,dw1 frame.push(v1); frame.push(v2); frame.push(v1); break; } } throw new InternalError("Illegal use of DUP2_X2"); case SWAP: // w2, w1 => w1, w2 v1 = frame.popWord(); v2 = frame.popWord(); frame.push(v1); frame.push(v2); break; case IDIV: case IREM: case LDIV: case LREM: frame.pop(); // See next case canThrowException = true; break; case IADD: case LADD: case FADD: case DADD: case ISUB: case LSUB: case FSUB: case DSUB: case IMUL: case LMUL: case FMUL: case DMUL: case FDIV: case DDIV: case FREM: case DREM: case ISHL: case LSHL: case ISHR: case LSHR: case IUSHR: case LUSHR: case IAND: case LAND: case IOR: case LOR: case IXOR: case LXOR: // Binary op. frame.pop(); v = frame.pop(); // The result is always the same type as the first arg frame.push(Value.make(i, v.getTypeDesc())); break; case LCMP: case FCMPL: case FCMPG: case DCMPL: case DCMPG: frame.popn(2); frame.push(Value.make(i, D_INT)); break; case INEG: case LNEG: case FNEG: case DNEG: v = frame.pop(); frame.push(Value.make(i, v.getTypeDesc())); break; case IINC: var = ((IincInsnNode) ain).var; frame.setLocal(var, Value.make(i, D_INT)); break; case I2L: case F2L: case D2L: frame.pop(); frame.push(Value.make(i, D_LONG)); break; case I2D: case L2D: case F2D: frame.pop(); frame.push(Value.make(i, D_DOUBLE)); break; case I2F: case L2F: case D2F: frame.pop(); frame.push(Value.make(i, D_FLOAT)); break; case L2I: case F2I: case D2I: frame.pop(); frame.push(Value.make(i, D_INT)); break; case I2B: frame.popWord(); frame.push(Value.make(i, D_BOOLEAN)); break; case I2C: frame.popWord(); frame.push(Value.make(i, D_CHAR)); break; case I2S: frame.popWord(); frame.push(Value.make(i, D_SHORT)); break; case IFEQ: case IFNE: case IFLT: case IFGE: case IFGT: case IFLE: case IFNULL: case IFNONNULL: frame.popWord(); break; case IF_ICMPEQ: case IF_ICMPNE: case IF_ICMPLT: case IF_ICMPGE: case IF_ICMPGT: case IF_ICMPLE: case IF_ACMPEQ: case IF_ACMPNE: frame.popn(2); break; case GOTO: case JSR: // note: the targetBB pushes the return address // itself // because it is marked with isSubroutine case RET: break; case TABLESWITCH: case LOOKUPSWITCH: frame.pop(); break; case IRETURN: case LRETURN: case FRETURN: case DRETURN: case ARETURN: case RETURN: canThrowException = true; if (opcode != RETURN) { frame.pop(); } if (frame.stacklen != 0) { throw new InternalError("stack non null at method return"); } break; case GETSTATIC: canThrowException = true; v = Value.make(i, TypeDesc.getInterned(((FieldInsnNode) ain).desc)); frame.push(v); break; case PUTSTATIC: canThrowException = true; frame.pop(); break; case GETFIELD: canThrowException = true; v1 = frame.pop(); v = Value.make(i, TypeDesc.getInterned(((FieldInsnNode) ain).desc)); //if (TypeDesc.isRefType(v.getTypeDesc())) { // System.out.println("GETFIELD " + ((FieldInsnNode)ain).name + ": " + v + "---->" + v1); //} frame.push(v); break; case PUTFIELD: canThrowException = true; v1 = frame.pop(); v = frame.pop(); //if (TypeDesc.isRefType(v.getTypeDesc())) { // System.out.println("PUTFIELD " + ((FieldInsnNode)ain).name + ": " + v + " ----> " + v1); //} break; case INVOKEVIRTUAL: case INVOKESPECIAL: case INVOKESTATIC: case INVOKEINTERFACE: // pop args, push return value MethodInsnNode min = ((MethodInsnNode) ain); String desc = min.desc; if (flow.isPausableMethodInsn(min) && frame.numMonitorsActive > 0) { throw new KilimException( "Error: Can not call pausable nethods from within a synchronized block\n" + "Caller: " + this.flow.classFlow.name.replace('/', '.') + "." + this.flow.name + this.flow.desc + "\nCallee: " + ((MethodInsnNode) ain).name); } canThrowException = true; frame.popn(TypeDesc.getNumArgumentTypes(desc)); if (opcode != INVOKESTATIC) { v = frame.pop(); // "this" ref //assert checkReceiverType(v, min) : "Method " + flow.name + " calls " + min.name + " on a receiver with incompatible type " + v.getTypeDesc() ; } desc = TypeDesc.getReturnTypeDesc(desc); if (desc != D_VOID) { frame.push(Value.make(i, desc)); } break; case NEW: canThrowException = true; v = Value.make(i, TypeDesc.getInterned(((TypeInsnNode) ain).desc)); frame.push(v); break; case NEWARRAY: canThrowException = true; frame.popWord(); int atype = ((IntInsnNode) ain).operand; String t; switch (atype) { case T_BOOLEAN: t = D_ARRAY_BOOLEAN; break; case T_CHAR: t = D_ARRAY_CHAR; break; case T_FLOAT: t = D_ARRAY_FLOAT; break; case T_DOUBLE: t = D_ARRAY_DOUBLE; break; case T_BYTE: t = D_ARRAY_BYTE; break; case T_SHORT: t = D_ARRAY_SHORT; break; case T_INT: t = D_ARRAY_INT; break; case T_LONG: t = D_ARRAY_LONG; break; default: throw new InternalError("Illegal argument to NEWARRAY: " + atype); } frame.push(Value.make(i, t)); break; case ANEWARRAY: canThrowException = true; frame.popWord(); componentType = TypeDesc.getInterned(((TypeInsnNode) ain).desc); v = Value.make(i, TypeDesc.getInterned("[" + componentType)); frame.push(v); break; case ARRAYLENGTH: canThrowException = true; frame.popWord(); frame.push(Value.make(i, D_INT)); break; case ATHROW: canThrowException = true; frame.pop(); propagateFrame = false; break; case CHECKCAST: canThrowException = true; frame.pop(); v = Value.make(i, TypeDesc.getInterned(((TypeInsnNode) ain).desc)); frame.push(v); break; case INSTANCEOF: canThrowException = true; frame.pop(); frame.push(Value.make(i, D_INT)); break; case MONITORENTER: case MONITOREXIT: if (opcode == MONITORENTER) { frame.numMonitorsActive++; } else { frame.numMonitorsActive--; } canThrowException = true; frame.pop(); canThrowException = true; break; case MULTIANEWARRAY: MultiANewArrayInsnNode minode = (MultiANewArrayInsnNode) ain; int dims = minode.dims; frame.popn(dims); componentType = TypeDesc.getInterned(minode.desc); StringBuffer sb = new StringBuffer(componentType.length() + dims); for (int j = 0; j < dims; j++) sb.append('['); sb.append(componentType); v = Value.make(i, TypeDesc.getInterned(sb.toString())); frame.push(v); break; default: assert false : "Unexpected opcode: " + ain.getOpcode(); } } i = -1; // reset for assertion catch block below if (propagateFrame) { mergeSuccessors(frame); } if (handlers != null) { for (Handler handler : handlers) { handler.catchBB.merge(frame, /* localsOnly= */true); // merge // only // locals } canThrowException = false; } } catch (AssertionError ae) { log.error("**** Assertion Error analyzing " + flow.classFlow.name + "." + flow.name); log.error("Basic block " + this); log.error("i = " + i); log.error("Frame: " + frame); throw ae; } }
From source file:com.pronoiahealth.olhie.server.services.BookCoverImageService.java
/** * Create an image that contains text/* w w w .ja v a 2s. com*/ * * @param height * @param width * @param text * @param textColor * @param center * @param fontMap * @param type * @return */ private BufferedImage createText(int height, int width, String text, String textColor, boolean center, Map<TextAttribute, Object> fontMap, int type) { BufferedImage img = new BufferedImage(width, height, type); Graphics2D g2d = null; try { g2d = (Graphics2D) img.getGraphics(); // Create attributed text AttributedString txt = new AttributedString(text, fontMap); // Set graphics color g2d.setColor(Color.decode(textColor)); // Create a new LineBreakMeasurer from the paragraph. // It will be cached and re-used. AttributedCharacterIterator paragraph = txt.getIterator(); int paragraphStart = paragraph.getBeginIndex(); int paragraphEnd = paragraph.getEndIndex(); FontRenderContext frc = g2d.getFontRenderContext(); LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(paragraph, frc); // Set break width to width of Component. float breakWidth = (float) width; float drawPosY = 0; // Set position to the index of the first character in the // paragraph. lineMeasurer.setPosition(paragraphStart); // Get lines until the entire paragraph has been displayed. while (lineMeasurer.getPosition() < paragraphEnd) { // Retrieve next layout. A cleverer program would also cache // these layouts until the component is re-sized. TextLayout layout = lineMeasurer.nextLayout(breakWidth); // Compute pen x position. If the paragraph is right-to-left we // will align the TextLayouts to the right edge of the panel. // Note: drawPosX is always where the LEFT of the text is // placed. float drawPosX = layout.isLeftToRight() ? 0 : breakWidth - layout.getAdvance(); if (center == true) { double xOffSet = (width - layout.getBounds().getWidth()) / 2; drawPosX = drawPosX + new Float(xOffSet); } // Move y-coordinate by the ascent of the layout. drawPosY += layout.getAscent(); // Draw the TextLayout at (drawPosX, drawPosY). layout.draw(g2d, drawPosX, drawPosY); // Move y-coordinate in preparation for next layout. drawPosY += layout.getDescent() + layout.getLeading(); } } finally { if (g2d != null) { g2d.dispose(); } } return img; }
From source file:org.squale.squalecommon.enterpriselayer.facade.quality.MeasureFacade.java
/** * Creation d'une mesure de type Kiviat pour un projet * //from w w w . j ava2 s .c o m * @param pProjectId Id du projet * @param pAuditId Id de l'audit * @param pAllFactors tous les facteurs (= "true") ou seulement ceux ayant une note ? * @throws JrafEnterpriseException en cas de pb Hibernate * @return tableau d'objets : la map des donnes + le boolen pour affichage de la case cocher tous les facteurs */ public static Object[] getProjectKiviat(Long pProjectId, Long pAuditId, String pAllFactors) throws JrafEnterpriseException { Map result = new HashMap(); JFreeChart projectKiviat = null; MeasureDAOImpl measureDAO = MeasureDAOImpl.getInstance(); // Session Hibernate ISession session = null; // Boolen conditonnanant l'affichage de la case cocher "tous les facteurs" dans la page Jsp boolean displayCheckBoxFactors = true; try { // rcupration d'une session session = PERSISTENTPROVIDER.getSession(); // On ajoute les notes de chaque projets sur le kiviat ProjectBO project = (ProjectBO) ProjectDAOImpl.getInstance().load(session, pProjectId); SortedMap values = new TreeMap(); // recupere les facteurs du projet Collection factorResults = QualityResultDAOImpl.getInstance().findWhere(session, pProjectId, pAuditId); // et cree le map nom => note correspondant Iterator it = factorResults.iterator(); ArrayList nullValuesList = new ArrayList(); while (it.hasNext()) { FactorResultBO factor = (FactorResultBO) it.next(); // le -1 est trait directement par le kiviatMaker Float value = new Float(factor.getMeanMark()); // ajoute la note dans le titre // TODO prendre le vritable nom du facteur String name = factor.getRule().getName(); if (value.floatValue() >= 0) { // avec 1 seul chiffre aprs la virgule NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(1); nf.setMaximumFractionDigits(1); name = name + " (" + nf.format(value) + ")"; } else { // Mmorisation temporaire des facteurs pour lesquels les notes sont nulles : sera utile si l'option // "Tous les facteurs" est coche pour afficher uniquement les facteurs ayant une note. nullValuesList.add(name); } values.put(name, value); } final int FACTORS_MIN = 3; if (nullValuesList.size() <= 0 || values.size() <= FACTORS_MIN) { displayCheckBoxFactors = false; } // Seulement les facteurs ayant une note ? ==> suppression des facteurs ayant une note nulle. // Mais trois facteurs doivent au moins s'afficher (nuls ou pas !) values = deleteFactors(values, nullValuesList, pAllFactors, FACTORS_MIN); // recupre le nom de l'audit String name = null; AuditBO audit = (AuditBO) AuditDAOImpl.getInstance().load(session, pAuditId); if (audit.getType().compareTo(AuditBO.MILESTONE) == 0) { name = audit.getName(); } if (null == name) { DateFormat df = DateFormat.getDateInstance(DateFormat.LONG); name = df.format(audit.getDate()); } result.put(name, values); } catch (Exception e) { FacadeHelper.convertException(e, MeasureFacade.class.getName() + ".getMeasures"); } finally { FacadeHelper.closeSession(session, MeasureFacade.class.getName() + ".getMeasures"); } Object[] kiviatObject = { result, new Boolean(displayCheckBoxFactors) }; return kiviatObject; }
From source file:com.doculibre.constellio.services.RecordServicesImpl.java
@Override public Float computeFieldBoost(Record record, IndexField indexField) { Float boostAssociatedWithIndexField = 1.0f; String indexFieldName = indexField.getName(); Set<String> indexFieldAssociatedMetaNames = new HashSet<String>(); if (indexFieldName.equals(IndexField.UNIQUE_KEY_FIELD)) { indexFieldAssociatedMetaNames.add(SpiConstants.PROPNAME_DOCID); } else {//from w ww . j av a 2 s . c o m if (indexFieldName.equals(IndexField.DEFAULT_SEARCH_FIELD)) { indexFieldAssociatedMetaNames.add(SpiConstants.PROPNAME_CONTENT); } else { indexFieldAssociatedMetaNames = indexField.getMetaNames(); } } for (String metaName : indexFieldAssociatedMetaNames) { List<RecordMeta> boosts = record.getMetas(IndexFieldServices.BOOST_FIELD_PREFIX + metaName); if (boosts != null) { for (RecordMeta boost : boosts) { boostAssociatedWithIndexField *= Float.valueOf(boost.getContent()); } } } // Ajout du boost des fields ajouts via l'interface de gestion de la pertinence des champs Float boostFieldAddedThrowInterface = indexField.getBoost(); if (boostFieldAddedThrowInterface == null) { boostFieldAddedThrowInterface = new Float(0F); } return boostAssociatedWithIndexField * boostFieldAddedThrowInterface; }