CPD Results

The following document contains the results of PMD's CPD 7.3.0.

Duplications

File Line
nl/tudelft/simulation/dsol/swing/introspection/gui/CollectionTableModel.java 85
nl/tudelft/simulation/dsol/swing/introspection/gui/ImmutableCollectionTableModel.java 78
public CollectionTableModel(final Property parentProperty, final Introspector introspector)
    {
        Object values;
        try
        {
            values = parentProperty.getValue();
        }
        catch (Exception e)
        {
            values = new String("-");
        }
        if (values.getClass().isArray())
        {
            for (int i = 0; i < Array.getLength(values); i++)
            {
                addValue(Array.get(values, i));
            }
        }
        if (values instanceof Collection)
        {
            for (Iterator<?> i = ((Collection<?>) values).iterator(); i.hasNext();)
            {
                addValue(i.next());
            }
        }
        if (values instanceof ImmutableCollection)
        {
            for (Iterator<?> i = ((ImmutableCollection<?>) values).iterator(); i.hasNext();)
            {
                addValue(i.next());
            }
        }
        this.parentProperty = parentProperty;
        this.introspector = introspector;
        // Initialize buttons
        for (int i = 0; i < this.instances.size(); i++)
        {
            this.buttons.add(new ExpandButton(getProperty(i), this));
        }
    }

    /**
     * Adds a new value to the managed composite property.
     * @param value Object; the value to add
     */
    private void addValue(final Object value)
    {
        Integer nextKey = Integer.valueOf(this.maxKey++);
        this.keys.add(nextKey);
        this.instances.put(nextKey, value);
    }

    /** {@inheritDoc} */
    @Override
    public int getRowCount()
    {
        return this.instances.size();
    }

    /** {@inheritDoc} */
    @Override
    public int getColumnCount()
    {
        return CollectionTableModel.COLUMNS.length;
File Line
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistContinuous.java 93
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistDiscrete.java 93
InputParameterMapDistContinuous value = parameter.getOptions().get(option);
            JTextField[] paramFields = new JTextField[value.getSortedSet().size()];
            int index = 0;
            for (InputParameter<?, ?> param : value.getSortedSet())
            {
                JPanel itemPanel = new JPanel();
                itemPanel.setLayout(new GridLayout(1, 2, 5, 0));
                itemPanel.add(new JLabel(param.getShortName()));
                paramFields[index] = new JTextField(param.getDefaultValue().toString(), 20);
                itemPanel.add(paramFields[index]);
                distParamPanel.add(itemPanel);
                index++;
            }
            this.textFields.put(option.toString(), paramFields);
            distParamPanel.add(Box.createVerticalGlue());
            this.distPanel.add(distParamPanel, option.toString());
        }

        container.add(this.distComboBox);
        container.add(this.distPanel);
        panel.add(container);

        cardLayout.show(this.distPanel, selections[defaultIndex]);

        JLabel explanation = new JLabel(parameter.getDescription());
        panel.add(explanation);
    }

    /** {@inheritDoc} */
    @Override
    public void itemStateChanged(final ItemEvent event)
    {
        CardLayout cardLayout = (CardLayout) (this.distPanel.getLayout());
        cardLayout.show(this.distPanel, (String) event.getItem());
    }

    /** {@inheritDoc} */
    @Override
    public InputParameterDistContinuousSelection getParameter()
File Line
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDoubleScalar.java 47
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldFloatScalar.java 47
.setText("" + parameter.getDefaultTypedValue().getInUnit(parameter.getDefaultTypedValue().getDisplayUnit()));
        JLabel explanation = new JLabel(parameter.getDescription());

        String[] selections = new String[parameter.getUnitParameter().getOptions().size()];
        int defaultIndex = 0;
        int i = 0;
        for (String option : parameter.getUnitParameter().getOptions().keySet())
        {
            selections[i] = option.toString();
            U value = parameter.getUnitParameter().getOptions().get(option);
            if (value.equals(parameter.getUnitParameter().getDefaultValue()))
            {
                defaultIndex = i;
            }
            i++;
        }
        this.unitField = new JComboBox<>(selections);
        this.unitField.setSelectedIndex(defaultIndex);

        panel.add(label);
        JPanel scalarPanel = new JPanel();
        scalarPanel.setLayout(new GridLayout(1, 2, 5, 0));
        scalarPanel.add(this.doubleField);
