+/EE360P

distributed systems

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

vijaygarg1Util added8171f45

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