+/EE360P

distributed systems

git clone https://git.julia.blue/+/EE360P

vijaygarg1init6bd33a4

master
2.1 KiB90 linesraw
1package dist;
2import java.io.*; import java.util.*;
3
4public class Util {
5	final static boolean debugFlag = true;
6	public static void mySleep(int time) {
7		try {
8			Thread.sleep(time);
9		} catch (InterruptedException e) {
10		}
11	}
12
13	public static void myWait(Object obj) {
14		println("waiting");
15		try {
16			obj.wait();
17		} catch (InterruptedException e) {
18		}
19	}
20
21	public static boolean lessThan(int A[], int B[]) {
22		for (int j = 0; j < A.length; j++)
23			if (A[j] > B[j])
24				return false;
25		for (int j = 0; j < A.length; j++)
26			if (A[j] < B[j])
27				return true;
28		return false;
29	}
30
31	public static int maxArray(int A[]) {
32		int v = A[0];
33		for (int i = 0; i < A.length; i++)
34			if (A[i] > v)
35				v = A[i];
36		return v;
37	}
38
39	public static String writeArray(int A[]) {
40		StringBuffer s = new StringBuffer();
41		for (int j = 0; j < A.length; j++)
42			s.append(String.valueOf(A[j]) + " ");
43		return new String(s.toString());
44	}
45	public static String readLine(InputStream sin) throws IOException{
46		BufferedReader inp = new BufferedReader(
47            new InputStreamReader(sin));
48		return inp.readLine();
49	}
50	public static String readLine(String fileName) throws IOException{
51		BufferedReader inp = new BufferedReader(
52            new FileReader(fileName));
53		return inp.readLine();
54	}
55	public static void readArray(String s, int A[]) {
56		StringTokenizer st = new StringTokenizer(s);
57		for (int j = 0; j < A.length; j++)
58			A[j] = Integer.parseInt(st.nextToken());
59	}
60
61	public static void readList(String s, LinkedList<Integer> q) {
62		StringTokenizer st = new StringTokenizer(s);
63		q.clear();
64		while (st.hasMoreTokens()) {
65			q.add(Integer.parseInt(st.nextToken()));
66		}
67	}
68
69	public static int searchArray(int A[], int x) {
70		for (int i = 0; i < A.length; i++)
71			if (A[i] == x)
72				return i;
73		return -1;
74	}
75
76	public static void println(String s) {
77		if (debugFlag) {
78			System.out.println(s);
79			System.out.flush();
80		}
81	}
82
83	public static LinkedList<Object> getLinkedList(Object... objects) {
84		LinkedList<Object> list = new LinkedList<Object>();
85		for (int i = 0; i < objects.length; i += 1) {
86			list.add(objects[i]);
87		}
88		return list;
89	}
90}