Skip to content

Commit 108f9b6

Browse files
committed
remove redundant boxing and casting
1 parent c183c68 commit 108f9b6

7 files changed

Lines changed: 35 additions & 50 deletions

File tree

core/src/processing/awt/PSurfaceAWT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,8 @@ public void setIcon(PImage image) {
597597
Class<?> thinkDifferent =
598598
Thread.currentThread().getContextClassLoader().loadClass(td);
599599
Method method =
600-
thinkDifferent.getMethod("setIconImage", new Class[] { java.awt.Image.class });
601-
method.invoke(null, new Object[] { awtImage });
600+
thinkDifferent.getMethod("setIconImage", Image.class);
601+
method.invoke(null, awtImage);
602602
} catch (Exception e) {
603603
e.printStackTrace(); // That's unfortunate
604604
}
@@ -655,8 +655,8 @@ protected void setProcessingIcon(Frame frame) {
655655
Class<?> thinkDifferent =
656656
Thread.currentThread().getContextClassLoader().loadClass(td);
657657
Method method =
658-
thinkDifferent.getMethod("setIconImage", new Class[] { java.awt.Image.class });
659-
method.invoke(null, new Object[] { Toolkit.getDefaultToolkit().getImage(url) });
658+
thinkDifferent.getMethod("setIconImage", Image.class);
659+
method.invoke(null, Toolkit.getDefaultToolkit().getImage(url));
660660
} catch (Exception e) {
661661
e.printStackTrace(); // That's unfortunate
662662
}

core/src/processing/core/PApplet.java

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,18 +1581,7 @@ public void unregisterMethod(String name, Object target) {
15811581
}
15821582
}
15831583

1584-
1585-
protected void handleMethods(String methodName) {
1586-
synchronized (registerLock) {
1587-
RegisteredMethods meth = registerMap.get(methodName);
1588-
if (meth != null) {
1589-
meth.handle();
1590-
}
1591-
}
1592-
}
1593-
1594-
1595-
protected void handleMethods(String methodName, Object[] args) {
1584+
protected void handleMethods(String methodName, Object...args) {
15961585
synchronized (registerLock) {
15971586
RegisteredMethods meth = registerMap.get(methodName);
15981587
if (meth != null) {
@@ -2223,7 +2212,7 @@ protected PGraphics makeGraphics(int w, int h,
22232212
Class<?> rendererClass =
22242213
Thread.currentThread().getContextClassLoader().loadClass(renderer);
22252214

2226-
Constructor<?> constructor = rendererClass.getConstructor(new Class[] { });
2215+
Constructor<?> constructor = rendererClass.getConstructor();
22272216
PGraphics pg = (PGraphics) constructor.newInstance();
22282217

22292218
pg.setParent(this);
@@ -2707,7 +2696,7 @@ protected void handleMouseEvent(MouseEvent event) {
27072696
break;
27082697
}
27092698

2710-
handleMethods("mouseEvent", new Object[] { event });
2699+
handleMethods("mouseEvent", event);
27112700

27122701
switch (action) {
27132702
case MouseEvent.PRESS:
@@ -2979,7 +2968,7 @@ protected void handleKeyEvent(KeyEvent event) {
29792968
}
29802969
*/
29812970

2982-
handleMethods("keyEvent", new Object[] { event });
2971+
handleMethods("keyEvent", event);
29832972

29842973
// if someone else wants to intercept the key, they should
29852974
// set key to zero (or something besides the ESC).
@@ -3824,8 +3813,8 @@ public void dispose() {
38243813
*/
38253814
public void method(String name) {
38263815
try {
3827-
Method method = getClass().getMethod(name, new Class[] {});
3828-
method.invoke(this, new Object[] { });
3816+
Method method = getClass().getMethod(name);
3817+
method.invoke(this);
38293818

38303819
} catch (IllegalArgumentException e) {
38313820
e.printStackTrace();
@@ -6676,8 +6665,8 @@ static private void selectCallback(File selectedFile,
66766665
try {
66776666
Class<?> callbackClass = callbackObject.getClass();
66786667
Method selectMethod =
6679-
callbackClass.getMethod(callbackMethod, new Class[] { File.class });
6680-
selectMethod.invoke(callbackObject, new Object[] { selectedFile });
6668+
callbackClass.getMethod(callbackMethod, File.class);
6669+
selectMethod.invoke(callbackObject, selectedFile);
66816670

66826671
} catch (IllegalAccessException iae) {
66836672
System.err.println(callbackMethod + "() must be public");
@@ -10802,8 +10791,8 @@ public void uncaughtException(Thread t, Throwable e) {
1080210791
Class<?> thinkDifferent =
1080310792
Thread.currentThread().getContextClassLoader().loadClass(td);
1080410793
Method method =
10805-
thinkDifferent.getMethod("init", new Class[] { PApplet.class });
10806-
method.invoke(null, new Object[] { sketch });
10794+
thinkDifferent.getMethod("init", PApplet.class);
10795+
method.invoke(null, sketch);
1080710796
} catch (Exception e) {
1080810797
e.printStackTrace(); // That's unfortunate
1080910798
}

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)