Minor code cleanup
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/ec5df09b Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/ec5df09b Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/ec5df09b Branch: refs/heads/master Commit: ec5df09b76d0415985ea50a9b29ab77f22a4304e Parents: c6a44cc Author: stariy <stari...@gmail.com> Authored: Mon Mar 5 11:10:25 2018 +0300 Committer: stariy <stari...@gmail.com> Committed: Mon Mar 5 11:10:25 2018 +0300 ---------------------------------------------------------------------- .../cayenne/map/SQLTemplateDescriptor.java | 9 ++--- .../cayenne/map/SelectQueryDescriptor.java | 8 ++--- .../modeler/editor/SQLTemplatePrefetchTab.java | 35 ++++++++++---------- .../modeler/editor/SelectQueryPrefetchTab.java | 30 ++++++++--------- 4 files changed, 39 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cayenne/blob/ec5df09b/cayenne-server/src/main/java/org/apache/cayenne/map/SQLTemplateDescriptor.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/SQLTemplateDescriptor.java b/cayenne-server/src/main/java/org/apache/cayenne/map/SQLTemplateDescriptor.java index 785d32f..5b6a79f 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/map/SQLTemplateDescriptor.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/map/SQLTemplateDescriptor.java @@ -107,12 +107,9 @@ public class SQLTemplateDescriptor extends QueryDescriptor { template.setRoot(root); } - - - HashMap<String, Integer> prefetches = this.getPrefetchesMap(); - if (prefetches != null && !prefetches.isEmpty()) { - for (String prefetch : prefetches.keySet()) { - template.addPrefetch(PrefetchTreeNode.withPath(prefetch, prefetchesMap.get(prefetch))); + if (prefetchesMap != null) { + for (Map.Entry<String, Integer> entry : prefetchesMap.entrySet()) { + template.addPrefetch(PrefetchTreeNode.withPath(entry.getKey(), entry.getValue())); } } http://git-wip-us.apache.org/repos/asf/cayenne/blob/ec5df09b/cayenne-server/src/main/java/org/apache/cayenne/map/SelectQueryDescriptor.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/SelectQueryDescriptor.java b/cayenne-server/src/main/java/org/apache/cayenne/map/SelectQueryDescriptor.java index fa1590a..7b04910 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/map/SelectQueryDescriptor.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/map/SelectQueryDescriptor.java @@ -28,6 +28,7 @@ import org.apache.cayenne.util.XMLEncoder; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @since 4.0 @@ -175,10 +176,9 @@ public class SelectQueryDescriptor extends QueryDescriptor { selectQuery.addOrderings(orderings); } - HashMap<String, Integer> prefetchesMap = this.getPrefetchesMap(); - if(prefetchesMap != null && !prefetchesMap.isEmpty()) { - for(String prefetch : prefetchesMap.keySet()) { - selectQuery.addPrefetch(PrefetchTreeNode.withPath(prefetch, prefetchesMap.get(prefetch))); + if (prefetchesMap != null) { + for (Map.Entry<String, Integer> entry : prefetchesMap.entrySet()) { + selectQuery.addPrefetch(PrefetchTreeNode.withPath(entry.getKey(), entry.getValue())); } } http://git-wip-us.apache.org/repos/asf/cayenne/blob/ec5df09b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplatePrefetchTab.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplatePrefetchTab.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplatePrefetchTab.java index 49f8a67..1375429 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplatePrefetchTab.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplatePrefetchTab.java @@ -63,8 +63,6 @@ import java.awt.CardLayout; import java.awt.Dimension; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.util.ArrayList; -import java.util.List; import java.util.prefs.Preferences; /** @@ -79,11 +77,11 @@ public class SQLTemplatePrefetchTab extends JPanel implements PropertyChangeList private static final String DISJOINT_BY_ID_PREFETCH_SEMANTICS = "Disjoint by id"; private static final String UNDEFINED_SEMANTICS = "Undefined semantics"; - static final Dimension BROWSER_CELL_DIM = new Dimension(150, 100); - static final Dimension TABLE_DIM = new Dimension(460, 60); + private static final Dimension BROWSER_CELL_DIM = new Dimension(150, 100); + private static final Dimension TABLE_DIM = new Dimension(460, 60); - static final String REAL_PANEL = "real"; - static final String PLACEHOLDER_PANEL = "placeholder"; + private static final String REAL_PANEL = "real"; + private static final String PLACEHOLDER_PANEL = "placeholder"; protected ProjectController mediator; protected SQLTemplateDescriptor sqlTemplate; @@ -169,7 +167,7 @@ public class SQLTemplatePrefetchTab extends JPanel implements PropertyChangeList protected void setUpPrefetchBox(TableColumn column) { - JComboBox prefetchBox = new JComboBox(); + JComboBox<String> prefetchBox = new JComboBox<>(); prefetchBox.addItem(JOINT_PREFETCH_SEMANTICS); prefetchBox.addItem(DISJOINT_BY_ID_PREFETCH_SEMANTICS); @@ -344,12 +342,10 @@ public class SQLTemplatePrefetchTab extends JPanel implements PropertyChangeList Object object = exp.evaluate(root); if (object instanceof Relationship) { return ((Relationship) object).isToMany(); - } - else { + } else { return false; } - } - catch (ExpressionException e) { + } catch (ExpressionException e) { return false; } } @@ -404,22 +400,21 @@ public class SQLTemplatePrefetchTab extends JPanel implements PropertyChangeList PrefetchModel() { if (sqlTemplate != null) { - prefetches = new String[sqlTemplate.getPrefetchesMap().size()]; - List<String> list = new ArrayList<>(sqlTemplate.getPrefetchesMap().keySet()); - for(int i = 0; i < list.size(); i++){ - prefetches[i] = list.get(i); - } + prefetches = sqlTemplate.getPrefetchesMap().keySet().toArray(new String[0]); } } + @Override public int getColumnCount() { return 3; } + @Override public int getRowCount() { return (prefetches != null) ? prefetches.length : 0; } + @Override public Object getValueAt(int row, int column) { switch (column) { case 0: @@ -433,6 +428,7 @@ public class SQLTemplatePrefetchTab extends JPanel implements PropertyChangeList } } + @Override public Class getColumnClass(int column) { switch (column) { case 0: @@ -446,6 +442,7 @@ public class SQLTemplatePrefetchTab extends JPanel implements PropertyChangeList } } + @Override public String getColumnName(int column) { switch (column) { case 0: @@ -459,14 +456,16 @@ public class SQLTemplatePrefetchTab extends JPanel implements PropertyChangeList } } + @Override public boolean isCellEditable(int row, int column) { - return column == 2 ? true : false; + return column == 2; } + @Override public void setValueAt(Object value, int row, int column) { switch (column) { case 2: - sqlTemplate.addPrefetch(prefetches[row],getPrefetchType((String)value)); + sqlTemplate.addPrefetch(prefetches[row], getPrefetchType((String)value)); break; } } http://git-wip-us.apache.org/repos/asf/cayenne/blob/ec5df09b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryPrefetchTab.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryPrefetchTab.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryPrefetchTab.java index c75b6eb..1c4ac54 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryPrefetchTab.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryPrefetchTab.java @@ -47,8 +47,6 @@ import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableColumn; import javax.swing.table.TableModel; import javax.swing.tree.TreeModel; -import java.util.ArrayList; -import java.util.List; /** * Subclass of the SelectQueryOrderingTab configured to work with prefetches. @@ -72,7 +70,7 @@ public class SelectQueryPrefetchTab extends SelectQueryOrderingTab { protected void setUpPrefetchBox(TableColumn column) { - JComboBox prefetchBox = new JComboBox(); + JComboBox<String> prefetchBox = new JComboBox<>(); prefetchBox.addItem(JOINT_PREFETCH_SEMANTICS); prefetchBox.addItem(DISJOINT_PREFETCH_SEMANTICS); prefetchBox.addItem(DISJOINT_BY_ID_PREFETCH_SEMANTICS); @@ -192,12 +190,10 @@ public class SelectQueryPrefetchTab extends SelectQueryOrderingTab { Object object = exp.evaluate(root); if (object instanceof Relationship) { return ((Relationship) object).isToMany(); - } - else { + } else { return false; } - } - catch (ExpressionException e) { + } catch (ExpressionException e) { return false; } } @@ -235,22 +231,21 @@ public class SelectQueryPrefetchTab extends SelectQueryOrderingTab { PrefetchModel() { if (selectQuery != null) { - prefetches = new String[selectQuery.getPrefetchesMap().size()]; - List<String> list = new ArrayList<>(selectQuery.getPrefetchesMap().keySet()); - for(int i = 0; i < list.size(); i++) { - prefetches[i] = list.get(i); - } + prefetches = selectQuery.getPrefetchesMap().keySet().toArray(new String[0]); } } + @Override public int getColumnCount() { return 3; } + @Override public int getRowCount() { return (prefetches != null) ? prefetches.length : 0; } + @Override public Object getValueAt(int row, int column) { switch (column) { case 0: @@ -264,6 +259,7 @@ public class SelectQueryPrefetchTab extends SelectQueryOrderingTab { } } + @Override public Class getColumnClass(int column) { switch (column) { case 0: @@ -277,6 +273,7 @@ public class SelectQueryPrefetchTab extends SelectQueryOrderingTab { } } + @Override public String getColumnName(int column) { switch (column) { case 0: @@ -286,14 +283,17 @@ public class SelectQueryPrefetchTab extends SelectQueryOrderingTab { case 2: return "Prefetch Type"; default: - throw new IndexOutOfBoundsException("Invalid columnw: " + column); + throw new IndexOutOfBoundsException("Invalid column: " + column); } } + @Override public boolean isCellEditable(int row, int column) { - return column == 2 ? true : false; + return column == 2; } - public void setValueAt(Object value, int row, int column){ + + @Override + public void setValueAt(Object value, int row, int column) { switch (column) { case 2: selectQuery.addPrefetch(prefetches[row], getPrefetchType((String)value));