From: Leif Åstrand Date: Mon, 30 Jul 2012 10:31:26 +0000 (+0000) Subject: Improved code readability based on review (#8109) X-Git-Tag: 7.0.0.beta1~79^2~60 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7635949eb052473472fbe9a50e563f6ef8730e2f;p=vaadin-framework.git Improved code readability based on review (#8109) svn changeset:24033/svn branch:6.8 --- diff --git a/src/com/vaadin/ui/AbstractSelect.java b/src/com/vaadin/ui/AbstractSelect.java index 1a781dd4f3..e0d1f4e3f2 100644 --- a/src/com/vaadin/ui/AbstractSelect.java +++ b/src/com/vaadin/ui/AbstractSelect.java @@ -396,7 +396,8 @@ public abstract class AbstractSelect extends AbstractField implements // Selection change if (variables.containsKey("selected")) { - final String[] ka = (String[]) variables.get("selected"); + final String[] clientSideSelectedKeys = (String[]) variables + .get("selected"); // Multiselect mode if (isMultiSelect()) { @@ -404,19 +405,20 @@ public abstract class AbstractSelect extends AbstractField implements // TODO Optimize by adding repaintNotNeeded when applicable // Converts the key-array to id-set - final LinkedList s = new LinkedList(); - for (int i = 0; i < ka.length; i++) { - final Object id = itemIdMapper.get(ka[i]); + final LinkedList acceptedSelections = new LinkedList(); + for (int i = 0; i < clientSideSelectedKeys.length; i++) { + final Object id = itemIdMapper + .get(clientSideSelectedKeys[i]); if (!isNullSelectionAllowed() && (id == null || id == getNullSelectionItemId())) { // skip empty selection if nullselection is not allowed requestRepaint(); } else if (id != null && containsId(id)) { - s.add(id); + acceptedSelections.add(id); } } - if (!isNullSelectionAllowed() && s.size() < 1) { + if (!isNullSelectionAllowed() && acceptedSelections.size() < 1) { // empty selection not allowed, keep old value requestRepaint(); return; @@ -424,11 +426,11 @@ public abstract class AbstractSelect extends AbstractField implements // Limits the deselection to the set of visible items // (non-visible items can not be deselected) - Collection visible = getVisibleItemIds(); - if (visible != null) { - visible = new HashSet(visible); + Collection visibleNotSelected = getVisibleItemIds(); + if (visibleNotSelected != null) { + visibleNotSelected = new HashSet(visibleNotSelected); // Don't remove those that will be added to preserve order - visible.removeAll(s); + visibleNotSelected.removeAll(acceptedSelections); @SuppressWarnings("unchecked") Set newsel = (Set) getValue(); @@ -437,18 +439,19 @@ public abstract class AbstractSelect extends AbstractField implements } else { newsel = new LinkedHashSet(newsel); } - newsel.removeAll(visible); - newsel.addAll(s); + newsel.removeAll(visibleNotSelected); + newsel.addAll(acceptedSelections); setValue(newsel, true); } } else { // Single select mode if (!isNullSelectionAllowed() - && (ka.length == 0 || ka[0] == null || ka[0] == getNullSelectionItemId())) { + && (clientSideSelectedKeys.length == 0 + || clientSideSelectedKeys[0] == null || clientSideSelectedKeys[0] == getNullSelectionItemId())) { requestRepaint(); return; } - if (ka.length == 0) { + if (clientSideSelectedKeys.length == 0) { // Allows deselection only if the deselected item is // visible final Object current = getValue(); @@ -457,7 +460,8 @@ public abstract class AbstractSelect extends AbstractField implements setValue(null, true); } } else { - final Object id = itemIdMapper.get(ka[0]); + final Object id = itemIdMapper + .get(clientSideSelectedKeys[0]); if (!isNullSelectionAllowed() && id == null) { requestRepaint(); } else if (id != null diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index c4d90d7790..e96636dd70 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -2294,8 +2294,9 @@ public class Table extends AbstractSelect implements Action.Container, * The end key * @return */ - private Set getItemIdsInRange(Object itemId, final int length) { - HashSet ids = new LinkedHashSet(); + private LinkedHashSet getItemIdsInRange(Object itemId, + final int length) { + LinkedHashSet ids = new LinkedHashSet(); for (int i = 0; i < length; i++) { assert itemId != null; // should not be null unless client-server // are out of sync @@ -2315,7 +2316,7 @@ public class Table extends AbstractSelect implements Action.Container, final String[] ka = (String[]) variables.get("selected"); final String[] ranges = (String[]) variables.get("selectedRanges"); - Set renderedItemIds = getCurrentlyRenderedItemIds(); + Set renderedButNotSelectedItemIds = getCurrentlyRenderedItemIds(); @SuppressWarnings("unchecked") HashSet newValue = new LinkedHashSet( @@ -2340,7 +2341,7 @@ public class Table extends AbstractSelect implements Action.Container, requestRepaint(); } else if (id != null && containsId(id)) { newValue.add(id); - renderedItemIds.remove(id); + renderedButNotSelectedItemIds.remove(id); } } @@ -2350,17 +2351,17 @@ public class Table extends AbstractSelect implements Action.Container, String[] split = range.split("-"); Object startItemId = itemIdMapper.get(split[0]); int length = Integer.valueOf(split[1]); - Set itemIdsInRange = getItemIdsInRange(startItemId, - length); + LinkedHashSet itemIdsInRange = getItemIdsInRange( + startItemId, length); newValue.addAll(itemIdsInRange); - renderedItemIds.removeAll(itemIdsInRange); + renderedButNotSelectedItemIds.removeAll(itemIdsInRange); } } /* * finally clear all currently rendered rows (the ones that the client * side counterpart is aware of) that the client didn't send as selected */ - newValue.removeAll(renderedItemIds); + newValue.removeAll(renderedButNotSelectedItemIds); if (!isNullSelectionAllowed() && newValue.isEmpty()) { // empty selection not allowed, keep old value