List of utility methods to do Scanner Read
double[][] | loadDoubleMatrix(Scanner reader) load Double Matrix int rows = reader.nextInt(); int cols = reader.nextInt(); double[][] ret = new double[rows][cols]; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { ret[i][j] = Double.parseDouble(reader.next()); return ret; |
int[] | loadIntArray(Scanner reader) load Int Array int dim = reader.nextInt(); int[] ret = new int[dim]; for (int i = 0; i < dim; i++) { ret[i] = Integer.parseInt(reader.next()); return ret; |
int[] | loadNDimDoubleMatrix(Scanner reader, int numberOfDim, Object nmatrix) load N Dim Double Matrix int[] dim = new int[numberOfDim]; for (int i = 0; i < dim.length; i++) { dim[i] = Integer.parseInt(reader.next()); return dim; |
void | loadNDimDoubleMatrixRec(Scanner reader, int[] dim, Object nmatrix) load N Dim Double Matrix Rec if (dim.length == 1) { for (int i = 0; i < dim[0]; i++) { ((double[]) nmatrix)[i] = reader.nextDouble(); } else { int[] newDim = Arrays.copyOfRange(dim, 1, dim.length); for (int i = 0; i < dim[0]; i++) { loadNDimDoubleMatrixRec(reader, newDim, ((Object[]) nmatrix)[i]); ... |
Map | loadSentencesMap(String path) load sentences from file, one line one sentence return map Map<Integer, String> res = new HashMap<Integer, String>(); try (Scanner in = new Scanner(new FileReader(path))) { int index = 0; while (in.hasNextLine()) { String line = in.nextLine(); res.put(index++, line); } catch (FileNotFoundException e) { ... |
int[] | loadSolution(File file) load Solution Scanner sc = null; try { sc = new Scanner(file); List<Integer> temp = new ArrayList<Integer>(); while (sc.hasNextInt()) { temp.add(sc.nextInt()); int[] assignments = new int[temp.size()]; ... |
String | loadTestProgram(final Class> resourceClass, final String fileName) Loads a test program from a resource. InputStream stream = resourceClass.getResourceAsStream("/" + fileName); if (stream == null) { throw new IOException("Cannot find file: " + fileName); return new Scanner(stream).useDelimiter("\\A").next(); |
double[][] | loadTimeseries(File file, String delimeter, int _amountOfLines) Load a 3D (3 axes) time series csv file to a 2D array. Scanner scanner = new Scanner(file); scanner.useDelimiter("\n"); List<Double[]> valuesList = new ArrayList<Double[]>(); while (scanner.hasNext()) { String[] tokens = scanner.next().split(delimeter); Double[] curVal = new Double[3]; for (int i = 0; i < curVal.length; i++) { curVal[i] = Double.valueOf(tokens[i]); ... |
Double | read() read try { return Double.parseDouble(new Scanner(System.in).nextLine()); } catch (NumberFormatException e) { return null; |
String | read(Class clazz, String f) read return new Scanner(clazz.getResourceAsStream(f)).useDelimiter("\\Z").next(); |