无法在jTable中循环进行代码克隆

时间:2014-06-12 10:54:33

标签: java swing loops jtable clone

我已经构建了代码克隆应用程序,它使用了阻止ANTLR的JCCD API。为了显示代码克隆,我正在使用jtable。这是我的截图应用: https://www.dropbox.com/s/pjjkra96iskf3r7/Table1.png

Okey,从上面的截图中,我成功地将一个文件与另一个文件进行比较。问题是当我将文件与两个或多个文件进行比较时。这些表只是给我这样的代码克隆的最后一个嫌疑人 https://www.dropbox.com/s/x1sqs8muhs2tbmd/table2.png

但是,在我的netbeans输出控制台中,我成功打印出所有嫌疑人。 对不起,我无法给你截图,因为我没有10个声誉。

如何在我的netbeans控制台中向我的jTable显示所有嫌疑人?

这是我的代码:

public static void printSimilarityGroups(final SimilarityGroupManager groupContainer) {

SimilarityGroup[] simGroups = groupContainer.getSimilarityGroups(); // output similarity groups
    DefaultTableModel model = (DefaultTableModel) Main_Menu.jTable1.getModel();
    model.setRowCount(0);

    List<final_tugas_akhir.Report> theListData = new ArrayList<Report>(); //final_tugas_akhir.Report is my package

    if (null == simGroups) {
        simGroups = new SimilarityGroup[0];
    }
    if ((null != simGroups) && (0 < simGroups.length)) {
        for (int i = 0; i < simGroups.length; i++) {

            final ASourceUnit[] nodes = simGroups[i].getNodes();
            System.out.println("");
            System.out.println("Similarity Group " + simGroups[i].getGroupId());

            for (int j = 0; j < nodes.length; j++) {

                final SourceUnitPosistion minPos = getFirstNodePosition((ANode) nodes[j]); 
                final SourceUnitPosistion maxPos = getLastNodePosition((ANode) nodes[j]);

                ANode fileNode = (ANode) nodes[j];

                while (fileNode.getTipe() != TipeNode.FILE.getTipe()) {
                    fileNode = fileNode.getParent();
                }

                final_tugas_akhir.Report theResult = new final_tugas_akhir.Report(); //final_tugas_akhir.Report() is a class that contain getter and setter

                //Mixing the Line
                StringBuilder sb = new StringBuilder();
                StringBuilder append = sb.append(minPos.getBaris()).append("."); // get the row
                sb.append(minPos.getKarakter()).append(" - "); //get Character
                StringBuilder append1 = sb.append(maxPos.getBaris()).append(".");// get row
                sb.append(maxPos.getKarakter()); get the character

                theResult.setSimiliaritygroup(simGroups[i].getGroupId()); //Similiarity Group
                theResult.setId(nodes[j].getId()); //setter similiarity id on token
                theResult.setIndikasi(nodes[j].getText()); // setter Kind of Similairity
                theResult.setFileutama(fileNode.getText()); //Files name
                theResult.setLine(sb.toString());

                theListData.add(theResult);
            }
        }
        for (Report report : theListData) {
            //test for the console
            System.out.print(report.getSimiliaritygroup() + " ");
            System.out.print(report.getId() + " ");
            System.out.print(report.getIndikasi() + " ");
            System.out.print(report.getFileutama() + " ");
            System.out.print(report.getLine() + "\n");

            //for table that failed
            model.addRow(new Object[]{
                report.getSimiliaritygroup(),
                report.getId(),
                report.getIndikasi(),
                report.getFileutama(),
                report.getLine()});
        }
    } else {
        System.out.println("No similar nodes found.");
    }
}

Oke,report.java就像这样

package final_tugas_akhir;

public class Report {

private int Id;
private int similiaritygroup;
private String theFile;
private String indication;
private String line;

public int getId() {
    return Id;
}

public void setId(int Id) {
    this.Id = Id;
}

public String getFile() {
    return theFile;
}

public void setFile(String theFile) {
    this.theFile = theFile;
}

public int getSimiliaritygroup() {
    return similiaritygroup;
}

public void setSimiliaritygroup(int similiaritygroup) {
    this.similiaritygroup = similiaritygroup;
}

public String getIndication() {
    return indication;
}

public void setIndication(String indication) {
    this.indication = indication;
}

public String getLine() {
    return line;
}

public void setLine(String line) {
    this.line = line;
}

}

