diff options
author | Ahmed Ashour <asashour@yahoo.com> | 2017-10-12 10:46:06 +0200 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-10-12 11:46:06 +0300 |
commit | c147b5d85bca3ddf30d9adbcd268066165889f37 (patch) | |
tree | 18d73bda278618004ec4a28ee62af7eb7edbeb98 /client | |
parent | 13d406a7086cc1546eac3fa86f6263bfb436de85 (diff) | |
download | vaadin-framework-c147b5d85bca3ddf30d9adbcd268066165889f37.tar.gz vaadin-framework-c147b5d85bca3ddf30d9adbcd268066165889f37.zip |
Use Collection.isEmpty() (#10172)
Diffstat (limited to 'client')
15 files changed, 45 insertions, 40 deletions
diff --git a/client/src/main/java/com/vaadin/client/componentlocator/ComponentLocator.java b/client/src/main/java/com/vaadin/client/componentlocator/ComponentLocator.java index 9669131651..e0dbfca6b3 100644 --- a/client/src/main/java/com/vaadin/client/componentlocator/ComponentLocator.java +++ b/client/src/main/java/com/vaadin/client/componentlocator/ComponentLocator.java @@ -152,7 +152,7 @@ public class ComponentLocator { for (LocatorStrategy strategy : locatorStrategies) { if (strategy.validatePath(path)) { List<Element> elements = strategy.getElementsByPath(path); - if (elements.size() > 0) { + if (!elements.isEmpty()) { for (Element e : elements) { jsElements.push(e); } @@ -184,7 +184,7 @@ public class ComponentLocator { if (strategy.validatePath(path)) { List<Element> elements = strategy .getElementsByPathStartingAt(path, root); - if (elements.size() > 0) { + if (!elements.isEmpty()) { for (Element e : elements) { jsElements.push(e); } diff --git a/client/src/main/java/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java b/client/src/main/java/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java index b650702c08..2c2ff5707c 100644 --- a/client/src/main/java/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java +++ b/client/src/main/java/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java @@ -118,7 +118,7 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy { path.add(pathFragment); } - if (path.size() == 0) { + if (path.isEmpty()) { // If we didn't find a single element, return null.. return null; } @@ -277,7 +277,7 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy { public List<Element> getElementsByPath(String path) { List<SelectorPredicate> postFilters = SelectorPredicate .extractPostFilterPredicates(path); - if (postFilters.size() > 0) { + if (!postFilters.isEmpty()) { path = path.substring(1, path.lastIndexOf(')')); } @@ -347,7 +347,7 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy { Element root) { List<SelectorPredicate> postFilters = SelectorPredicate .extractPostFilterPredicates(path); - if (postFilters.size() > 0) { + if (!postFilters.isEmpty()) { path = path.substring(1, path.lastIndexOf(')')); } @@ -617,7 +617,7 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy { List<Integer> widgetTags = new ArrayList<>(); widgetTags.addAll(getTags(widgetName)); - if (widgetTags.size() == 0) { + if (widgetTags.isEmpty()) { widgetTags.addAll(getTags("com.vaadin.ui." + widgetName)); } @@ -631,7 +631,7 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy { final String simpleName = getSimpleClassName(name); final String fullName = getFullClassName(name); - if (widgetTags.size() > 0) { + if (!widgetTags.isEmpty()) { Integer[] foundTags = client.getConfiguration() .getTagsForServerSideClassName(fullName); for (int tag : foundTags) { diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/GridDragSourceConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/GridDragSourceConnector.java index bc94293e78..3414133a9d 100644 --- a/client/src/main/java/com/vaadin/client/connectors/grid/GridDragSourceConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/grid/GridDragSourceConnector.java @@ -141,7 +141,7 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { draggedItems = getDraggedRows(nativeEvent); // Ignore event if there are no items dragged - if (draggedItems.size() == 0) { + if (draggedItems.isEmpty()) { return; } @@ -214,9 +214,12 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { final Element selectionColumnCell = getGrid().getSelectionColumn() .isPresent() // -1 is used when even selection column is not frozen - && frozenColumnCount != -1 ? draggedRowElement - .removeChild(draggedRowElement.getFirstChild()) - .cast() : null; + && frozenColumnCount != -1 + ? draggedRowElement + .removeChild( + draggedRowElement.getFirstChild()) + .cast() + : null; final List<String> frozenCellsTransforms = new ArrayList<>(); for (int i = 0; i < getGrid().getColumnCount(); i++) { @@ -331,7 +334,7 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { return; } // Ignore event if there are no items dragged - if (draggedItems != null && draggedItems.size() > 0) { + if (draggedItems != null && !draggedItems.isEmpty()) { super.onDragEnd(event); } @@ -448,8 +451,8 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { * @return Stream of dragged table row elements. */ private Stream<TableRowElement> getDraggedRowElementStream() { - return draggedItems.stream() - .map(row -> ((AbstractRemoteDataSource<JsonObject>) gridConnector + return draggedItems.stream().map( + row -> ((AbstractRemoteDataSource<JsonObject>) gridConnector .getDataSource()).indexOf(row)) .map(getGridBody()::getRowElement); } diff --git a/client/src/main/java/com/vaadin/client/debug/internal/AnalyzeLayoutsPanel.java b/client/src/main/java/com/vaadin/client/debug/internal/AnalyzeLayoutsPanel.java index a1bcae5524..88a85cb764 100644 --- a/client/src/main/java/com/vaadin/client/debug/internal/AnalyzeLayoutsPanel.java +++ b/client/src/main/java/com/vaadin/client/debug/internal/AnalyzeLayoutsPanel.java @@ -83,17 +83,17 @@ public class AnalyzeLayoutsPanel extends FlowPanel { Set<ComponentConnector> zeroWidthComponents = new HashSet<>(); findZeroSizeComponents(zeroHeightComponents, zeroWidthComponents, ac.getUIConnector()); - if (zeroHeightComponents.size() > 0 || zeroWidthComponents.size() > 0) { + if (!zeroHeightComponents.isEmpty() || !zeroWidthComponents.isEmpty()) { add(new HTML("<h4> Client side notifications</h4>" + " <em>The following relative sized components were " + "rendered to a zero size container on the client side." + " Note that these are not necessarily invalid " + "states, but reported here as they might be.</em>")); - if (zeroHeightComponents.size() > 0) { + if (!zeroHeightComponents.isEmpty()) { add(new HTML("<p><strong>Vertically zero size:</strong></p>")); printClientSideDetectedIssues(zeroHeightComponents, ac); } - if (zeroWidthComponents.size() > 0) { + if (!zeroWidthComponents.isEmpty()) { add(new HTML( "<p><strong>Horizontally zero size:</strong></p>")); printClientSideDetectedIssues(zeroWidthComponents, ac); diff --git a/client/src/main/java/com/vaadin/client/debug/internal/InfoSection.java b/client/src/main/java/com/vaadin/client/debug/internal/InfoSection.java index c0efe72b78..9e688349ad 100644 --- a/client/src/main/java/com/vaadin/client/debug/internal/InfoSection.java +++ b/client/src/main/java/com/vaadin/client/debug/internal/InfoSection.java @@ -142,7 +142,7 @@ public class InfoSection implements Section { clear(); List<ApplicationConnection> apps = ApplicationConfiguration .getRunningApplications(); - if (apps.size() == 0) { + if (apps.isEmpty()) { // try again in a while refresher.schedule(1000); } else { diff --git a/client/src/main/java/com/vaadin/client/debug/internal/SelectorPath.java b/client/src/main/java/com/vaadin/client/debug/internal/SelectorPath.java index 268924b143..07da3fbd4a 100644 --- a/client/src/main/java/com/vaadin/client/debug/internal/SelectorPath.java +++ b/client/src/main/java/com/vaadin/client/debug/internal/SelectorPath.java @@ -80,7 +80,7 @@ public class SelectorPath { String tmpPath = path; List<SelectorPredicate> postFilters = SelectorPredicate .extractPostFilterPredicates(path); - if (postFilters.size() > 0) { + if (!postFilters.isEmpty()) { tmpPath = tmpPath.substring(1, tmpPath.lastIndexOf(')')); if (tmpPath.contains("#")) { // FIXME: SubParts should be handled. diff --git a/client/src/main/java/com/vaadin/client/extensions/FileDropTargetConnector.java b/client/src/main/java/com/vaadin/client/extensions/FileDropTargetConnector.java index 2d4048bc78..6d9a5c3bba 100644 --- a/client/src/main/java/com/vaadin/client/extensions/FileDropTargetConnector.java +++ b/client/src/main/java/com/vaadin/client/extensions/FileDropTargetConnector.java @@ -80,7 +80,7 @@ public class FileDropTargetConnector extends DropTargetExtensionConnector { */ private void uploadNextFile() { Scheduler.get().scheduleDeferred(() -> { - if (!uploading && uploadUrls.size() > 0) { + if (!uploading && !uploadUrls.isEmpty()) { uploading = true; String nextId = uploadUrls.keySet().stream().findAny().get(); @@ -124,7 +124,7 @@ public class FileDropTargetConnector extends DropTargetExtensionConnector { } // Request a list of upload URLs for the dropped files - if (fileParams.size() > 0) { + if (!fileParams.isEmpty()) { getRpcProxy(FileDropTargetRpc.class).drop(fileParams); } @@ -197,7 +197,8 @@ public class FileDropTargetConnector extends DropTargetExtensionConnector { protected FileUploadXHR() { } - public final native void postFile(File file) /*-{ + public final native void postFile(File file) + /*-{ this.setRequestHeader('Content-Type', 'multipart/form-data'); this.send(file); }-*/; diff --git a/client/src/main/java/com/vaadin/client/extensions/ResponsiveConnector.java b/client/src/main/java/com/vaadin/client/extensions/ResponsiveConnector.java index 7115c1e3c6..3af049c635 100644 --- a/client/src/main/java/com/vaadin/client/extensions/ResponsiveConnector.java +++ b/client/src/main/java/com/vaadin/client/extensions/ResponsiveConnector.java @@ -107,7 +107,7 @@ public class ResponsiveConnector extends AbstractExtensionConnector selectors.append('.').append(primaryStyle); if (target.getState().styles != null - && target.getState().styles.size() > 0) { + && !target.getState().styles.isEmpty()) { for (String style : target.getState().styles) { selectors.append(",.").append(style); selectors.append(",.").append(primaryStyle).append('.') diff --git a/client/src/main/java/com/vaadin/client/ui/VComboBox.java b/client/src/main/java/com/vaadin/client/ui/VComboBox.java index 37b94ef8d6..5d98fd25d6 100644 --- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java +++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java @@ -1067,7 +1067,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, * Gets the preferred height of the menu including pageItemsCount items. */ String getPreferredHeight(int pageItemsCount) { - if (currentSuggestions.size() > 0) { + if (!currentSuggestions.isEmpty()) { final int pixels = getPreferredHeight() / currentSuggestions.size() * pageItemsCount; return pixels + "px"; @@ -1260,7 +1260,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, */ int getItemOffsetHeight() { List<MenuItem> items = getItems(); - return items != null && items.size() > 0 + return items != null && !items.isEmpty() ? items.get(0).getOffsetHeight() : 0; } @@ -1270,7 +1270,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, */ int getItemOffsetWidth() { List<MenuItem> items = getItems(); - return items != null && items.size() > 0 + return items != null && !items.isEmpty() ? items.get(0).getOffsetWidth() : 0; } diff --git a/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java b/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java index 20a0afcf0d..0202cdf430 100644 --- a/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java +++ b/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java @@ -248,7 +248,7 @@ public class VDragAndDropWrapper extends VCustomComponent @Override public void execute() { if (!uploading) { - if (fileIds.size() > 0) { + if (!fileIds.isEmpty()) { uploading = true; final Integer fileId = fileIds.remove(0); diff --git a/client/src/main/java/com/vaadin/client/ui/VMenuBar.java b/client/src/main/java/com/vaadin/client/ui/VMenuBar.java index 8f0026dc14..432f44fe05 100644 --- a/client/src/main/java/com/vaadin/client/ui/VMenuBar.java +++ b/client/src/main/java/com/vaadin/client/ui/VMenuBar.java @@ -1116,7 +1116,7 @@ public class VMenuBar extends SimpleFocusablePanel // Only collapse if there is more than one item in the root menu and the // menu has an explicit size if ((getItems().size() > 1 || (collapsedRootItems != null - && collapsedRootItems.getItems().size() > 0)) + && !collapsedRootItems.getItems().isEmpty())) && getElement().getStyle().getProperty("width") != null && moreItem != null) { @@ -1144,7 +1144,7 @@ public class VMenuBar extends SimpleFocusablePanel } int widthReduced = 0; - while (widthReduced < widthNeeded && getItems().size() > 0) { + while (widthReduced < widthNeeded && !getItems().isEmpty()) { // Move last root menu item to collapsed menu CustomMenuItem collapse = getItems() .get(getItems().size() - 1); @@ -1152,21 +1152,21 @@ public class VMenuBar extends SimpleFocusablePanel removeItem(collapse); collapsedRootItems.addItem(collapse, 0); } - } else if (collapsedRootItems.getItems().size() > 0) { + } else if (!collapsedRootItems.getItems().isEmpty()) { // Space available for items: expand first items from collapsed // menu int widthAvailable = diff + moreItemWidth; int widthGrowth = 0; while (widthAvailable > widthGrowth - && collapsedRootItems.getItems().size() > 0) { + && !collapsedRootItems.getItems().isEmpty()) { // Move first item from collapsed menu to the root menu CustomMenuItem expand = collapsedRootItems.getItems() .get(0); collapsedRootItems.removeItem(expand); addItem(expand); widthGrowth += expand.getOffsetWidth(); - if (collapsedRootItems.getItems().size() > 0) { + if (!collapsedRootItems.getItems().isEmpty()) { widthAvailable -= moreItemWidth; } if (widthGrowth > widthAvailable) { @@ -1177,7 +1177,7 @@ public class VMenuBar extends SimpleFocusablePanel } } } - if (collapsedRootItems.getItems().size() > 0) { + if (!collapsedRootItems.getItems().isEmpty()) { addItem(moreItem); } } diff --git a/client/src/main/java/com/vaadin/client/ui/VWindow.java b/client/src/main/java/com/vaadin/client/ui/VWindow.java index c39da6d168..df2c4b17f3 100644 --- a/client/src/main/java/com/vaadin/client/ui/VWindow.java +++ b/client/src/main/java/com/vaadin/client/ui/VWindow.java @@ -327,7 +327,7 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, } private static VWindow getTopmostWindow() { - if (windowOrder.size() > 0) { + if (!windowOrder.isEmpty()) { return windowOrder.get(windowOrder.size() - 1); } return null; diff --git a/client/src/main/java/com/vaadin/client/ui/menubar/MenuBar.java b/client/src/main/java/com/vaadin/client/ui/menubar/MenuBar.java index 099cf15489..fae876165b 100644 --- a/client/src/main/java/com/vaadin/client/ui/menubar/MenuBar.java +++ b/client/src/main/java/com/vaadin/client/ui/menubar/MenuBar.java @@ -331,7 +331,7 @@ public class MenuBar extends Widget implements PopupListener { * @return the first item from the menu or null if no items. */ public MenuItem getFirstItem() { - return items != null && items.size() > 0 ? items.get(0) : null; + return items != null && !items.isEmpty() ? items.get(0) : null; } /** @@ -341,7 +341,7 @@ public class MenuBar extends Widget implements PopupListener { * @return the last item from the menu or null if no items. */ public MenuItem getLastItem() { - return items != null && items.size() > 0 ? items.get(items.size() - 1) + return items != null && !items.isEmpty() ? items.get(items.size() - 1) : null; } @@ -627,7 +627,7 @@ public class MenuBar extends Widget implements PopupListener { */ private void onShow() { // Select the first item when a menu is shown. - if (items.size() > 0) { + if (!items.isEmpty()) { selectItem(items.get(0)); } } diff --git a/client/src/main/java/com/vaadin/client/widget/grid/datasources/ListSorter.java b/client/src/main/java/com/vaadin/client/widget/grid/datasources/ListSorter.java index 14cb2e6523..07fc05622b 100644 --- a/client/src/main/java/com/vaadin/client/widget/grid/datasources/ListSorter.java +++ b/client/src/main/java/com/vaadin/client/widget/grid/datasources/ListSorter.java @@ -159,11 +159,12 @@ public class ListSorter<T> { if (result != 0) { return o.getDirection() == SortDirection.ASCENDING - ? result : -result; + ? result + : -result; } } - if (order.size() > 0) { + if (!order.isEmpty()) { return order.get(0) .getDirection() == SortDirection.ASCENDING ? a.hashCode() - b.hashCode() diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java index 6adc0cbef9..61887dd980 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java +++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java @@ -425,7 +425,7 @@ public class Escalator extends Widget velocity = delta / ellapsed; // if last speed was so low, reset speeds and start // storing again - if (speeds.size() > 0 && !validSpeed(speeds.get(0))) { + if (!speeds.isEmpty() && !validSpeed(speeds.get(0))) { speeds.clear(); run = true; } |