-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.java
More file actions
72 lines (60 loc) · 1.42 KB
/
Copy pathUtilities.java
File metadata and controls
72 lines (60 loc) · 1.42 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Copyright (c) 2000-2001 ipKangaroo
*
*/
package layer;
import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
public class Utilities {
public static Image getImage(String path) {
return Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource(path));
}
public static ImageIcon getImageIcon(String path) {
//return new ImageIcon(ClassLoader.getSystemResource(path));
return new ImageIcon();
}
public static String getLongestString(Object[] a) {
String longest = new String();
for (int i = 0; i < a.length; i++)
if (a[i].toString().length() > longest.length())
longest = a[i].toString();
return longest;
}
public static void sort(Comparable[] a) {
sort(a, 0, a.length - 1);
}
private final static void sort(Comparable[] a, int lo0, int hi0) {
int lo = lo0;
int hi = hi0;
if (lo >= hi)
return;
else if (lo == hi - 1) {
if (a[lo].compareTo(a[hi]) > 0) {
Comparable temp = a[lo];
a[lo] = a[hi];
a[hi] = temp;
}
return;
}
Comparable pivot = a[(lo + hi) / 2];
a[(lo + hi) / 2] = a[hi];
a[hi] = pivot;
while (lo < hi) {
while (a[lo].compareTo(pivot) <= 0 && lo < hi)
lo++;
while (pivot.compareTo(a[hi]) <= 0 && lo < hi )
hi--;
if (lo < hi) {
Comparable temp = a[lo];
a[lo] = a[hi];
a[hi] = temp;
}
}
a[hi0] = a[hi];
a[hi] = pivot;
sort(a, lo0, lo - 1);
sort(a, hi + 1, hi0);
}
}