public static <T extends Number> ArrayList<ArrayList<T>> mulScalarWithMatrix(T scalar, ArrayList<ArrayList<T>> a, Class<T> type) {
	ArrayList<ArrayList<T>> result = new ArrayList<ArrayList<T>>();
	try {
	    if (a == null) {
		throw new NullPointerException();
	    }
	    int rows = a.size();
	    int columns = a.get(0).size();
	    
	    for (int i = 0; i < rows; i++) {
		ArrayList<T> row = new ArrayList<>();
		for (int j = 0; j < columns; j++) {
		    T elem = ElementOpUtils.mul(scalar, a.get(i).get(j), type);
		    row.add(elem);
		}
		result.add(row);
	    }
	    return result;
	} catch (NullPointerException e) {
	    Logger.getGlobal().log(Level.SEVERE, "cannot multiply null matrixes");
	    e.printStackTrace();
	    return null;
	} catch (IndexOutOfBoundsException e) {
	    Logger.getGlobal().log(Level.SEVERE, "check your indexes when multiplying matrixes");
	    e.printStackTrace();
	    return null;
	}
    }