Blame view

PercTeacher/Sources/ApplicationJava/Util.java 796 Bytes
c5abccad   pfrison   PercTeacher inter...
1
2
3
4
5
6
7
8
9
  
  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++) {
04949080   pfrison   PercTeacher stabl...
10
  			arrays[i] = getArrayFromLine(split[i], i);
c5abccad   pfrison   PercTeacher inter...
11
12
13
14
15
  			if(arrays[i] == null)
  				return null;
  		}
  		return arrays;
  	}
04949080   pfrison   PercTeacher stabl...
16
  	private static long[] getArrayFromLine(String str, int nLine) {
c5abccad   pfrison   PercTeacher inter...
17
  		str = str.substring(1, str.length() - 2); // remove { and }
04949080   pfrison   PercTeacher stabl...
18
19
20
21
22
23
  		String[] longsStr;
  		if(nLine <= 1)
  			longsStr = str.split(", ");
  		else
  			longsStr = str.split("L, ");
  		
c5abccad   pfrison   PercTeacher inter...
24
25
26
27
28
29
30
31
32
  		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;
  	}
  }