用弹簧壳打印固定线

时间:2019-05-02 09:10:23

标签: spring spring-shell

我想开发一个小型的Sprint Shell项目,在其中显示静态信息,这些静态信息在收到事件时可能会更新。 Spring Shell可以实现此功能吗?或者它甚至是完成这项工作的正确工具?

举一个我想要实现的例子:

public class Matrix {
    private int row;
    private int col;
    private int rowNum;
    private int colNum;
    private double[][] m;

    public Matrix(int rowNum, int colNum) {
        this.rowNum = rowNum;
        this.colNum = colNum;
        m = new double[rowNum][colNum];
        for (int i = 0; i < rowNum; i++) {
            for (int j = 0; j < colNum; j++) {
                m[i][j] = 0;
            }
        }
    }

    public Matrix(double[][] m) {
        rowNum = m.length;
        colNum = m[0].length;
        this.m = m;
    }

    public Matrix(double[] v) {
        rowNum = v.length;
        colNum = 1;
        double[][] m = new double[rowNum][colNum];
        for (int i = 0; i < rowNum; i++) {
            m[i][0] = v[i];
        }
        this.m = m;
    }

    public Matrix pro(double lambda) {
        for (int i = 0; i < rowNum; i++) {
            for (int j = 0; j < colNum; j++) {
                m[i][j] *= lambda;
            }
        }
        return this;
    }


    public Matrix add(Matrix mm) throws MatrixProcessException {
        if (mm.getRowNum() != rowNum || mm.getColNum() != colNum) {
            throw new MatrixProcessException();
        }
        double[][] m1 = m;
        double[][] m2 = mm.getM();
        double[][] addM = new double[m.length][m[0].length];
        for (int i = 0; i < m.length; i++) {
            for (int j = 0; j < m[0].length; j++) {
                addM[i][j] = m1[i][j] + m2[i][j];
            }
        }
        return new Matrix(addM);
    }


    public Matrix sub(Matrix mm) throws MatrixProcessException {
        if (mm.getRowNum() != rowNum || mm.getColNum() != colNum) {
            throw new MatrixProcessException();
        }
        return this.add(mm.pro(-1));
    }
  }

    public double[][] getM() {
        return m;
    }

    public void setM(double[][] m) {
        this.m = m;
    }

    public int getRowNum() {
        return rowNum;
    }

    public void setRowNum(int rowNum) {
        this.rowNum = rowNum;
    }

    public int getColNum() {
        return colNum;
    }

    public void setColNum(int colNum) {
        this.colNum = colNum;
    }

    public Matrix dot(Matrix M) throws MatrixProcessException {
        double[][] m1 = m;
        double[][] m2 = M.getM();
        if (this.colNum != M.rowNum) {
            System.out.println("sss");
            throw new MatrixProcessException();
        }
        double[][] ansMatrix = new double[this.rowNum][M.colNum];
        for (int i = 0; i < this.rowNum; i++) {
            for (int j = 0; j < M.colNum; j++) {
                double num = 0;
                for (int k = 0; k < this.colNum; k++) {
                    num += m1[i][k] * m2[k][j];
                }
                ansMatrix[i][j] = num;
            }
        }
        return new Matrix(ansMatrix);
    }


    public Matrix inv() throws MatrixProcessException {
        if (rowNum != colNum) {
            throw new MatrixProcessException();
        }

        Matrix mm = new Matrix(rowNum, 2 * colNum);
        for (int i = 0; i < rowNum; i++) {
            for (int j = 0; j < 2 * colNum; j++) {
                if (j < rowNum) {
                    mm.set(i, j, m[i][j]);
                }
                else {
                    if (j - rowNum == i) {
                        mm.set(i, j, 1);
                    }
                }
            }
        }

        Collections.calculateUpperTriangle(mm);
        Collections.calculateSimplest(mm);


        for (int i = 0; i < rowNum; i++) {
            mm.proR(i, 1.0 / mm.get(i, i));
        }


        Matrix M = new Matrix(rowNum, colNum);
        for (int i = 0; i < rowNum; i++) {
            for (int j = 0; j < rowNum; j++) {
                M.set(i, j, mm.get(i, j + rowNum));
            }
        }
        return M;
    }

    public void showMatrix() {
        System.out.println("\nMatrix:");
        for (int i = 0; i < rowNum; i++) {
            for (int j = 0; j < colNum; j++) {
                System.out.print(m[i][j] + "  ");
            }
            System.out.println();
        }
    }

    public double[] toVector() {
        double[] v = new double[rowNum];
        if (colNum == 1) {
            for (int i = 0; i < rowNum; i++) {
                v[i] = m[i][0];
            }
        }
        else {
            System.out.println("This matrix is not a vector");
        }
        return v;
    }

}

当我在应用程序中键入事件时,应该可以将其更改为例如

-------------------
| Stock Value: 5$ | < This information should be always displayed
-------------------

shell:> I can put input here

1 个答案:

答案 0 :(得分:0)