和Anode.java这样:

package algoritma.data.ast;

import java.util.Vector;

import  algoritma.data.ASourceUnit;
import  algoritma.data.PosisiSourceUnit;


public abstract class ANode extends ASourceUnit implements Cloneable {

/**
 * Semua node-node child
 */
private Vector<ANode> children = null;

private int Tree{osition = -1;

private ANode parent = null;

private int tipe = -1;

@Override
public ANode clone() throws CloneNotSupportedException {
    final ANode clonedNode = (ANode) super.clone();

    if (null != this.position) {
        clonedNode.position = new PosisiSourceUnit(this.position
                .getBaris(), this.position.getKarakter());
    }

    // nge-clone annotations
    if (null != this.annotations) {
        clonedNode.annotations = null;
        for (final Class<?> group : this.annotations.keySet()) {
            for (final Object key : this.annotations.get(group).keySet()) {
                clonedNode.addAnnotation(group, key, this.annotations.get(
                        group).get(key));
            }
        }
    }

    clonedNode.children = null;
    clonedNode.parent = null;

    if (this.haveChildren()) {
        for (final ANode child : this.children) {
            clonedNode.tambahChild(child.clone());
        }
    }

    return clonedNode;
}


void setParent(final ANode _parent) {
    parent = _parent;
}


void addChild(final ANode child) {
    this.tambahChild(child, -1);
}

void swapChildren(int i, int j) {
    if (i < 0 || j < 0) {
        return;
    }

    if ((this.getChildAmount() - 1 < i) || (this.getChildAmount() - 1 < j)) {
        return;
    }

    final ANode child1 = this.getChild(i);
    final ANode child2 = this.getChild(j);
    this.removeChild(i);
    this.addChild(child2, i);
    this.removeChild(j);
    this.addChild(child1, j);

}

void addChild(final ANode child, final int posisiChild) {
    if (this.children == null) {
        this.children = new Vector<ANode>();
    }

    if (-1 == ChildPosition) {
        child.TreePosition = this.children.size();
        this.children.add(child);
    } else {
        child.TreePosition = posisiChild;
        this.children.add(posisiChild, child);
        this.posisiChildYangBenar(posisiChild);
    }
    child.setParent(this);
}

public ANode getParent() {
    return parent;
}

public ANode getChild(int i) {
    return this.children.get(i);
}

public boolean punyaChildren() {
    return (0 < this.getJumlahChild());
}

public int getChildAmount() {
    if (this.children == null) {
        return 0;
    }
    return children.size();
}

public String getNodeIdentifier() {
    if (this.isRoot()) {
        return this.getText();
    }

    final StringBuffer sb = new StringBuffer();
    // sb.append(this.treePosition);
    ANode parent = this;
    boolean showSeperator = false;
    while (null != parent) {
        if (showSeperator) {
            sb.insert(0, '|');
        }

        showSeperator = true;

        if (parent.isRoot()) {
            sb.insert(0, parent.getText());
        } else {
            sb.insert(0, parent.posisiTree);
        }
        parent = parent.getParent();
    }

    return sb.toString();
}

public boolean isLeaf() {
    return (getJumlahChild() == 0);
}

public boolean isRoot() {
    return (parent == null);
}

public int getTipe() {
    return this.tipe;
}

void setTipe(int tipe) {
    this.tipe = tipe;
}

void collapseChild(final int posisiChild) {
    if ((null == this.parent) || (null == this.children)) {
        return;
    }

    final ANode collapseNode = this.children.get(posisiChild);
    this.children.remove(posisiChild);
    if (0 != collapseNode.getJumlahChild()) {
        for (int i = collapseNode.getJumlahChild(); --i >= 0;) {
            this.children.add(posisiChild, collapseNode.getChild(i));
            collapseNode.getChild(i).setParent(this);
        }
    }
    this.childTruePosition(posisiChild);
}

void removeChild(int posisiChild) {
    if (null == this.children) {
        return;
    }

    this.children.remove(posisiChild);
    this.childTruePosition(posisiChild);
}


private void childTruePosition(final int dariPosisiChild) {
    if (dariPosisiChild < this.children.size()) {
        for (int i = dariPosisiChild; i < this.children.size(); i++) {
            this.children.get(i).posisiTree = i;
        }
    }
}


void removeAllChildren() {
    this.children = null;
}

}

0 个答案:

没有答案