Skip to content

Commit d535705

Browse files
committed
Cleanup warnings
1 parent 15f12a8 commit d535705

File tree

21 files changed

+811
-840
lines changed

21 files changed

+811
-840
lines changed

src/main/java/org/teachingextensions/approvals/lite/reporters/MultipleExceptions.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,33 @@
33
import java.util.ArrayList;
44

55
public class MultipleExceptions extends RuntimeException {
6-
public MultipleExceptions(ArrayList<Throwable> exceptions) {
7-
super(getText(exceptions), exceptions.get(0));
8-
}
6+
private static final long serialVersionUID = 1464454338264847972L;
7+
8+
public MultipleExceptions(ArrayList<Throwable> exceptions) {
9+
super(getText(exceptions), exceptions.get(0));
10+
}
911

10-
public static void rethrowExceptions(ArrayList<Throwable> exceptions) throws Exception {
11-
if (exceptions.size() != 0) {
12-
if (exceptions.size() == 0) {
13-
Throwable t = exceptions.get(0);
14-
if (t instanceof Exception) {
15-
throw ((Exception) t);
16-
}
17-
throw (Error) t;
18-
} else {
19-
throw new MultipleExceptions(exceptions);
20-
}
12+
public static void rethrowExceptions(ArrayList<Throwable> exceptions)
13+
throws Exception {
14+
if (exceptions.size() != 0) {
15+
if (exceptions.size() == 0) {
16+
Throwable t = exceptions.get(0);
17+
if (t instanceof Exception) {
18+
throw ((Exception) t);
2119
}
20+
throw (Error) t;
21+
} else {
22+
throw new MultipleExceptions(exceptions);
23+
}
2224
}
25+
}
2326

24-
private static String getText(ArrayList<Throwable> exceptions) {
25-
StringBuilder b = new StringBuilder("Multiple Exceptions Thrown:");
26-
for (int i = 0; i < exceptions.size(); i++) {
27-
b.append(String.format("\n #%s): %s", i + 1, exceptions.get(i).getMessage()));
28-
}
29-
return b.toString();
27+
private static String getText(ArrayList<Throwable> exceptions) {
28+
StringBuilder b = new StringBuilder("Multiple Exceptions Thrown:");
29+
for (int i = 0; i < exceptions.size(); i++) {
30+
b.append(String.format("\n #%s): %s", i + 1, exceptions.get(i)
31+
.getMessage()));
3032
}
33+
return b.toString();
34+
}
3135
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package org.teachingextensions.approvals.lite.util;
22

3-
43
public class FormattedException extends RuntimeException {
54

6-
public FormattedException(String string, Object... params) {
7-
super(String.format(string, params));
8-
MySystem.variable(this.getMessage());
9-
}
5+
private static final long serialVersionUID = -4388436150197314047L;
6+
7+
public FormattedException(String string, Object... params) {
8+
super(String.format(string, params));
9+
MySystem.variable(this.getMessage());
10+
}
1011
}
Lines changed: 5 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
package org.teachingextensions.approvals.lite.util;
22

3-
import java.awt.Image;
4-
import java.lang.reflect.Array;
5-
import java.lang.reflect.Method;
3+
import javax.swing.*;
4+
import java.awt.*;
65
import java.net.URL;
7-
import java.util.ArrayList;
8-
import java.util.Arrays;
9-
import java.util.List;
10-
11-
import javax.swing.ImageIcon;
126

137
/**
148
* A static class of convenience functions for Manipulating objects
@@ -28,8 +22,8 @@ public static boolean isEqual(Object s1, Object s2) {
2822
return s1 == s2 || (s1 != null) && s1.equals(s2);
2923
}
3024

31-
public static boolean isThisInstanceOfThat(Class<?> thiz, Class<?> that) {
32-
return that.isAssignableFrom(thiz);
25+
public static boolean isThisInstanceOfThat(Class<?> type, Class<?> that) {
26+
return that.isAssignableFrom(type);
3327
}
3428

3529
public static Error throwAsError(Throwable t) throws Error {
@@ -42,82 +36,6 @@ public static Error throwAsError(Throwable t) throws Error {
4236
}
4337
}
4438

45-
/**
46-
* @param from
47-
* the source array
48-
* @param methodName
49-
* the filter method
50-
* @return a filtered array
51-
*/
52-
public static Object[] extractArray(Object[] from, String methodName) {
53-
try {
54-
if (from == null || from.length == 0) {
55-
return new Object[0];
56-
}
57-
Method method = getGreatestCommonDenominator(from, methodName);
58-
Object[] array;
59-
if (Object.class.isAssignableFrom(method.getReturnType())) {
60-
array = (Object[]) Array.newInstance(method.getReturnType(),
61-
from.length);
62-
} else {
63-
array = (Object[]) Array.newInstance(
64-
ClassUtils.getWrapperClass(method.getReturnType()), from.length);
65-
}
66-
for (int i = 0; i < from.length; i++) {
67-
array[i] = method.invoke(from[i], (Object[]) null);
68-
}
69-
return array;
70-
} catch (Exception e) {
71-
MySystem.warning(e);
72-
throw ObjectUtils.throwAsError(e);
73-
}
74-
}
75-
76-
public static Method getGreatestCommonDenominator(Object[] from,
77-
String methodName) throws SecurityException, NoSuchMethodException {
78-
List<Class<?>> classes = new ArrayList<>();
79-
ArrayUtils.addArray(classes, getAllCastableClasses(from[0]));
80-
for (Object o : from) {
81-
for (int i = classes.size() - 1; i >= 0; i--) {
82-
Class clazz = classes.get(i);
83-
if (!isThisInstanceOfThat(o.getClass(), clazz)
84-
|| !ClassUtils.hasMethod(clazz, methodName)) {
85-
classes.remove(i);
86-
}
87-
}
88-
}
89-
return classes.size() == 0 ? null : ArrayUtils.getLast(classes).getMethod(
90-
methodName, (Class[]) null);
91-
}
92-
93-
private static Class[] getAllCastableClasses(Object object) {
94-
Class<?> clazz = object.getClass();
95-
ArrayList<Object> list = new ArrayList<>();
96-
while (clazz != null) {
97-
list.add(clazz);
98-
ArrayUtils.addArray(list, clazz.getInterfaces());
99-
clazz = clazz.getSuperclass();
100-
}
101-
Class[] found = list.toArray(new Class[list.size()]);
102-
ArrayUtils.toReverseArray(found);
103-
return found;
104-
}
105-
106-
public static void assertInstance(Class classes[], Object object) {
107-
if (object == null) {
108-
throw new NullPointerException("Expected Object of Type "
109-
+ Arrays.asList(extractArray(classes, "getName")) + " but was null");
110-
}
111-
for (Class aClass : classes) {
112-
if (ClassUtils.getWrapperClass(aClass).isInstance(object)) {
113-
return;
114-
}
115-
}
116-
throw new IllegalArgumentException("Expected Object of Type "
117-
+ Arrays.asList(extractArray(classes, "getName")) + " but got "
118-
+ object.getClass().getName());
119-
}
120-
12139
public static String getClassName(Object o) {
12240
return o == null ? "null" : o.getClass().getName();
12341
}
@@ -132,4 +50,4 @@ public static Image loadImage(Class<?> type, String name) {
13250
}
13351
return new ImageIcon(resource).getImage();
13452
}
135-
}
53+
}

src/main/java/org/teachingextensions/approvals/lite/util/ParserCommons.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
import java.util.List;
44

55
public class ParserCommons {
6-
public static ParserCommons INSTANCE = new ParserCommons();
6+
public static ParserCommons INSTANCE = new ParserCommons();
77

8-
public static Class getClass(String clazz) throws ClassNotFoundException {
9-
return Class.forName(clazz);
10-
}
8+
public static Class<?> getClass(String clazz) throws ClassNotFoundException {
9+
return Class.forName(clazz);
10+
}
1111

12-
public static Object getNull() {
13-
return null;
14-
}
12+
public static Object getNull() {
13+
return null;
14+
}
1515

16-
public static int getArrayLength(Object[] array) {
17-
return array == null ? 0 : array.length;
18-
}
16+
public static int getArrayLength(Object[] array) {
17+
return array == null ? 0 : array.length;
18+
}
1919

20-
public static Object get(Object[] array, int index) {
21-
return getArrayLength(array) > index ? array[index] : null;
22-
}
20+
public static Object get(Object[] array, int index) {
21+
return getArrayLength(array) > index ? array[index] : null;
22+
}
2323

24-
public static Object get(List list, int index) {
25-
return list == null ? null : list.get(index);
26-
}
24+
public static Object get(List<?> list, int index) {
25+
return list == null ? null : list.get(index);
26+
}
2727
}

0 commit comments

Comments
 (0)