From caaf9db56fc98526b9e794b93283f320ccc6bb30 Mon Sep 17 00:00:00 2001 From: arthur Date: Fri, 13 Nov 2020 21:53:51 +0300 Subject: [PATCH] SPARK-1469: Code cleanup: Fix probable bugs: Remove empty statements. Also remove the code that does nothing. --- .../org/jivesoftware/launcher/Installer.java | 2 - .../spark/component/CheckTree.java | 10 --- .../spark/component/JiveSortableTable.java | 6 -- .../spark/component/JiveTable.java | 6 -- .../jivesoftware/spark/component/Table.java | 6 -- .../jivesoftware/spark/ui/ContactList.java | 4 +- .../ui/conferences/ConferenceRoomBrowser.java | 8 +- .../conferences/GroupChatParticipantList.java | 3 - .../spark/ui/status/CustomMessages.java | 7 +- .../jivesoftware/spark/util/StringUtils.java | 82 +++++++++---------- .../plugin/viewer/PluginRenderer.java | 3 - .../preference/sounds/SoundPreference.java | 5 -- .../sparkimpl/profile/VCardManager.java | 3 - .../search/users/UserSearchForm.java | 7 +- .../game/reversi/ReversiPanel.java | 6 +- .../game/reversi/ReversiPlugin.java | 6 +- 16 files changed, 51 insertions(+), 113 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/launcher/Installer.java b/core/src/main/java/org/jivesoftware/launcher/Installer.java index 414be1282..536cae4b5 100644 --- a/core/src/main/java/org/jivesoftware/launcher/Installer.java +++ b/core/src/main/java/org/jivesoftware/launcher/Installer.java @@ -104,8 +104,6 @@ public class Installer implements InstallAction { */ private void setURI(String path) { boolean exists = WinRegistry.keyExists(RegistryRoot.HKEY_CLASSES_ROOT, "xmpp"); - if (exists) { - } // JOptionPane.showConfirmDialog(null, "Another application is currently registered to handle XMPP instant messaging. Make Spark the default XMPP instant messaging client?", "Confirmation", } WinRegistry.deleteKey(RegistryRoot.HKEY_CLASSES_ROOT, "xmpp", true); diff --git a/core/src/main/java/org/jivesoftware/spark/component/CheckTree.java b/core/src/main/java/org/jivesoftware/spark/component/CheckTree.java index d1cbd4eae..24b83c07a 100644 --- a/core/src/main/java/org/jivesoftware/spark/component/CheckTree.java +++ b/core/src/main/java/org/jivesoftware/spark/component/CheckTree.java @@ -75,20 +75,10 @@ public class CheckTree extends JPanel { CheckNode node = (CheckNode)path.getLastPathComponent(); boolean isSelected = !node.isSelected(); node.setSelected(isSelected); - if (node.getSelectionMode() == CheckNode.DIG_IN_SELECTION) { - if (isSelected) { - //tree.expandPath(path); - } - else { - //tree.collapsePath(path); - } - } ((DefaultTreeModel)tree.getModel()).nodeChanged(node); // I need revalidate if node is root. but why? - tree.revalidate(); tree.repaint(); - } } } diff --git a/core/src/main/java/org/jivesoftware/spark/component/JiveSortableTable.java b/core/src/main/java/org/jivesoftware/spark/component/JiveSortableTable.java index 2719f9747..203ea5018 100644 --- a/core/src/main/java/org/jivesoftware/spark/component/JiveSortableTable.java +++ b/core/src/main/java/org/jivesoftware/spark/component/JiveSortableTable.java @@ -275,9 +275,6 @@ public abstract class JiveSortableTable extends Table { else { setForeground(Color.black); setBackground(Color.white); - if (row % 2 == 0) { - //setBackground( new Color( 156, 207, 255 ) ); - } } if (isBordered) { @@ -362,9 +359,6 @@ public abstract class JiveSortableTable extends Table { else { setForeground(Color.black); setBackground(Color.white); - if (row % 2 == 0) { - //setBackground( new Color( 156, 207, 255 ) ); - } } if (isBordered) { diff --git a/core/src/main/java/org/jivesoftware/spark/component/JiveTable.java b/core/src/main/java/org/jivesoftware/spark/component/JiveTable.java index 35de1e811..a832397ad 100644 --- a/core/src/main/java/org/jivesoftware/spark/component/JiveTable.java +++ b/core/src/main/java/org/jivesoftware/spark/component/JiveTable.java @@ -143,9 +143,6 @@ public class JiveTable extends JTable { else { setForeground(Color.black); setBackground(Color.white); - if (row % 2 == 0) { - //setBackground( new Color( 156, 207, 255 ) ); - } } if (isBordered) { @@ -197,9 +194,6 @@ public class JiveTable extends JTable { else { setForeground(Color.black); setBackground(Color.white); - if (row % 2 == 0) { - //setBackground( new Color( 156, 207, 255 ) ); - } } if (isBordered) { diff --git a/core/src/main/java/org/jivesoftware/spark/component/Table.java b/core/src/main/java/org/jivesoftware/spark/component/Table.java index e50127eca..1356f2732 100644 --- a/core/src/main/java/org/jivesoftware/spark/component/Table.java +++ b/core/src/main/java/org/jivesoftware/spark/component/Table.java @@ -304,9 +304,6 @@ public abstract class Table extends JXTable { else { setForeground(Color.black); setBackground(Color.white); - if (row % 2 == 0) { - //setBackground( new Color( 156, 207, 255 ) ); - } } if (isBordered) { @@ -393,9 +390,6 @@ public abstract class Table extends JXTable { else { setForeground(Color.black); setBackground(Color.white); - if (row % 2 == 0) { - //setBackground( new Color( 156, 207, 255 ) ); - } } if (isBordered) { diff --git a/core/src/main/java/org/jivesoftware/spark/ui/ContactList.java b/core/src/main/java/org/jivesoftware/spark/ui/ContactList.java index fc383a859..069db1e86 100644 --- a/core/src/main/java/org/jivesoftware/spark/ui/ContactList.java +++ b/core/src/main/java/org/jivesoftware/spark/ui/ContactList.java @@ -824,9 +824,7 @@ public class ContactList extends JPanel implements ActionListener, ContactGroup unfiledGrp = getUnfiledGroup(); ContactItem unfiledItem = unfiledGrp.getContactItemByJID(jid.asBareJid()); - if (unfiledItem != null) { - - } else { + if (unfiledItem == null) { ContactItem offlineItem = offlineGroup.getContactItemByJID(jid.asBareJid()); if (offlineItem != null) { if ((rosterEntry.getType() == RosterPacket.ItemType.none || rosterEntry.getType() == RosterPacket.ItemType.from) diff --git a/core/src/main/java/org/jivesoftware/spark/ui/conferences/ConferenceRoomBrowser.java b/core/src/main/java/org/jivesoftware/spark/ui/conferences/ConferenceRoomBrowser.java index 7607cd1c7..5bad729c4 100644 --- a/core/src/main/java/org/jivesoftware/spark/ui/conferences/ConferenceRoomBrowser.java +++ b/core/src/main/java/org/jivesoftware/spark/ui/conferences/ConferenceRoomBrowser.java @@ -344,27 +344,21 @@ public class ConferenceRoomBrowser extends JPanel implements ActionListener, } private RoomObject getRoomsAndInfo(final HostedRoom room) { - boolean stillSearchForOccupants = true; RoomObject result = null; try { try { String roomName = room.getName(); EntityBareJid roomJID = room.getJid(); int numberOfOccupants = -1; - if (stillSearchForOccupants) { RoomInfo roomInfo = null; try { - roomInfo = MultiUserChatManager.getInstanceFor( SparkManager.getConnection() ).getRoomInfo( roomJID ); + roomInfo = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getRoomInfo(roomJID); } catch (Exception e) { // Nothing to do } if (roomInfo != null) { numberOfOccupants = roomInfo.getOccupantsCount(); - if (numberOfOccupants == -1) { - } - } else { - } } result = new RoomObject(); diff --git a/core/src/main/java/org/jivesoftware/spark/ui/conferences/GroupChatParticipantList.java b/core/src/main/java/org/jivesoftware/spark/ui/conferences/GroupChatParticipantList.java index 221f67717..6ef94a3ec 100644 --- a/core/src/main/java/org/jivesoftware/spark/ui/conferences/GroupChatParticipantList.java +++ b/core/src/main/java/org/jivesoftware/spark/ui/conferences/GroupChatParticipantList.java @@ -662,9 +662,6 @@ public class GroupChatParticipantList extends JPanel { while (true) { newNickname = newNickname.trim(); String nick = chat.getNickname().toString(); - if (newNickname.equals(nick)) { - // return; - } try { chat.changeNickname(Resourcepart.from(newNickname)); break; diff --git a/core/src/main/java/org/jivesoftware/spark/ui/status/CustomMessages.java b/core/src/main/java/org/jivesoftware/spark/ui/status/CustomMessages.java index 4c37ff436..805649ff5 100644 --- a/core/src/main/java/org/jivesoftware/spark/ui/status/CustomMessages.java +++ b/core/src/main/java/org/jivesoftware/spark/ui/status/CustomMessages.java @@ -241,10 +241,7 @@ public class CustomMessages { Iterator iter = customItems.iterator(); while (iter.hasNext()) { CustomStatusItem item = iter.next(); - if (item.getType().equals(messageType) && item.getStatus().equals(messageStatus)) { - - } - else { + if (!item.getType().equals(messageType) || !item.getStatus().equals(messageStatus)) { list.add(item); } } @@ -597,4 +594,4 @@ public class CustomMessages { } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/jivesoftware/spark/util/StringUtils.java b/core/src/main/java/org/jivesoftware/spark/util/StringUtils.java index d26865a46..477a7f9ce 100644 --- a/core/src/main/java/org/jivesoftware/spark/util/StringUtils.java +++ b/core/src/main/java/org/jivesoftware/spark/util/StringUtils.java @@ -281,52 +281,50 @@ public class StringUtils { /** * This method takes a string and strips out all tags while still leaving * the tag body intact. - * - * @param in - * the text to be converted. - * @param stripBRTag - * Remove BR tags. + * + * @param in the text to be converted. + * @param stripBRTag Remove BR tags. * @return the input string with all tags removed. */ public static String stripTags(String in, boolean stripBRTag) { - if (in == null) { - return null; - } + if (in == null) { + return null; + } - char ch; - int i = 0; - int last = 0; - char[] input = in.toCharArray(); - int len = input.length; - StringBuilder out = new StringBuilder((int) (len * 1.3)); - for (; i < len; i++) { - ch = input[i]; - if (ch > '>') { - // Nothing to do - } else if (ch == '<') { - if (!stripBRTag && i + 3 < len && input[i + 1] == 'b' - && input[i + 2] == 'r' && input[i + 3] == '>') { - i += 3; - continue; - } - if (i > last) { - if (last > 0) { - out.append(" "); - } - out.append(input, last, i - last); - } - last = i + 1; - } else if (ch == '>') { - last = i + 1; - } - } - if (last == 0) { - return in; - } - if (i > last) { - out.append(input, last, i - last); - } - return out.toString(); + char ch; + int i = 0; + int last = 0; + char[] input = in.toCharArray(); + int len = input.length; + StringBuilder out = new StringBuilder((int) (len * 1.3)); + for (; i < len; i++) { + ch = input[i]; + if (ch <= '>') { + if (ch == '<') { + if (!stripBRTag && i + 3 < len && input[i + 1] == 'b' + && input[i + 2] == 'r' && input[i + 3] == '>') { + i += 3; + continue; + } + if (i > last) { + if (last > 0) { + out.append(" "); + } + out.append(input, last, i - last); + } + last = i + 1; + } else if (ch == '>') { + last = i + 1; + } + } + } + if (last == 0) { + return in; + } + if (i > last) { + out.append(input, last, i - last); + } + return out.toString(); } /** diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginRenderer.java b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginRenderer.java index acca1da18..60d7b78fc 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginRenderer.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginRenderer.java @@ -57,9 +57,6 @@ public class PluginRenderer extends JLabel implements TableCellRenderer { else { setForeground(Color.black); setBackground(Color.white); - if (row % 2 == 0) { - //setBackground( new Color( 156, 207, 255 ) ); - } } if (isBordered) { diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/preference/sounds/SoundPreference.java b/core/src/main/java/org/jivesoftware/sparkimpl/preference/sounds/SoundPreference.java index 82f4afb95..e9a8b1682 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/preference/sounds/SoundPreference.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/preference/sounds/SoundPreference.java @@ -316,7 +316,6 @@ public class SoundPreference implements Preference { return incomingInvitationBox.isSelected(); } - private void pickFile(String title, JTextField field) { if (fc == null) { fc = new JFileChooser(); @@ -336,11 +335,7 @@ public class SoundPreference implements Preference { Log.error(e); } } - else { - - } } - } private File getSoundSettingsFile() { diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java b/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java index e84716324..b1924eabe 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/profile/VCardManager.java @@ -460,10 +460,7 @@ public class VCardManager { // Create temp vcard. vcard = new VCard(); vcard.setJabberId(jid.toString()); - } else { - //System.out.println(jid+" HDD ---------->"); } - return vcard; } diff --git a/core/src/main/java/org/jivesoftware/sparkimpl/search/users/UserSearchForm.java b/core/src/main/java/org/jivesoftware/sparkimpl/search/users/UserSearchForm.java index c6305eb76..0fa897717 100644 --- a/core/src/main/java/org/jivesoftware/sparkimpl/search/users/UserSearchForm.java +++ b/core/src/main/java/org/jivesoftware/sparkimpl/search/users/UserSearchForm.java @@ -139,16 +139,11 @@ public class UserSearchForm extends JPanel { Log.error(ioe); } - } - else { - // Log.error("Search-Searvice-Error: Properties-file does not exist= " + pluginsettings.getPath()); - } - + } if (servicesBox.getItemCount() > 0) { servicesBox.setSelectedIndex(0); } - titlePanel = new TitlePanel("", "", SparkRes.getImageIcon(SparkRes.BLANK_IMAGE), true); add(titlePanel, new GridBagConstraints(0, 0, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); diff --git a/plugins/reversi/src/main/java/org/jivesoftware/game/reversi/ReversiPanel.java b/plugins/reversi/src/main/java/org/jivesoftware/game/reversi/ReversiPanel.java index f7b6de9f8..1fbdcc9cc 100644 --- a/plugins/reversi/src/main/java/org/jivesoftware/game/reversi/ReversiPanel.java +++ b/plugins/reversi/src/main/java/org/jivesoftware/game/reversi/ReversiPanel.java @@ -107,9 +107,9 @@ public class ReversiPanel extends JPanel { // Redraw board. ReversiPanel.this.repaint(); } - else { - // TODO: other user automatically forfeits! - } + // TODO: other user automatically forfeits! + // else { + // } // Execute move. } } diff --git a/plugins/reversi/src/main/java/org/jivesoftware/game/reversi/ReversiPlugin.java b/plugins/reversi/src/main/java/org/jivesoftware/game/reversi/ReversiPlugin.java index 943554424..fdaa0e370 100644 --- a/plugins/reversi/src/main/java/org/jivesoftware/game/reversi/ReversiPlugin.java +++ b/plugins/reversi/src/main/java/org/jivesoftware/game/reversi/ReversiPlugin.java @@ -240,9 +240,9 @@ public class ReversiPlugin implements Plugin { // before adding the new one (possible if the opponent sends two invites // in a row). Object oldInvitation = gameInvitations.put(invitation.getFrom(), inviteAlert); - if (oldInvitation != null) { - // TODO: clean it up by removing it from the transcript window. - } + // TODO: clean it up by removing it from the transcript window. + // if (oldInvitation != null) { + // } // Add the response panel to the transcript window. room.getTranscriptWindow().addComponent(inviteAlert);