当前位置: 首页 > 面试题库 >

JavaDoc可重用参数值

龙亮
2023-03-14
问题内容

好的,我这里有这段代码,这是我对标准Swing
TableModel的替换实现。我认为这绝对是一场噩梦,我的问题是,我有很多rowIndex和columIndex参数,有没有一种方法可以共享它们之间的描述,从而实现更标准化,更少手指操作的方式?谢谢!!

package atablemodel;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

/**
 * My custom swing TableModel version 1.x will represent a complete table model
 * while version 2.x adds several methods for updating an existing table version
 * 0.x is an incomplete version
 * Completely changed everything to work with arraylist instead of array, which means
 * that ATableModel Object can now simply be updated instead of recreated
 * @author alex
 * @version 2.0
 * @see AbstractTableModel
 * @see TableModel
 */

@SuppressWarnings("serial")
public class ATableModel extends AbstractTableModel {
    private ArrayList<String> cn = new ArrayList<String>();
    private ArrayList<ArrayList<RowDataObject>> rd = new ArrayList<ArrayList<RowDataObject>>();

    /**
     * Creates my custom TableModel
     * 
     * @param columnames The names for the columns
     * @param rowdata The data for the rows
     */
    public ATableModel(String[] columnames, Object[][] rowdata) {
        for (int i = 0; i < columnames.length; i++) {
            cn.add(columnames[i]);
        }
        for (int i = 0; i < rowdata.length; i++) {
            ArrayList<RowDataObject> rdot1 = new ArrayList<RowDataObject>();
            for (int i2 = 0; i2 < rowdata[i].length; i2++) {
                rdot1.add(new RowDataObject(rowdata[i][i2]));
            }
            rd.add(rdot1);
        }

    }

    /**
     * Looks up the column name for the specified column
     * 
     * @param column The number of the column to look up
     * @return The name (string) of the column
     */
    public String getColumnName(int column) {
        return cn.get(column);
    }

    /**
     * This method will simply tell you if a cell is editable
     * This is only here because it is in the Default TableModel
     * @deprecated use {@link #getCellEditable(int, int)} instead
     * @param columnIndex The column
     * @param rowIndex The row
     * @return A boolean indicating if the cell is editable or not
     */
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return getCellEditable(rowIndex, columnIndex);
    }

    /**
     * Sets the value at a certain cell; <b>TAKE NOTE!:</b> this set the cell to
     * editable before changing the value, and returns it to either uneditable,
     * or editable depending on what the cell was before in {@link #rde}
     * 
     * @param aValue The value to set
     * @param rowIndex The row
     * @param columnIndex The column
     */
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        boolean editable = getRDO(rowIndex, columnIndex).getEditable();
        getRDO(rowIndex, columnIndex).setEditable(true);
        getRDO(rowIndex, columnIndex).setData(aValue);
        getRDO(rowIndex, columnIndex).setEditable(editable);
    }

    /**
     * gets the number of columns; returns the length of columnnames, so if your
     * rowdata and columnnames don't match up, it might not give you the info
     * you want
     * 
     * @return Number of columns
     */

    public int getColumnCount() {
        return cn.size();
    }

    /**
     * gets the number of rows
     * 
     * @return number of rows
     */
    public int getRowCount() {
        return rd.size();
    }

    /**
     * gets the value for a specified cell
     * 
     * @param rowIndex The row
     * @param columnIndex The column
     * @return the value (if any) at the specified cell
     */
    public Object getValueAt(int rowIndex, int columnIndex) {
        return getRDO(rowIndex, columnIndex).getData();
        /* getValueAt(0, 3); returns d */
    }

    /**
     * do not use, useless unless absolutely necessary for some reason
     * 
     * @deprecated
     */
    public TableModel returnTableModel() {
        return this;
    }

    /**
     * gets a boolean indicating if the cell is editable or not
     * 
     * @param rowIndex The row
     * @param columnIndex The column
     * @return A boolean indicating whether the cell is editable
     */
    public boolean getCellEditable(int rowIndex, int columnIndex) {
        return getRDO(rowIndex, columnIndex).getEditable();
    }

    /**
     * sets all cells editable
     * 
     * @param rowIndex The row
     * @param columnIndex The column
     * @param editable set all cells to this value
     */
    public void setCellEditable(int rowIndex, int columnIndex, boolean editable) {
        getRDO(rowIndex, columnIndex).setEditable(editable);
    }

    /**
     * Sets all cells in the current rowdata to {@code editable}
     * 
     * @param editable What to set all of the cells editable values to
     */

    public void setAllCellsEditable(boolean editable) {
        int x, y;
        for (x = 0; x < rd.size(); x++) {
            for (y = 0; y < rd.get(x).size(); y++) {
                getRDO(x, y).setEditable(editable);
            }
        }
    }

    /**
     * Set all the cells of a single row to editable or not
     * 
     * @param rowIndex The row to set editable
     * @param editable what to set the cells editable values to
     */
    public void setRowEditable(int rowIndex, boolean editable) {
        for (RowDataObject rdo : getRDORow(rowIndex)) {
            rdo.setEditable(editable);
        }
    }

    /**
     * Set all the cells in one column to editable
     * 
     * @param columnIndex The column to set editable
     * @param editable what to set all the cells editable values to
     */
    public void setColumnEditable(int columnIndex, boolean editable) {
        for (RowDataObject rdo : getRDOCol(columnIndex)) {
            rdo.setEditable(editable);
        }
    }

    public RowDataObject getRDO(int rowIndex, int columnIndex) {
        return rd.get(rowIndex).get(columnIndex);
    }

    public ArrayList<RowDataObject> getRDORow(int rowIndex) {
        //ArrayList<RowDataObject> rdor;
        /*for (int i = 0; i < rd.get(rowIndex).size(); i++) {

        }*/
        return rd.get(rowIndex);
    }

    public ArrayList<RowDataObject> getRDOCol(int columnIndex) {
        ArrayList<RowDataObject> rdoc = new ArrayList<RowDataObject>();
        for (int i = 0; i < rd.size(); i++) {
            rdoc.add(rd.get(i).get(columnIndex));
        }

        return rdoc;        
    }

}

