Skip to content

Commit 4a6cdf5

Browse files
authored
remove redundant boxing and casting (#51)
remove redundant boxing and casting
2 parents d259373 + 108f9b6 commit 4a6cdf5

File tree

7 files changed

+35
-50
lines changed

7 files changed

+35
-50
lines changed

core/src/processing/awt/PSurfaceAWT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,8 @@ public void setIcon(PImage image) {
633633
Class<?> thinkDifferent =
634634
Thread.currentThread().getContextClassLoader().loadClass(td);
635635
Method method =
636-
thinkDifferent.getMethod("setIconImage", new Class[] { java.awt.Image.class });
637-
method.invoke(null, new Object[] { awtImage });
636+
thinkDifferent.getMethod("setIconImage", Image.class);
637+
method.invoke(null, awtImage);
638638
} catch (Exception e) {
639639
e.printStackTrace(); // That's unfortunate
640640
}
@@ -691,8 +691,8 @@ protected void setProcessingIcon(Frame frame) {
691691
Class<?> thinkDifferent =
692692
Thread.currentThread().getContextClassLoader().loadClass(td);
693693
Method method =
694-
thinkDifferent.getMethod("setIconImage", new Class[] { java.awt.Image.class });
695-
method.invoke(null, new Object[] { Toolkit.getDefaultToolkit().getImage(url) });
694+
thinkDifferent.getMethod("setIconImage", Image.class);
695+
method.invoke(null, Toolkit.getDefaultToolkit().getImage(url));
696696
} catch (Exception e) {
697697
e.printStackTrace(); // That's unfortunate
698698
}

core/src/processing/core/PApplet.java

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,18 +1454,7 @@ public void unregisterMethod(String name, Object target) {
14541454
}
14551455
}
14561456

