Menu

How to use SDTMatrix to

-get a particular column,check whether a column exists,check whether a part of table exists, get a part of a decision column,reverse a decision table (columns become rows),remove a column from a decision table


/**
 * Gets the column test.
 * @author: Yan Tang, VUB, 2009
 * @return the column test
 */
public static void getColumnTest() {
    String[][] matrix = new String[][] { { "C1", "1", "2", "1", "2" },
            { "C2", "1", "1", "2", "2" }, { "A1", "*", "", "", "" } };
    SDTMatrix m = new SDTMatrix(matrix);

    m.getColumn(0);
    System.out.println(m.getProcessInfo());
    m.getColumn(1);
    System.out.println(m.getProcessInfo());
    m.getColumn(2);
    System.out.println(m.getProcessInfo());

    m.getColumn(5);
    System.out.println(m.getProcessInfo());
}

/**
 * Column exist test.
 */
public static void columnExistTest() {
    String[][] matrix = new String[][] { { "C1", "1", "2", "1", "2" },
            { "C2", "1", "1", "2", "2" }, { "A1", "*", "", "", "" } };
    SDTMatrix m = new SDTMatrix(matrix);
    String[] t = new String[] { "C1" };

    boolean exists = m.columnExist(t);
    System.out.println("Test 1\n" + exists + " |" + m.getProcessInfo());

    t = new String[] { "C1", "C2", "A1" };
    m.columnExist(t);
    System.out.println("Test 2\n" + exists + " |" + m.getProcessInfo());

    t = new String[] { "2", "1", "" };
    m.columnExist(t);
    System.out.println("Test 3\n" + exists + " |" + m.getProcessInfo());

    t = new String[] { "2", "1", "*" };
    m.columnExist(t);
    System.out.println("Test 4\n" + exists + " |" + m.getProcessInfo());

}

/**
 * Part exist test.
 */
public static void partExistTest() {
    String[][] matrix = new String[][] { { "C1", "1", "2", "1", "2" },
            { "C2", "1", "1", "1", "3" }, { "A1", "*", "", "", "" } };
    SDTMatrix m = new SDTMatrix(matrix);
    String[] t = new String[] { "C1" };
    boolean exist = m.partExist(t);
    System.out.println("Test 1\n" + exist + " |" + m.getProcessInfo());

    t = new String[] { "2", "1" };
    exist = m.partExist(t);
    System.out.println("Test 2\n" + exist + " |" + m.getProcessInfo());
    System.err.println(m.getPosition());

    t = new String[] { "1", "*" };
    exist = m.partExist(t);
    System.out.println("Test 3\n" + exist + " |" + m.getProcessInfo());

    matrix = new String[][] { { "", "1", "2", "1", "2" },
            { "C2", "1", "1", "1", "3" }, { "A1", "*", "", "", "" } };
    System.out.println("print matrix");
    for (int i = 0; i < matrix.length; i++) {
        for (int j = 0; j < matrix[i].length; j++)
            System.out.print(matrix[i][j] + ";");
        System.out.println();
    }
    m = new SDTMatrix(matrix);
    t = new String[] { "", "C2" };
    exist = m.partExist(t);
    System.out.println("Test 4\n" + exist + " |" + m.getProcessInfo());
}

/**
 * Gets the column nbr test.
 *
 * @return the column nbr test
 */
public static void getColumnNbrTest() {
    String[][] matrix = new String[][] { { "C1", "1", "2", "1", "2" },
            { "C2", "1", "1", "2", "2" }, { "A1", "*", "", "", "" } };
    SDTMatrix m = new SDTMatrix(matrix);
    String[] t = new String[] { "1", "2", "" };
    int nbr = m.getColumnNbr(t, false);
    System.out.println("Test1:\n" + nbr + "|" + m.getProcessInfo());

    t = new String[] { "1", "2", "", "" };
    nbr = m.getColumnNbr(t, false);
    System.out.println("Test2:\n" + nbr + "|" + m.getProcessInfo());

    t = new String[] { "1", "2" };
    nbr = m.getColumnNbr(t, true);
    System.out.println("Test3:\n" + nbr + "|" + m.getProcessInfo());

    t = new String[] { "1", "3" };
    nbr = m.getColumnNbr(t, true);
    System.out.println("Test4:\n" + nbr + "|" + m.getProcessInfo());

}

/**
 * Gets the last column part test.
 *
 * @return the last column part test
 */
public static void getLastColumnPartTest() {
    String[][] matrix = new String[][] { { "C1", "1", "2", "1", "2" },
            { "C2", "1", "1", "2", "2" }, { "A1", "*", "", "", "" } };
    SDTMatrix m = new SDTMatrix(matrix);
    String[] t = m.getLastColumnPart(1, 2);
    System.out.println("Test1:\n" + "|" + m.getProcessInfo());

    t = m.getLastColumnPart(1, 1);
    System.out.println("Test2:\n" + "|" + m.getProcessInfo());

    t = m.getLastColumnPart(1, 4);
    System.out.println("Test3:\n" + "|" + m.getProcessInfo());

    t = m.getLastColumnPart(2, 1);
    System.out.println("Test4:\n" + "|" + m.getProcessInfo());

    t = m.getLastColumnPart(5, 2);
    System.out.println("Test5:\n" + "|" + m.getProcessInfo());

}

/**
 * Gets the reversed table test.
 *
 * @return the reversed table test
 */
public static void getReversedTableTest() {
    String[][] matrix = new String[][] { { "C1", "1", "2", "1", "2" },
            { "C2", "1", "1", "2", "2" }, { "A1", "*", "", "", "" } };
    SDTMatrix m = new SDTMatrix(matrix);
    System.out.println("before");
    m.printToConsole();
    m.setContent(m.getReversedTable());
    System.out.println("after");
    m.printToConsole();
}

/**
 * Removes the column test.
 */
public static void removeColumnTest() {
    String[][] matrix = new String[][] { { "C1", "1", "2", "1", "2" },
            { "C2", "1", "1", "2", "2" }, { "A1", "*", "", "", "" } };
    SDTMatrix m = new SDTMatrix(matrix);
    System.out.println("before");
    m.printToConsole();

    String[][] removed = m.removeColumn(2);
    if (removed != null) {
        System.out.println("after");
        m.setContent(removed);
        m.printToConsole();
    }

}

/**
 * Removes the column test2.
 */
public static void removeColumnTest2() {
    String[][] matrix = new String[][] { { "C1", "1", "2", "1", "2" },
            { "C2", "1", "1", "2", "2" }, { "A1", "*", "", "", "" } };
    SDTMatrix m = new SDTMatrix(matrix);
    System.out.println("before");
    m.printToConsole();

    String[][] removed = m.removeColumn(new int[] { 2, 4 });
    if (removed != null) {
        System.out.println("after");
        m.setContent(removed);
        m.printToConsole();
    }

    m.setContent(matrix);
    removed = m.removeColumn(new int[] { 0, 3, 4 });
    if (removed != null) {
        System.out.println("after");
        m.setContent(removed);
        m.printToConsole();
    }
}
Posted by Yan Tang Demey 2012-10-18

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.