/*
 * rd[2][5] 0 1 2 3 4 0 {a b c d e} 1 {f g h i j}
 * 
 * {a b c d e}, {f g h i j}
 */

问题答案:

没有一个就不可能

  • 修补标准doclet(或替换您自己的doclet)
  • 修补Javadoc核心
  • 在将源代码提供给JavaDoc之前对其进行预处理
  • 运行Javadoc后对HTML输出进行后处理。


 类似资料:
  • 问题内容: 该代码无法编译,编译器说f含糊。但是我认为第二种方法可以解决什么问题? 问题答案: 这是因为无法确定该方法调用是应调用变量args还是应调用float和变量args。 Java决定以这种方式来调用拓宽>装箱>变量args的方法,但是在这种情况下,两者都具有变量args。 在这种情况下,基本上将char扩展为浮动。 Java基元的扩展顺序为:

  • 基本上,eclipse导出javadoc输出格式如下: 如果我想另一种格式,如: (没有包名称) 在EclipseJavadoc额外javadoc选项项中我应该做什么?非常感谢。

  • 问题内容: 我正在开发一个API,其中包含许多相同名称的方法,只是签名不同而已,这在我看来是很普遍的。它们都做相同的事情,不同之处在于,如果用户不想指定默认值,则它们会默认初始化各种值。作为一个容易理解的例子,考虑 所有这些方法执行的基本动作是相同的;森林里种了一棵树。我的API用户需要了解许多重要事项,以了解如何为所有这些方法添加树。 理想情况下,我想编写一个Javadoc块,供所有方法使用:

  • 问题内容: 我有一个用于编码URI的便捷类。在其中,根据需要的具体程度,我创建了三种方法。我想知道在这种情况下是否使用JavaDoc 重用描述?(我还没有找到) 问题答案: 否。复制适用于覆盖的方法,但不适用于重载的方法。http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/javadoc.html#inheritingcomments

  • Swagger2.0支持可重用参数,如下所述。 如何使用Springfox利用此特性 SpringFox支持这个特性吗?

  • 问题内容: 有没有一种方法可以从方法文档主体中添加对一个或多个方法参数的引用?就像是: 问题答案: 据我阅读javadoc文档后所知,没有这样的功能。 不要按照其他答案中的建议使用;您可以使用。当您引用诸如以下类型的泛型类型时,尤其要知道这一点-肯定看起来比更好,不是吗!