Skip to content

Commit f640c7a

Browse files
turbanoffmrserb
authored andcommitted
8274806: Simplify equals() call on nullable variable and a constant in java.desktop
Reviewed-by: serb, pbansal
1 parent 9c431dd commit f640c7a

File tree

11 files changed

+16
-17
lines changed

11 files changed

+16
-17
lines changed

src/java.desktop/macosx/classes/sun/lwawt/macosx/CMenuItem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -55,7 +55,7 @@ protected void initialize(MenuItem target) {
5555

5656
private boolean isSeparator() {
5757
String label = ((MenuItem)getTarget()).getLabel();
58-
return (label != null && label.equals("-"));
58+
return "-".equals(label);
5959
}
6060

6161
@Override

src/java.desktop/share/classes/java/awt/Window.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,11 @@ public static enum Type {
417417
@SuppressWarnings("removal")
418418
String s = java.security.AccessController.doPrivileged(
419419
new GetPropertyAction("java.awt.syncLWRequests"));
420-
systemSyncLWRequests = (s != null && s.equals("true"));
420+
systemSyncLWRequests = "true".equals(s);
421421
@SuppressWarnings("removal")
422422
String s2 = java.security.AccessController.doPrivileged(
423423
new GetPropertyAction("java.awt.Window.locationByPlatform"));
424-
locationByPlatformProp = (s2 != null && s2.equals("true"));
424+
locationByPlatformProp = "true".equals(s2);
425425
}
426426

427427
/**

src/java.desktop/share/classes/javax/swing/DefaultDesktopManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -328,9 +328,9 @@ private void setupDragMode(JComponent f) {
328328
Window window = SwingUtilities.getWindowAncestor(f);
329329
if (window != null && !window.isOpaque()) {
330330
dragMode = DEFAULT_DRAG_MODE;
331-
} else if (mode != null && mode.equals("outline")) {
331+
} else if ("outline".equals(mode)) {
332332
dragMode = OUTLINE_DRAG_MODE;
333-
} else if (mode != null && mode.equals("faster")
333+
} else if ("faster".equals(mode)
334334
&& f instanceof JInternalFrame
335335
&& ((JInternalFrame)f).isOpaque() &&
336336
(parent == null || parent.isOpaque())) {

src/java.desktop/share/classes/javax/swing/JLayeredPane.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -205,7 +205,7 @@ private void validateOptimizedDrawing() {
205205
(layer = (Integer)((JComponent)c).
206206
getClientProperty(LAYER_PROPERTY)) != null))
207207
{
208-
if(layer != null && layer.equals(FRAME_CONTENT_LAYER))
208+
if (FRAME_CONTENT_LAYER.equals(layer))
209209
continue;
210210
layeredComponentFound = true;
211211
break;

src/java.desktop/share/classes/javax/swing/filechooser/FileSystemView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ public boolean isFloppyDrive(File dir) {
824824
public boolean isComputerNode(File dir) {
825825
if (dir != null) {
826826
String parent = dir.getParent();
827-
if (parent != null && parent.equals("/net")) {
827+
if ("/net".equals(parent)) {
828828
return true;
829829
}
830830
}

src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ public View create(Element elem) {
13261326
} else if (kind == HTML.Tag.IMPLIED) {
13271327
String ws = (String) elem.getAttributes().getAttribute(
13281328
CSS.Attribute.WHITE_SPACE);
1329-
if ((ws != null) && ws.equals("pre")) {
1329+
if ("pre".equals(ws)) {
13301330
return new LineView(elem);
13311331
}
13321332
return new javax.swing.text.html.ParagraphView(elem);

src/java.desktop/share/classes/sun/java2d/SurfaceDataProxy.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import sun.java2d.loops.Blit;
3838
import sun.java2d.loops.BlitBg;
3939
import sun.awt.image.SurfaceManager;
40-
import sun.awt.image.SurfaceManager.FlushableCacheData;
4140

4241
import java.security.AccessController;
4342
import sun.security.action.GetPropertyAction;
@@ -74,7 +73,7 @@ public abstract class SurfaceDataProxy
7473
@SuppressWarnings("removal")
7574
String manimg = AccessController.doPrivileged(
7675
new GetPropertyAction("sun.java2d.managedimages"));
77-
if (manimg != null && manimg.equals("false")) {
76+
if ("false".equals(manimg)) {
7877
cachingAllowed = false;
7978
System.out.println("Disabling managed images");
8079
}

src/java.desktop/share/classes/sun/print/RasterPrinterJob.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ public void print(PrintRequestAttributeSet attributes)
15471547
* PrintRequestAttributeSet while calling print(attributes)
15481548
*/
15491549
JobSheets js = (JobSheets)psvc.getDefaultAttributeValue(JobSheets.class);
1550-
if (js != null && js.equals(JobSheets.NONE)) {
1550+
if (JobSheets.NONE.equals(js)) {
15511551
noJobSheet = true;
15521552
}
15531553

src/java.desktop/unix/classes/sun/awt/X11/XTaskbarPeer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class XTaskbarPeer implements TaskbarPeer {
4848
String de = AccessController.doPrivileged(
4949
(PrivilegedAction<String>) ()
5050
-> System.getenv("XDG_CURRENT_DESKTOP"));
51-
isUnity = de != null && de.equals("Unity");
51+
isUnity = "Unity".equals(de);
5252
}
5353

5454
private static void initWithLock() {

src/java.desktop/unix/classes/sun/print/UnixPrintJob.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public class UnixPrintJob implements CancelablePrintJob {
128128
mDestType = UnixPrintJob.DESTPRINTER;
129129
JobSheets js = (JobSheets)(service.
130130
getDefaultAttributeValue(JobSheets.class));
131-
if (js != null && js.equals(JobSheets.NONE)) {
131+
if (JobSheets.NONE.equals(js)) {
132132
mNoJobSheet = true;
133133
}
134134
}

0 commit comments

Comments
 (0)