File Line
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistContinuous.java 143
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistDiscrete.java 143
InputParameterMapDistContinuous ipMap = this.selectionMap.get(selectedOption);
        JTextField[] paramFields = this.textFields.get(selectedOption);
        int index = 0;
        for (InputParameter<?, ?> param : ipMap.getSortedSet())
        {
            String sValue = paramFields[index].getText();
            if (param instanceof InputParameterDouble)
            {
                InputParameterDouble dParam = (InputParameterDouble) param;
                dParam.setDoubleValue(InputFieldDouble.getDoubleValue(sValue, param.getShortName()));
            }
            else if (param instanceof InputParameterFloat)
            {
                InputParameterFloat fParam = (InputParameterFloat) param;
                fParam.setFloatValue(InputFieldFloat.getFloatValue(sValue, param.getShortName()));
            }
            else if (param instanceof InputParameterInteger)
            {
                InputParameterInteger iParam = (InputParameterInteger) param;
                iParam.setIntValue(InputFieldInteger.getIntValue(sValue, param.getShortName()));
            }
            else if (param instanceof InputParameterLong)
            {
                InputParameterLong lParam = (InputParameterLong) param;
                lParam.setLongValue(InputFieldLong.getLongValue(sValue, param.getShortName()));
            }
            index++;
        }
    }

}
File Line
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistContinuous.java 73
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistDiscrete.java 73
InputParameterMapDistContinuous value = parameter.getOptions().get(option);
            this.selectionMap.put(selections[i], value);
            if (value.equals(parameter.getDefaultValue()))
            {
                defaultIndex = i;
            }
            i++;
        }
        this.distComboBox = new JComboBox<>(selections);
        this.distComboBox.setSelectedIndex(defaultIndex);
        this.distComboBox.addItemListener(this);
        comboBoxPane.add(this.distComboBox);

        CardLayout cardLayout = new CardLayout();
        this.distPanel = new JPanel(cardLayout);
        for (String option : parameter.getOptions().keySet())
        {
            JPanel distParamPanel = new JPanel();
            BoxLayout boxLayout = new BoxLayout(distParamPanel, BoxLayout.Y_AXIS);
            distParamPanel.setLayout(boxLayout);
File Line
nl/tudelft/simulation/dsol/swing/introspection/gui/CollectionTableModel.java 303
nl/tudelft/simulation/dsol/swing/introspection/gui/ImmutableCollectionTableModel.java 221
}

    /** {@inheritDoc} */
    @Override
    public Introspector getIntrospector()
    {
        return this.introspector;
    }

    /** {@inheritDoc} */
    @Override
    public Class<?> getTypeAt(final int rowIndex, final int columnIndex)
    {
        if (columnIndex == 0)
        {
            return String.class;
        }
        if (columnIndex == 1)
        {
            return ExpandButton.class;
        }
        if (columnIndex == 2)
        {
            return this.instances.get(this.keys.get(rowIndex)).getClass();
        }
        return null;
    }

    /**
     * Sets the modelmanager. By default, a {see DefaultModelManager}is used.
     * @param manager ModelManager; the manager
     */
    public void setModelManager(final ModelManager manager)
    {
        this.manager = manager;
    }

    /**
     * By default, a {see DefaultModelManager}returned.
     * @see nl.tudelft.simulation.dsol.swing.introspection.gui.IntrospectingTableModelInterface #getModelManager()
     * @return the Manager
     */
    @Override
    public ModelManager getModelManager()
    {
        return this.manager;
    }
File Line
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistContinuous.java 57
nl/tudelft/simulation/dsol/swing/gui/inputparameters/InputFieldDistDiscrete.java 57
public InputFieldDistContinuous(final JPanel panel, final InputParameterDistContinuousSelection parameter)
    {
        super(parameter);
        JLabel label = new JLabel(parameter.getShortName());
        panel.add(label);

        JPanel container = new JPanel();
        container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));

        JPanel comboBoxPane = new JPanel(); // use FlowLayout
        String[] selections = new String[parameter.getOptions().size()];
        int defaultIndex = 0;
        int i = 0;
        for (String option : parameter.getOptions().keySet())
        {
            selections[i] = option.toString();