Blame view

PercTeacher/Sources/Util.java 711 Bytes
c5abccad   pfrison   PercTeacher inter...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  
  public class Util {
  	public static long[][] getArraysFromImport(String str){
  		long[][] arrays = new long[4][];
  		String[] split = str.split("\n");
  		if(split.length < 4)
  			return null;
  		
  		for(int i=0; i<arrays.length; i++) {
  			arrays[i] = getArrayFromLine(split[i]);
  			if(arrays[i] == null)
  				return null;
  		}
  		return arrays;
  	}
  	private static long[] getArrayFromLine(String str) {
  		str = str.substring(1, str.length() - 2); // remove { and }
  		String[] longsStr = str.split("L, ");
  		try {
  			long[] longs = new long[longsStr.length];
  			for(int i=0; i<longs.length; i++)
  				longs[i] = Long.parseLong(longsStr[i]);
  			return longs;
  		} catch (NumberFormatException ignored) {}
  		return null;
  	}
  }