JavaDoc可重复使用的参数值

4

好的,我有这段代码,它是我对标准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}
 */

2个回答

1

如果不进行以下操作之一,是无法实现的:

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

谢谢您的回答。我能否从命令行调用javadoc编译器,并在编译之前替换所有出现的某个字符串? - alexmherrmann
我担心这不是直接可能的 - Javadoc 想要从文件中读取它的东西。当然,你可以使用一些程序来替换它,在其他地方创建新的源文件(例如在单独的树中)。如果您正在使用Ant,则copy任务可以包括filtersetfilterchain,允许您进行替换。(或者您可以使用C预处理器。) - Paŭlo Ebermann
哎呀,我真的无法处理像C(++)这样的语言,即使只是预处理器,指针也让我感到困惑。也许我可以使用注释?但首先我需要学习关于注释的知识,你有任何关于JIT的问题参考资料吗?我已经搜索了几个小时,没有找到太多相关的内容。但现在一切都好了,因为我在Stack Overflow上找到了答案 :D。 - alexmherrmann
C预处理器不使用任何指针,它只是文本替换(正是您想要的)。但我认为这在这里是一种过度工程化的解决方案,它只是一个例子。请使用ant filterchains - Paŭlo Ebermann
可能,我总是可以做一点点bash(确切地说是sed)的魔法。 - alexmherrmann

0

这是我认为唯一可以自由复制粘贴的情况之一。我认为任何宏处理魔法都会过度。


有没有机会让我使用一些m4! - alexmherrmann

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接