1457-
1458-
protected void handleMethods(String methodName) {
1459-
synchronized (registerLock) {
1460-
RegisteredMethods meth = registerMap.get(methodName);
1461-
if (meth != null) {
1462-
meth.handle();
1463-
}
1464-
}
1465-
}
1466-
1467-
1468-
protected void handleMethods(String methodName, Object[] args) {
1457+
protected void handleMethods(String methodName, Object...args) {
14691458
synchronized (registerLock) {
14701459
RegisteredMethods meth = registerMap.get(methodName);
14711460
if (meth != null) {
@@ -2096,7 +2085,7 @@ protected PGraphics makeGraphics(int w, int h,
20962085
Class<?> rendererClass =
20972086
Thread.currentThread().getContextClassLoader().loadClass(renderer);
20982087

2099-
Constructor<?> constructor = rendererClass.getConstructor(new Class[] { });
2088+
Constructor<?> constructor = rendererClass.getConstructor();
21002089
PGraphics pg = (PGraphics) constructor.newInstance();
21012090

21022091
pg.setParent(this);
@@ -2580,7 +2569,7 @@ protected void handleMouseEvent(MouseEvent event) {
25802569
break;
25812570
}
25822571

2583-
handleMethods("mouseEvent", new Object[] { event });
2572+
handleMethods("mouseEvent", event);
25842573

25852574
switch (action) {
25862575
case MouseEvent.PRESS:
@@ -2852,7 +2841,7 @@ protected void handleKeyEvent(KeyEvent event) {
28522841
}
28532842
*/
28542843

2855-
handleMethods("keyEvent", new Object[] { event });
2844+
handleMethods("keyEvent", event);
28562845

28572846
// if someone else wants to intercept the key, they should
28582847
// set key to zero (or something besides the ESC).
@@ -3689,8 +3678,8 @@ public void dispose() {
36893678
*/
36903679
public void method(String name) {
36913680
try {
3692-
Method method = getClass().getMethod(name, new Class[] {});
3693-
method.invoke(this, new Object[] { });
3681+
Method method = getClass().getMethod(name);
3682+
method.invoke(this);
36943683

36953684
} catch (IllegalArgumentException e) {
36963685
e.printStackTrace();
@@ -6150,8 +6139,8 @@ static public void selectCallback(File selectedFile,
61506139
try {
61516140
Class<?> callbackClass = callbackObject.getClass();
61526141
Method selectMethod =
6153-
callbackClass.getMethod(callbackMethod, new Class[] { File.class });
6154-
selectMethod.invoke(callbackObject, new Object[] { selectedFile });
6142+
callbackClass.getMethod(callbackMethod, File.class);
6143+
selectMethod.invoke(callbackObject, selectedFile);
61556144

61566145
} catch (IllegalAccessException iae) {
61576146
System.err.println(callbackMethod + "() must be public");
@@ -10236,8 +10225,8 @@ public void uncaughtException(Thread t, Throwable e) {
1023610225
Class<?> thinkDifferent =
1023710226
Thread.currentThread().getContextClassLoader().loadClass(td);
1023810227
Method method =
10239-
thinkDifferent.getMethod("init", new Class[] { PApplet.class });
10240-
method.invoke(null, new Object[] { sketch });
10228+
thinkDifferent.getMethod("init", PApplet.class);
10229+
method.invoke(null, sketch);
1024110230
} catch (Exception e) {
1024210231
e.printStackTrace(); // That's unfortunate
1024310232
}

core/src/processing/data/Table.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ public void parseInto(Object enclosingObject, String fieldName) {
10621062
con = target.getDeclaredConstructor(); //new Class[] { });
10631063
// PApplet.println("no enclosing class");
10641064
} else {
1065-
con = target.getDeclaredConstructor(new Class[] { enclosingClass });
1065+
con = target.getDeclaredConstructor(enclosingClass);
10661066
// PApplet.println("enclosed by " + enclosingClass.getName());
10671067
}
10681068
if (!con.canAccess(null)) {
@@ -1509,17 +1509,15 @@ protected void saveODS(OutputStream os) throws IOException {
15091509
entry = new ZipEntry("content.xml");
15101510
zos.putNextEntry(entry);
15111511
//lines = new String[] {
1512-
writeUTF(zos, new String[] {
1513-
xmlHeader,
1514-
"<office:document-content" +
1515-
" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"" +
1516-
" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"" +
1517-
" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"" +
1518-
" office:version=\"1.2\">",
1519-
" <office:body>",
1520-
" <office:spreadsheet>",
1521-
" <table:table table:name=\"Sheet1\" table:print=\"false\">"
1522-
});
1512+
writeUTF(zos, xmlHeader,
1513+
"<office:document-content" +
1514+
" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"" +
1515+
" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"" +
1516+
" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"" +
1517+
" office:version=\"1.2\">",
1518+
" <office:body>",
1519+
" <office:spreadsheet>",
1520+
" <table:table table:name=\"Sheet1\" table:print=\"false\">");
15231521
//zos.write(PApplet.join(lines, "\n").getBytes());
15241522

15251523
byte[] rowStart = " <table:table-row>\n".getBytes();
@@ -1546,12 +1544,10 @@ protected void saveODS(OutputStream os) throws IOException {
15461544
}
15471545

15481546
//lines = new String[] {
1549-
writeUTF(zos, new String[] {
1550-
" </table:table>",
1551-
" </office:spreadsheet>",
1552-
" </office:body>",
1553-
"</office:document-content>"
1554-
});
1547+
writeUTF(zos, " </table:table>",
1548+
" </office:spreadsheet>",
1549+
" </office:body>",
1550+
"</office:document-content>");
15551551
//zos.write(PApplet.join(lines, "\n").getBytes());
15561552
zos.closeEntry();
15571553

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ public class PGraphicsOpenGL extends PGraphics {
5353
// Using the technique alternative to finalization described in:
5454
// http://www.oracle.com/technetwork/articles/java/finalization-137655.html
5555
private static ReferenceQueue<Object> refQueue = new ReferenceQueue<>();
56-
private static List<Disposable<? extends Object>> reachableWeakReferences =
56+
private static List<Disposable<?>> reachableWeakReferences =
5757
new LinkedList<>();
5858

5959
static final private int MAX_DRAIN_GLRES_ITERATIONS = 10;
6060

6161
static void drainRefQueueBounded() {
6262
int iterations = 0;
6363
while (iterations < MAX_DRAIN_GLRES_ITERATIONS) {
64-
Disposable<? extends Object> res =
65-
(Disposable<? extends Object>) refQueue.poll();
64+
Disposable<?> res =
65+
(Disposable<?>) refQueue.poll();
6666
if (res == null) {
6767
break;
6868
}

core/src/processing/opengl/PJOGL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ public int createShader(int type) {
14691469

14701470
@Override
14711471
public void shaderSource(int shader, String source) {
1472-
gl2.glShaderSource(shader, 1, new String[] { source }, (int[]) null, 0);
1472+
gl2.glShaderSource(shader, 1, new String[] { source }, null, 0);
14731473
}
14741474

14751475
@Override

core/src/processing/opengl/PShapeOpenGL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4681,7 +4681,7 @@ public void draw(PGraphics g) {
46814681
if (family == GROUP) {
46824682
if (fragmentedGroup(gl)) {
46834683
for (int i = 0; i < childCount; i++) {
4684-
((PShapeOpenGL) children[i]).draw(gl);
4684+
children[i].draw(gl);
46854685
}
46864686
} else {
46874687
PImage tex = null;

core/src/processing/opengl/Texture.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ protected boolean bufferUpdate() {
925925
protected void getSourceMethods() {
926926
try {
927927
disposeBufferMethod = bufferSource.getClass().
928-
getMethod("disposeBuffer", new Class[] { Object.class });
928+
getMethod("disposeBuffer", Object.class);
929929
} catch (Exception e) {
930930
throw new RuntimeException("Provided source object doesn't have a " +
931931
"disposeBuffer method.");
@@ -1659,7 +1659,7 @@ protected class BufferData {
16591659
void dispose() {
16601660
try {
16611661
// Disposing the native buffer.
1662-
disposeBufferMethod.invoke(bufferSource, new Object[] { natBuf });
1662+
disposeBufferMethod.invoke(bufferSource, natBuf);
16631663
natBuf = null;
16641664
rgbBuf = null;
16651665
} catch (Exception e) {

0 commit comments

Comments
 (0)