diff --git a/openjpa-examples/image-gallery/src/test/java/org/apache/openjpa/example/gallery/constraint/ImageConstraint.java b/openjpa-examples/image-gallery/src/test/java/org/apache/openjpa/example/gallery/constraint/ImageConstraint.java index ff2c569ce..2605fda13 100644 --- a/openjpa-examples/image-gallery/src/test/java/org/apache/openjpa/example/gallery/constraint/ImageConstraint.java +++ b/openjpa-examples/image-gallery/src/test/java/org/apache/openjpa/example/gallery/constraint/ImageConstraint.java @@ -18,18 +18,19 @@ */ package org.apache.openjpa.example.gallery.constraint; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static org.apache.openjpa.example.gallery.ImageType.GIF; +import static org.apache.openjpa.example.gallery.ImageType.JPEG; + import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; import javax.validation.Constraint; import javax.validation.Payload; import org.apache.openjpa.example.gallery.ImageType; -import static org.apache.openjpa.example.gallery.ImageType.GIF; -import static org.apache.openjpa.example.gallery.ImageType.JPEG; /** * Type-level annotation used to specify an image constraint. Uses diff --git a/openjpa-examples/image-gallery/src/test/java/org/apache/openjpa/example/gallery/constraint/ImageContent.java b/openjpa-examples/image-gallery/src/test/java/org/apache/openjpa/example/gallery/constraint/ImageContent.java index ee9153d07..fb663a981 100644 --- a/openjpa-examples/image-gallery/src/test/java/org/apache/openjpa/example/gallery/constraint/ImageContent.java +++ b/openjpa-examples/image-gallery/src/test/java/org/apache/openjpa/example/gallery/constraint/ImageContent.java @@ -18,19 +18,20 @@ */ package org.apache.openjpa.example.gallery.constraint; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static org.apache.openjpa.example.gallery.ImageType.GIF; +import static org.apache.openjpa.example.gallery.ImageType.JPEG; + import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; import javax.validation.Constraint; import javax.validation.Payload; import org.apache.openjpa.example.gallery.ImageType; -import static org.apache.openjpa.example.gallery.ImageType.GIF; -import static org.apache.openjpa.example.gallery.ImageType.JPEG; /** * Attribute-level annotation used to specify an image content constraint. Uses diff --git a/openjpa-examples/image-gallery/src/test/java/org/apache/openjpa/example/gallery/constraint/ImageContentValidator.java b/openjpa-examples/image-gallery/src/test/java/org/apache/openjpa/example/gallery/constraint/ImageContentValidator.java index b07ac3ed1..16eabc558 100644 --- a/openjpa-examples/image-gallery/src/test/java/org/apache/openjpa/example/gallery/constraint/ImageContentValidator.java +++ b/openjpa-examples/image-gallery/src/test/java/org/apache/openjpa/example/gallery/constraint/ImageContentValidator.java @@ -37,6 +37,7 @@ public class ImageContentValidator implements ConstraintValidator _attr; public AttributeView(Attribute attr) { diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/ConfigurationViewer.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/ConfigurationViewer.java index 52c7accbf..c4c18428c 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/ConfigurationViewer.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/ConfigurationViewer.java @@ -28,14 +28,14 @@ import javax.swing.JTextPane; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class ConfigurationViewer extends JTextPane { + private static final long serialVersionUID = 1L; private static final char SPACE = ' '; public ConfigurationViewer(String title, Map config) { super(); setBorder(BorderFactory.createTitledBorder(title)); - TreeSet sortedKeys = new TreeSet(config.keySet()); + TreeSet sortedKeys = new TreeSet<>(config.keySet()); int L = getMaxLength(sortedKeys); for (String key : sortedKeys) { setCaretPosition(getDocument().getLength()); diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityDataModel.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityDataModel.java index f712c00a8..927b85cbb 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityDataModel.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityDataModel.java @@ -39,8 +39,8 @@ import javax.swing.table.TableModel; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class EntityDataModel extends AbstractTableModel implements TableModel, Iterable { + private static final long serialVersionUID = 1L; /** * Constant designates to include non-relation fields. */ @@ -84,10 +84,10 @@ public class EntityDataModel extends AbstractTableModel implements TableModel this.data = data; EntityType entityType = meta.entity(cls); - columnNames = new ArrayList(); - columnClasses = new ArrayList>(); - attributes = new ArrayList>(); - methods = new ArrayList(); + columnNames = new ArrayList<>(); + columnClasses = new ArrayList<>(); + attributes = new ArrayList<>(); + methods = new ArrayList<>(); showsRowCount = (styleBits & ROW_COUNT) != 0; showsBasicAttr = (styleBits & BASIC_ATTR) != 0; diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityTable.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityTable.java index 48a520c2f..3434ce431 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityTable.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityTable.java @@ -23,9 +23,9 @@ import javax.persistence.PersistenceUnitUtil; import javax.persistence.metamodel.Attribute; import javax.swing.DefaultCellEditor; import javax.swing.JComboBox; -import javax.swing.JLabel; import javax.swing.JTable; import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; @@ -48,8 +48,8 @@ import org.apache.openjpa.enhance.StateManager; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class EntityTable extends JTable { + private static final long serialVersionUID = 1L; private InstanceCellRenderer instanceCellRenderer; private CollectionCellRenderer collectionCellRenderer; @@ -59,7 +59,7 @@ public class EntityTable extends JTable { collectionCellRenderer = new CollectionCellRenderer(); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - setModel(new EntityDataModel(cls, data, unit.getMetamodel(), styleBits)); + setModel(new EntityDataModel<>(cls, data, unit.getMetamodel(), styleBits)); getModel().addTableModelListener(this); initColumnSizes(); setFillsViewportHeight(true); @@ -74,6 +74,7 @@ public class EntityTable extends JTable { * Gets the special renderer for single- and multi-valued association. * Otherwise uses the super classes' renderer defined by the field type. */ + @Override public TableCellRenderer getCellRenderer(int row, int column) { Attribute attr = ((EntityDataModel)getModel()).getAttribute(column); TableCellRenderer renderer = null; @@ -87,12 +88,13 @@ public class EntityTable extends JTable { renderer = super.getCellRenderer(row, column); } if (renderer instanceof DefaultTableCellRenderer) { - ((DefaultTableCellRenderer)renderer).setHorizontalAlignment(JLabel.CENTER); + ((DefaultTableCellRenderer)renderer).setHorizontalAlignment(SwingConstants.CENTER); } return renderer; } + @Override public TableCellEditor getCellEditor(int row, int column) { Attribute attr = ((EntityDataModel)getModel()).getAttribute(column); if (attr == null) @@ -145,6 +147,8 @@ public class EntityTable extends JTable { * */ public class InstanceCellRenderer extends DefaultTableCellRenderer { + + private static final long serialVersionUID = 1L; private final PersistenceUnitUtil util; public InstanceCellRenderer(PersistenceUnitUtil util) { @@ -171,6 +175,7 @@ public class EntityTable extends JTable { return id == null ? "null" : id.toString(); } + @Override public void setValue(Object instance) { setForeground(Color.BLUE); setText(renderAsString(instance)); @@ -186,6 +191,8 @@ public class EntityTable extends JTable { * */ public class CollectionCellRenderer extends DefaultTableCellRenderer { + + private static final long serialVersionUID = 1L; public CollectionCellRenderer() { setPreferredSize(new Dimension(10,20)); } diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityTableView.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityTableView.java index 0f0dac207..3f499ab90 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityTableView.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityTableView.java @@ -28,6 +28,7 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.ListSelectionModel; +import javax.swing.ScrollPaneConstants; import javax.swing.border.Border; import javax.swing.border.TitledBorder; import javax.swing.event.ListSelectionEvent; @@ -42,18 +43,18 @@ import jpa.tools.swing.EntityTable.InstanceCellRenderer; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class EntityTableView extends JPanel implements ListSelectionListener { + private static final long serialVersionUID = 1L; private EntityTable _table; private JTextArea _details; public EntityTableView(Class cls, int styleBits, EntityManagerFactory unit) { - this(cls, (List)Collections.EMPTY_LIST, styleBits, unit); + this(cls, Collections.emptyList(), styleBits, unit); } public EntityTableView(Class cls, List data, int styleBits, EntityManagerFactory unit) { super(true); - _table = new EntityTable(cls, data, styleBits, unit); + _table = new EntityTable<>(cls, data, styleBits, unit); _table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); if ((styleBits & EntityDataModel.PLURAL_ATTR) != 0) { @@ -68,8 +69,8 @@ public class EntityTableView extends JPanel implements ListSelectionListener setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); add(new JScrollPane(_table, - JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, - JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS)); + ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, + ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS)); if (_details != null) add(_details); } diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityTypeView.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityTypeView.java index 54c8b4098..14ff81e7a 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityTypeView.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/EntityTypeView.java @@ -31,8 +31,8 @@ import javax.swing.JPanel; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class EntityTypeView extends JPanel { + private static final long serialVersionUID = 1L; final EntityType type; final int hgap = 4; final int vgap = 4; diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/ErrorDialog.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/ErrorDialog.java index ed8fad3dc..cf87c540c 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/ErrorDialog.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/ErrorDialog.java @@ -32,6 +32,8 @@ import javax.swing.JEditorPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextPane; +import javax.swing.ScrollPaneConstants; +import javax.swing.WindowConstants; /** * A dialog to display runtime error. @@ -39,8 +41,8 @@ import javax.swing.JTextPane; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class ErrorDialog extends JDialog { + private static final long serialVersionUID = 1L; private static List filters = Arrays.asList( "java.awt.", "javax.swing.", @@ -87,7 +89,7 @@ public class ErrorDialog extends JDialog { setModal(true); if (icon != null && icon instanceof ImageIcon) setIconImage(((ImageIcon)icon).getImage()); - setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); _error = t; _message = createErrorMessage(_error); _main = createContent(); @@ -106,6 +108,7 @@ public class ErrorDialog extends JDialog { JComponent createContent() { final JButton showDetails = new JButton("Show Details >>"); showDetails.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { if (_showingDetails) { _main.remove(_details); @@ -133,6 +136,7 @@ public class ErrorDialog extends JDialog { final JCheckBox filter = new JCheckBox("Filter stack traces"); filter.setSelected(_isFiltering); filter.addActionListener(new ActionListener(){ + @Override public void actionPerformed(ActionEvent e) { _isFiltering = filter.isSelected(); StringBuilder buffer = new StringBuilder(); @@ -178,8 +182,8 @@ public class ErrorDialog extends JDialog { _stacktrace = new JTextPane(); _stacktrace.setEditable(false); JScrollPane pane = new JScrollPane(_stacktrace, - JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, - JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, + ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); return pane; } diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/FileScanner.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/FileScanner.java index 911c813e3..1f84436f9 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/FileScanner.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/FileScanner.java @@ -36,7 +36,7 @@ public class FileScanner { * Scans the given */ public List scan(File dir) { - List bag = new ArrayList(); + List bag = new ArrayList<>(); scan(dir, bag); return bag; } diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/Finder.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/Finder.java index 4e7461097..a87ef0804 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/Finder.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/Finder.java @@ -79,6 +79,7 @@ public class Finder { private void scan(File dir, String cls) throws IOException { File[] classes = dir.listFiles(new FileFilter() { + @Override public boolean accept(File path) { return path.getName().endsWith(CLASS_SUFFIX); } @@ -91,6 +92,7 @@ public class Finder { } File[] jars = dir.listFiles(new FileFilter() { + @Override public boolean accept(File path) { return path.getName().endsWith(JAR_SUFFIX); } @@ -102,6 +104,7 @@ public class Finder { } File[] dirs = dir.listFiles(new FileFilter() { + @Override public boolean accept(File path) { return path.isDirectory(); } diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/GraphicOutputStream.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/GraphicOutputStream.java index e83cc30cf..39613e6ec 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/GraphicOutputStream.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/GraphicOutputStream.java @@ -32,7 +32,7 @@ public class GraphicOutputStream extends OutputStream { ScrollingTextPane _sink; private char[] buffer = new char[1024]; private int count; - private Map _styles = new HashMap(); + private Map _styles = new HashMap<>(); private static AttributeSet _defaultStyle = StyleContext.getDefaultStyleContext() .getStyle(StyleContext.DEFAULT_STYLE); diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/IndexedMap.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/IndexedMap.java index d2babd7ab..96867bcd9 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/IndexedMap.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/IndexedMap.java @@ -39,21 +39,24 @@ import java.util.Set; * @param */ public class IndexedMap implements Map { - private final List _keys = new ArrayList(); - private final List _values = new ArrayList(); - private final Set _nulls = new HashSet(); + private final List _keys = new ArrayList<>(); + private final List _values = new ArrayList<>(); + private final Set _nulls = new HashSet<>(); + @Override public void clear() { _keys.clear(); _values.clear(); } + @Override public boolean containsKey(Object key) { return _keys.contains(key) && !_nulls.contains(key); } + @Override public boolean containsValue(Object value) { return _values.contains(value); } @@ -61,26 +64,31 @@ public class IndexedMap implements Map { /** * Not supported. */ + @Override public Set> entrySet() { throw new UnsupportedOperationException(); } + @Override public V get(Object key) { int i = indexOf(key); return i == -1 ? null : _values.get(i); } + @Override public boolean isEmpty() { return (_keys.size() - _nulls.size()) == 0; } + @Override public Set keySet() { - Set result = new HashSet(_keys); + Set result = new HashSet<>(_keys); result.removeAll(_nulls); return result; } + @Override public V put(K key, V value) { int i = _keys.indexOf(key); if (i == -1) { @@ -93,12 +101,14 @@ public class IndexedMap implements Map { } } + @Override public void putAll(Map m) { for (K k : m.keySet()) { this.put(k, m.get(k)); } } + @Override @SuppressWarnings("unchecked") public V remove(Object key) { V v = get(key); @@ -106,12 +116,14 @@ public class IndexedMap implements Map { return v; } + @Override public int size() { return _keys.size() - _nulls.size(); } + @Override public Collection values() { - Collection result = new ArrayList(); + Collection result = new ArrayList<>(); for (int i = 0; i < _values.size(); i++) { if (!_nulls.contains(_keys.get(i))) result.add(_values.get(i)); diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/InstanceDataModel.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/InstanceDataModel.java index 143433ca3..62005bc11 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/InstanceDataModel.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/InstanceDataModel.java @@ -19,8 +19,8 @@ import javax.persistence.metamodel.Attribute; import javax.persistence.metamodel.EntityType; import javax.swing.table.AbstractTableModel; -@SuppressWarnings("serial") public class InstanceDataModel extends AbstractTableModel { + private static final long serialVersionUID = 1L; List> attributes; private T _instance; diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/InstanceView.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/InstanceView.java index 6aa907113..906e4dd87 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/InstanceView.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/InstanceView.java @@ -16,10 +16,11 @@ package jpa.tools.swing; import javax.persistence.metamodel.EntityType; import javax.swing.JTable; -@SuppressWarnings("serial") public class InstanceView extends JTable { + private static final long serialVersionUID = 1L; + public InstanceView(EntityType type, T instance) { - super(new InstanceDataModel(type, instance)); + super(new InstanceDataModel<>(type, instance)); setShowHorizontalLines(false); setShowVerticalLines(false); } diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/MetamodelHelper.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/MetamodelHelper.java index 35639054e..39b401665 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/MetamodelHelper.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/MetamodelHelper.java @@ -88,7 +88,7 @@ public class MetamodelHelper { public static List> getAttributes(EntityType type) { - List> list = new ArrayList>(type.getAttributes()); + List> list = new ArrayList<>(type.getAttributes()); Collections.sort(list, new AttributeComparator()); return list; } @@ -110,7 +110,7 @@ public class MetamodelHelper { public static Set> getIdAttributes(EntityType type) { Set> attrs = type.getSingularAttributes(); - Set> idAttrs = new HashSet>(); + Set> idAttrs = new HashSet<>(); for (SingularAttribute attr : attrs) { if (attr.isId()) { idAttrs.add(attr); @@ -192,7 +192,7 @@ public class MetamodelHelper { default: return 5; } } - private static Map, Method> members = new HashMap, Method>(); + private static Map, Method> members = new HashMap<>(); private static Object[] EMPTY_ARGS = null; private static Class[] EMPTY_CLASSES = null; /** diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/MetamodelView.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/MetamodelView.java index 2fa09d620..f29576b0b 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/MetamodelView.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/MetamodelView.java @@ -43,9 +43,8 @@ import javax.swing.JPanel; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class MetamodelView extends JPanel implements Maze { - + private static final long serialVersionUID = 1L; private static final int GRID = 8; int hgap = 40; int vgap = 40; @@ -63,7 +62,7 @@ public class MetamodelView extends JPanel implements Maze { layout.setVgap(80); // getInsets(new Insets(100,100,100,100)); Set> types = model.getEntities(); - List> sorted = new ArrayList>(types); + List> sorted = new ArrayList<>(types); Collections.sort(sorted, new MetamodelHelper.EntityComparator()); for (EntityType type : sorted) { EntityTypeView view = new EntityTypeView(type); diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/PathFinder.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/PathFinder.java index a70543586..e81c21004 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/PathFinder.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/PathFinder.java @@ -58,8 +58,8 @@ public class PathFinder { Node source = new Node(null, x1, y1); Node target = new Node(null, x2, y2); int maxCost = distance(source, target)*2; - LinkedList openList = new LinkedList(); - List closedList = new ArrayList(); + LinkedList openList = new LinkedList<>(); + List closedList = new ArrayList<>(); openList.add(source); do { Node current = openList.remove(0); @@ -119,7 +119,7 @@ public class PathFinder { } List traceBackPath(Node target) { - LinkedList path = new LinkedList(); + LinkedList path = new LinkedList<>(); path.add(new Point(target.x, target.y)); Node next = target.parent; while (next != null) { @@ -132,7 +132,7 @@ public class PathFinder { List straighten(List path) { if (path.size() < 3) return path; - List mids = new ArrayList(); + List mids = new ArrayList<>(); Point prev = path.get(0); Point mid = path.get(1); for (int i = 2; i < path.size(); i++) { @@ -158,6 +158,7 @@ public class PathFinder { this.y = y; } + @Override public boolean equals(Object o) { if (this == o) return true; if (o instanceof Node) { @@ -173,6 +174,7 @@ public class PathFinder { return f > o.f ? 1 : -1; } + @Override public String toString() { return "(" + x + "," + y + ":" + g + ")"; } diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/PowerPointViewer.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/PowerPointViewer.java index 49415dff2..efa6fdcaa 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/PowerPointViewer.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/PowerPointViewer.java @@ -40,9 +40,9 @@ import openbook.client.Images; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class PowerPointViewer extends JPanel { - private List> _slides = new ArrayList>(); + private static final long serialVersionUID = 1L; + private List> _slides = new ArrayList<>(); private int _total; // Total number of slides in the deck. private String _dir; private List _slideURLs; @@ -89,6 +89,7 @@ public class PowerPointViewer extends JPanel { _prev = new RoundButton(Images.BACK); buttons.add(_prev); _prev.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { prevPage(); } @@ -101,6 +102,7 @@ public class PowerPointViewer extends JPanel { buttons.add(gotoLabel); buttons.add(_goto); _goto.addChangeListener(new ChangeListener() { + @Override public void stateChanged(ChangeEvent e) { Integer page = (Integer)_goto.getValue(); showPage(page-1); @@ -112,6 +114,7 @@ public class PowerPointViewer extends JPanel { buttons.add(_navButtons[i]); _navButtons[i].putClientProperty(SLIDE_INDEX, i+1); _navButtons[i].addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { JButton button = (JButton)e.getSource(); int index = (Integer)button.getClientProperty(SLIDE_INDEX); @@ -123,6 +126,7 @@ public class PowerPointViewer extends JPanel { buttons.add(Box.createHorizontalGlue()); buttons.add(_next); _next.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { nextPage(); } @@ -198,12 +202,12 @@ public class PowerPointViewer extends JPanel { ImageIcon loadSlide(int index) { URL imgURL = _slideURLs.get(index); ImageIcon icon = new ImageIcon(imgURL); - _slides.add(index, new WeakReference(icon)); + _slides.add(index, new WeakReference<>(icon)); return icon; } List validateSlides(String dir, List slides) { - List valid = new ArrayList(); + List valid = new ArrayList<>(); for (String slide : slides) { URL url = findResource(dir + slide); if (url != null) { diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/PreparedQueryViewer.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/PreparedQueryViewer.java index 9b62c28f3..fdedec9b9 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/PreparedQueryViewer.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/PreparedQueryViewer.java @@ -15,7 +15,6 @@ package jpa.tools.swing; import javax.swing.JTable; - import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory; import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; @@ -25,8 +24,8 @@ import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class PreparedQueryViewer extends JTable { + private static final long serialVersionUID = 1L; public PreparedQueryViewer(OpenJPAEntityManagerFactory emf) { super(new QueryStatisticsModel(((OpenJPAEntityManagerFactorySPI)emf).getConfiguration() diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/QueryStatisticsModel.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/QueryStatisticsModel.java index 65e22997a..f4b04f164 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/QueryStatisticsModel.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/QueryStatisticsModel.java @@ -21,10 +21,10 @@ import javax.swing.table.AbstractTableModel; import org.apache.openjpa.kernel.QueryStatistics; -@SuppressWarnings("serial") class QueryStatisticsModel extends AbstractTableModel { + private static final long serialVersionUID = 1L; QueryStatistics _stats; - private List _keys = new ArrayList(); + private List _keys = new ArrayList<>(); QueryStatisticsModel(QueryStatistics stats) { _stats = stats; @@ -65,7 +65,7 @@ class QueryStatisticsModel extends AbstractTableModel { void sortKeys(QueryStatistics stats) { if (_stats.keys().size() != _keys.size()) { - _keys = new ArrayList(_stats.keys()); + _keys = new ArrayList<>(_stats.keys()); if (_keys.size() > 1) { Collections.sort(_keys); } diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/RoundButton.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/RoundButton.java index 004ef25f5..4d4e4d28c 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/RoundButton.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/RoundButton.java @@ -34,8 +34,8 @@ import javax.swing.JButton; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class RoundButton extends JButton { + private static final long serialVersionUID = 1L; protected Shape shape, base; public RoundButton() { diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/ScrollingTextPane.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/ScrollingTextPane.java index d4ab5ef57..2ab82efef 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/ScrollingTextPane.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/ScrollingTextPane.java @@ -32,8 +32,8 @@ import javax.swing.text.Document; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class ScrollingTextPane extends JTextPane { + private static final long serialVersionUID = 1L; public void appendText(String text) { if (text == null) diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java index 6a7c8f972..48b156a11 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java @@ -28,6 +28,7 @@ import javax.swing.JEditorPane; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.ScrollPaneConstants; /** @@ -39,12 +40,12 @@ import javax.swing.JScrollPane; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class SourceCodeViewer extends JPanel { + private static final long serialVersionUID = 1L; private final JEditorPane _editor; private final JComboBox _bookmarks; - private IndexedMap _anchors = new IndexedMap(); - private LinkedList _visited = new LinkedList(); + private IndexedMap _anchors = new IndexedMap<>(); + private LinkedList _visited = new LinkedList<>(); /** * Create a Source Code Browser. @@ -62,6 +63,7 @@ public class SourceCodeViewer extends JPanel { _bookmarks.setEditable(false); _bookmarks.addActionListener(new ActionListener(){ + @Override public void actionPerformed(ActionEvent e) { showAnchor((String)_bookmarks.getSelectedItem()); } @@ -75,8 +77,8 @@ public class SourceCodeViewer extends JPanel { add(new JScrollPane(_editor, - JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, - JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS), + ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, + ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS), BorderLayout.CENTER); add(topPanel, BorderLayout.NORTH); } diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/StatusBar.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/StatusBar.java index fcdc406e4..3be13b9ad 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/StatusBar.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/StatusBar.java @@ -28,8 +28,8 @@ import javax.swing.JProgressBar; import javax.swing.SwingWorker; import javax.swing.Timer; -@SuppressWarnings("serial") public class StatusBar extends JPanel implements PropertyChangeListener { + private static final long serialVersionUID = 1L; private JProgressBar progressBar; private JProgressBar memoryBar; private JLabel messageText; @@ -76,6 +76,7 @@ public class StatusBar extends JPanel implements PropertyChangeListener { /** * Invoked when task's progress property changes. */ + @Override public void propertyChange(PropertyChangeEvent evt) { if ("progress".equals(evt.getPropertyName())) { progressBar.setValue((Integer)evt.getNewValue()); @@ -138,7 +139,7 @@ public class StatusBar extends JPanel implements PropertyChangeListener { long usedMemory = totalMemory-jvm.freeMemory(); int usedPct = (int)((100*usedMemory)/totalMemory); bar.setForeground(getColor(usedPct)); - bar.setValue((int)usedPct); + bar.setValue(usedPct); bar.setString(usedPct + "% (" + mb(usedMemory) + "/" + mb(totalMemory) + "MB) "); } diff --git a/openjpa-examples/openbooks/src/main/java/openbook/client/BuyBookPage.java b/openjpa-examples/openbooks/src/main/java/openbook/client/BuyBookPage.java index 93985ef20..e868840d8 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/client/BuyBookPage.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/client/BuyBookPage.java @@ -37,6 +37,8 @@ import javax.swing.SwingWorker; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; +import org.apache.openjpa.lib.jdbc.SQLFormatter; + import jpa.tools.swing.EntityDataModel; import jpa.tools.swing.EntityTable; import jpa.tools.swing.EntityTableView; @@ -50,8 +52,6 @@ import openbook.domain.ShoppingCart; import openbook.server.OpenBookService; import openbook.server.QueryDecorator; -import org.apache.openjpa.lib.jdbc.SQLFormatter; - /** * A visual page coordinates the following functions of {@link OpenBookService} : *
  • query for books @@ -71,8 +71,8 @@ import org.apache.openjpa.lib.jdbc.SQLFormatter; * * @author Pinaki Poddar */ -@SuppressWarnings("serial") public final class BuyBookPage extends JPanel { + private static final long serialVersionUID = 1L; private final OpenBookService _service; private final Customer _customer; private final SearchPanel _searchPanel; @@ -124,6 +124,8 @@ public final class BuyBookPage extends JPanel { * */ class SearchPanel extends JPanel implements ActionListener { + + private static final long serialVersionUID = 1L; private final JTextField _title = new JTextField("", 20); private final JTextField _author = new JTextField("", 20); private final JTextField _maxPrice = new JTextField("", 6); @@ -208,6 +210,7 @@ public final class BuyBookPage extends JPanel { * * The query is executed in a background, non-AWT thread. */ + @Override public void actionPerformed(ActionEvent e) { new SwingWorker, Void>() { private String queryString; @@ -260,6 +263,8 @@ public final class BuyBookPage extends JPanel { * */ class SelectBookPanel extends JPanel { + + private static final long serialVersionUID = 1L; private final JLabel _bookCount; private final EntityTableView _selectedBooks; @@ -267,7 +272,7 @@ public final class BuyBookPage extends JPanel { setLayout(new BorderLayout()); setBorder(BorderFactory.createTitledBorder(title)); - _selectedBooks = new EntityTableView(Book.class, + _selectedBooks = new EntityTableView<>(Book.class, EntityDataModel.BASIC_ATTR | EntityDataModel.ROW_COUNT, _service.getUnit()); _bookCount = new JLabel(); @@ -290,6 +295,8 @@ public final class BuyBookPage extends JPanel { * */ class BuyPanel extends JPanel implements ListSelectionListener { + + private static final long serialVersionUID = 1L; JLabel _bookTitle; JLabel _bookAuthors; JLabel _bookPrice; @@ -385,6 +392,8 @@ public final class BuyBookPage extends JPanel { * */ class ShoppingCartPanel extends JPanel implements ActionListener { + + private static final long serialVersionUID = 1L; private static final int MAX_ITEMS = 10; private final ShoppingCart _cart; private final JButton _placeOrder; diff --git a/openjpa-examples/openbooks/src/main/java/openbook/client/DeliveryPage.java b/openjpa-examples/openbooks/src/main/java/openbook/client/DeliveryPage.java index 50a069f51..304ee47be 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/client/DeliveryPage.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/client/DeliveryPage.java @@ -40,8 +40,8 @@ import openbook.server.OpenBookService; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class DeliveryPage extends JPanel { + private static final long serialVersionUID = 1L; private final JButton _deliver; private EntityTableView _orders; private final OpenBookService _service; @@ -55,7 +55,7 @@ public class DeliveryPage extends JPanel { _service = service; - _orders = new EntityTableView(PurchaseOrder.class, getOrders(PurchaseOrder.Status.PENDING), + _orders = new EntityTableView<>(PurchaseOrder.class, getOrders(PurchaseOrder.Status.PENDING), EntityDataModel.ALL_ATTR, service.getUnit()); _title = new JLabel(_orders.getDataModel().getRowCount() + " " + PurchaseOrder.Status.PENDING @@ -116,7 +116,7 @@ public class DeliveryPage extends JPanel { new SwingWorker, Void>() { @Override protected List doInBackground() throws Exception { - List updated = new ArrayList(); + List updated = new ArrayList<>(); EntityDataModel orders = _orders.getDataModel(); int n = orders.getRowCount(); for (int i = 0; i < n; i++) { diff --git a/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java b/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java index 0a5badee9..3a6486c1f 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java @@ -52,6 +52,10 @@ import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; +import org.apache.openjpa.conf.OpenJPAVersion; +import org.apache.openjpa.lib.jdbc.JDBCListener; +import org.apache.openjpa.persistence.OpenJPAPersistence; + import jpa.tools.swing.AttributeLegendView; import jpa.tools.swing.ConfigurationViewer; import jpa.tools.swing.ErrorDialog; @@ -67,18 +71,14 @@ import openbook.server.OpenBookService; import openbook.server.ServiceFactory; import openbook.util.PropertyHelper; -import org.apache.openjpa.conf.OpenJPAVersion; -import org.apache.openjpa.lib.jdbc.JDBCListener; -import org.apache.openjpa.persistence.OpenJPAPersistence; - /** * A graphical user interface based client of OpenBooks for demonstration. * * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class Demo extends JFrame { + private static final long serialVersionUID = 1L; private static Dimension TAB_VIEW = new Dimension(800,600); private static Dimension OUT_VIEW = new Dimension(800,200); private static Dimension NAV_VIEW = new Dimension(400,800); @@ -124,6 +124,7 @@ public class Demo extends JFrame { SwingHelper.setLookAndFeel(14); adjustWidgetSize(); SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { Demo demo = Demo.getInstance(); demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -207,7 +208,7 @@ public class Demo extends JFrame { SwingWorker getService = new SwingWorker () { @Override protected OpenBookService doInBackground() throws Exception { - Map runtimeConfig = new HashMap(); + Map runtimeConfig = new HashMap<>(); runtimeConfig.put("openjpa.jdbc.JDBCListeners", new JDBCListener[]{_sqlListener}); OpenBookService service = ServiceFactory.getService(unitName, runtimeConfig); service.initialize(null); @@ -302,6 +303,9 @@ public class Demo extends JFrame { * */ public abstract class OpenBookAction extends AbstractAction { + + private static final long serialVersionUID = 1L; + public OpenBookAction(String name, Icon icon, String tooltip) { putValue(Action.NAME, name); putValue(Action.SHORT_DESCRIPTION, tooltip); @@ -310,11 +314,14 @@ public class Demo extends JFrame { } public class BuyBookAction extends OpenBookAction { + + private static final long serialVersionUID = 1L; BuyBookPage _buyBookPage; public BuyBookAction(String name, Icon icon, String tooltip) { super(name, icon, tooltip); } + @Override public void actionPerformed(ActionEvent e) { if (_buyBookPage == null) { _buyBookPage = new BuyBookPage(getService(), getCustomer()); @@ -325,10 +332,13 @@ public class Demo extends JFrame { } public class DeliveryAction extends OpenBookAction { + + private static final long serialVersionUID = 1L; DeliveryPage _deliveryPage; public DeliveryAction(String name, Icon icon, String tooltip) { super(name, icon, tooltip); } + @Override public void actionPerformed(ActionEvent e) { if (_deliveryPage == null) { _deliveryPage = new DeliveryPage(getService()); @@ -340,10 +350,13 @@ public class Demo extends JFrame { } public class SupplyAction extends OpenBookAction { + + private static final long serialVersionUID = 1L; SupplyPage _supplyPage; public SupplyAction(String name, Icon icon, String tooltip) { super(name, icon, tooltip); } + @Override public void actionPerformed(ActionEvent e) { if (_supplyPage == null) { _supplyPage = new SupplyPage(getService()); @@ -355,10 +368,13 @@ public class Demo extends JFrame { } public class ViewConfigAction extends OpenBookAction { + + private static final long serialVersionUID = 1L; ConfigurationViewer _configView; public ViewConfigAction(String name, Icon icon, String tooltip) { super(name, icon, tooltip); } + @Override public void actionPerformed(ActionEvent e) { if (_configView == null) { _configView = new ConfigurationViewer("Unit Configuration", getService().getUnit().getProperties()); @@ -371,11 +387,14 @@ public class Demo extends JFrame { } public class ViewDomainAction extends OpenBookAction { + + private static final long serialVersionUID = 1L; MetamodelView _domainView; AttributeLegendView _legends; public ViewDomainAction(String name, Icon icon, String tooltip) { super(name, icon, tooltip); } + @Override public void actionPerformed(ActionEvent e) { if (_domainView == null) { _domainView = new MetamodelView(getService().getUnit().getMetamodel()); @@ -388,9 +407,12 @@ public class Demo extends JFrame { } public class ViewDataAction extends OpenBookAction { + + private static final long serialVersionUID = 1L; public ViewDataAction(String name, Icon icon, String tooltip) { super(name, icon, tooltip); } + @Override public void actionPerformed(ActionEvent e) { showTab(_tabbedPane, "Buy Books", null); } @@ -398,10 +420,13 @@ public class Demo extends JFrame { } public class ViewQueryCacheAction extends OpenBookAction { + + private static final long serialVersionUID = 1L; PreparedQueryViewer _queryView; public ViewQueryCacheAction(String name, Icon icon, String tooltip) { super(name, icon, tooltip); } + @Override public void actionPerformed(ActionEvent e) { if (_queryView == null) { _queryView = new PreparedQueryViewer(OpenJPAPersistence.cast(getService().getUnit())); @@ -413,10 +438,14 @@ public class Demo extends JFrame { } public class ViewSourceAction extends OpenBookAction { + + private static final long serialVersionUID = 1L; + public ViewSourceAction(String name, Icon icon, String tooltip) { super(name, icon, tooltip); } + @Override public void actionPerformed(ActionEvent e) { getSourceCodeBrowser(); } @@ -427,6 +456,8 @@ public class Demo extends JFrame { * */ public class ShowCodeAction extends OpenBookAction { + + private static final long serialVersionUID = 1L; private String _key; private String _page; @@ -439,6 +470,7 @@ public class Demo extends JFrame { _page = page; } + @Override public void actionPerformed(ActionEvent e) { getSourceCodeBrowser().showPage(_key, _page); } @@ -451,6 +483,8 @@ public class Demo extends JFrame { * */ public class WelcomeAction extends OpenBookAction { + + private static final long serialVersionUID = 1L; PowerPointViewer _powerpoint; JLabel _logoLabel = new JLabel(Images.LOGO_OPENBOOKS); boolean _showPresentation = true; @@ -459,6 +493,7 @@ public class Demo extends JFrame { super(name, icon, tooltip); } + @Override public void actionPerformed(ActionEvent e) { if (_powerpoint == null && _showPresentation) { String dir = getConfiguration("openbook.slides.dir", "slides/"); @@ -493,12 +528,15 @@ public class Demo extends JFrame { } public class AboutAction extends OpenBookAction { + + private static final long serialVersionUID = 1L; AboutDialog _dialog; public AboutAction(String name, Icon icon, String tooltip) { super(name, icon, tooltip); } + @Override public void actionPerformed(ActionEvent e) { if (_dialog == null) { _dialog = new AboutDialog(Images.LOGO_OPENBOOKS); @@ -605,6 +643,7 @@ public class Demo extends JFrame { tree.setShowsRootHandles(true); tree.addTreeSelectionListener(new TreeSelectionListener() { + @Override public void valueChanged(TreeSelectionEvent e) { Object treeNode = _navigator.getLastSelectedPathComponent(); if (treeNode instanceof ActionTreeNode) { @@ -628,11 +667,14 @@ public class Demo extends JFrame { * */ public static class ActionTreeNode extends DefaultMutableTreeNode { + + private static final long serialVersionUID = 1L; private final Action _action; public ActionTreeNode(Action action) { _action = action; } + @Override public String toString() { return _action.getValue(Action.SHORT_DESCRIPTION).toString(); } @@ -640,6 +682,9 @@ public class Demo extends JFrame { } public class TypedTreeCellRenderer extends DefaultTreeCellRenderer { + + private static final long serialVersionUID = 1L; + @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { @@ -648,6 +693,9 @@ public class Demo extends JFrame { } public static class AboutDialog extends JDialog { + + private static final long serialVersionUID = 1L; + public AboutDialog(Icon logo) { setModal(true); setLayout(new BorderLayout()); diff --git a/openjpa-examples/openbooks/src/main/java/openbook/client/ErrorHandler.java b/openjpa-examples/openbooks/src/main/java/openbook/client/ErrorHandler.java index 542ed3770..8aebb6776 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/client/ErrorHandler.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/client/ErrorHandler.java @@ -38,6 +38,7 @@ public class ErrorHandler implements Thread.UncaughtExceptionHandler{ uncaughtException(Thread.currentThread(), e); } + @Override public void uncaughtException(Thread t, Throwable e) { if (SwingUtilities.isEventDispatchThread()) { new ErrorDialog(null, Images.ERROR, e).setVisible(true); diff --git a/openjpa-examples/openbooks/src/main/java/openbook/client/Images.java b/openjpa-examples/openbooks/src/main/java/openbook/client/Images.java index 0c1c1c508..69d43d98d 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/client/Images.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/client/Images.java @@ -30,7 +30,7 @@ import javax.swing.ImageIcon; */ public class Images { - private static Map images = new HashMap(); + private static Map images = new HashMap<>(); public static Icon NEXT = getIcon("images/arrow_right.jpg", 24, -1); public static Icon BACK = getIcon("images/arrow_left.jpg", 24, -1); diff --git a/openjpa-examples/openbooks/src/main/java/openbook/client/SQLLogger.java b/openjpa-examples/openbooks/src/main/java/openbook/client/SQLLogger.java index 834da3718..c801141c9 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/client/SQLLogger.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/client/SQLLogger.java @@ -22,13 +22,11 @@ import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; -import jpa.tools.swing.GraphicOutputStream; - - - import org.apache.openjpa.lib.jdbc.AbstractJDBCListener; import org.apache.openjpa.lib.jdbc.JDBCEvent; +import jpa.tools.swing.GraphicOutputStream; + /** * Logs SQL statement to a graphic console. * @@ -59,6 +57,7 @@ public class SQLLogger extends AbstractJDBCListener { if (out == null) return; SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { out.println(event.getSQL()); } diff --git a/openjpa-examples/openbooks/src/main/java/openbook/client/SupplyPage.java b/openjpa-examples/openbooks/src/main/java/openbook/client/SupplyPage.java index 9eed4fa25..4fe1a7f80 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/client/SupplyPage.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/client/SupplyPage.java @@ -39,8 +39,9 @@ import openbook.server.OpenBookService; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class SupplyPage extends JPanel { + private static final long serialVersionUID = 1L; + private final OpenBookService _service; private final EntityTableView _lowInventories; @@ -62,7 +63,7 @@ public class SupplyPage extends JPanel { _supply = new JButton("Supply " + REORDER_QUANTITY + " to each item"); List orders = getInventory(REORDER_LIMIT); - _lowInventories = new EntityTableView(Inventory.class, + _lowInventories = new EntityTableView<>(Inventory.class, orders, EntityDataModel.BASIC_ATTR | EntityDataModel.ASSOCIATION_ATTR, service.getUnit()); @@ -76,6 +77,7 @@ public class SupplyPage extends JPanel { _view.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { _lowInventories.getDataModel().updateData(getInventory(REORDER_LIMIT)); } @@ -91,7 +93,7 @@ public class SupplyPage extends JPanel { @Override protected List doInBackground() throws Exception { EntityDataModel invs = _lowInventories.getDataModel(); - List updated = new ArrayList(); + List updated = new ArrayList<>(); for (Inventory inv : invs) { Book supplied = _service.supply(inv.getBook(), REORDER_QUANTITY); updated.add(supplied.getInventory()); @@ -99,6 +101,7 @@ public class SupplyPage extends JPanel { return updated; } + @Override public void done() { try { _lowInventories.getDataModel().updateData(get(1, TimeUnit.SECONDS)); diff --git a/openjpa-examples/openbooks/src/main/java/openbook/domain/Author.java b/openjpa-examples/openbooks/src/main/java/openbook/domain/Author.java index bcd9b7b13..b685c07dd 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/domain/Author.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/domain/Author.java @@ -67,7 +67,7 @@ public class Author { public void addBook(Book book) { if (books == null) - books = new HashSet(); + books = new HashSet<>(); books.add(book); } diff --git a/openjpa-examples/openbooks/src/main/java/openbook/domain/Book.java b/openjpa-examples/openbooks/src/main/java/openbook/domain/Book.java index 3c8a1833a..78c653140 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/domain/Book.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/domain/Book.java @@ -44,9 +44,10 @@ import javax.persistence.Version; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") @Entity public class Book implements Serializable { + private static final long serialVersionUID = 1L; + @Id private String ISBN; @@ -108,7 +109,7 @@ public class Book implements Serializable { public void addAuthor(Author...authors) { if (this.authors == null) - this.authors = new ArrayList(); + this.authors = new ArrayList<>(); for (Author a : authors) { if (!this.authors.contains(a)) this.authors.add(a); diff --git a/openjpa-examples/openbooks/src/main/java/openbook/domain/Customer.java b/openjpa-examples/openbooks/src/main/java/openbook/domain/Customer.java index 94c0f43fe..2e24083dd 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/domain/Customer.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/domain/Customer.java @@ -32,9 +32,9 @@ import javax.persistence.Version; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") @Entity public class Customer implements Serializable { + private static final long serialVersionUID = 1L; @Id @GeneratedValue private long id; @@ -71,6 +71,7 @@ public class Customer implements Serializable { return new ShoppingCart(this); } + @Override public String toString() { return name; } diff --git a/openjpa-examples/openbooks/src/main/java/openbook/domain/Inventory.java b/openjpa-examples/openbooks/src/main/java/openbook/domain/Inventory.java index a321bcb82..f60149693 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/domain/Inventory.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/domain/Inventory.java @@ -28,9 +28,10 @@ import javax.persistence.Version; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") @Entity public class Inventory implements Serializable { + private static final long serialVersionUID = 1L; + @Id @OneToOne(fetch=FetchType.EAGER, optional=false) private Book book; diff --git a/openjpa-examples/openbooks/src/main/java/openbook/domain/LineItem.java b/openjpa-examples/openbooks/src/main/java/openbook/domain/LineItem.java index a72b8d601..7dd791c80 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/domain/LineItem.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/domain/LineItem.java @@ -32,10 +32,11 @@ import javax.persistence.OrderColumn; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") @Entity @IdClass(LineItem.LineItemId.class) public class LineItem implements Serializable { + private static final long serialVersionUID = 1L; + /** * * An example of a compound derived identity. @@ -122,6 +123,8 @@ public class LineItem implements Serializable { * */ public static class LineItemId implements Serializable { + + private static final long serialVersionUID = 1L; long order; int index; diff --git a/openjpa-examples/openbooks/src/main/java/openbook/domain/PurchaseOrder.java b/openjpa-examples/openbooks/src/main/java/openbook/domain/PurchaseOrder.java index 477ca8020..3c59f784c 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/domain/PurchaseOrder.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/domain/PurchaseOrder.java @@ -54,9 +54,10 @@ import javax.persistence.TemporalType; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") @Entity public class PurchaseOrder implements Serializable { + private static final long serialVersionUID = 1L; + /** * Enumerates the status of a Purchase Order. * @@ -195,7 +196,7 @@ public class PurchaseOrder implements Serializable { throw new IllegalArgumentException("Can not add Line Item to Purchase Order for negative (=" + quantity + ") number of Book " + book); if (items == null) - items = new ArrayList(); + items = new ArrayList<>(); items.add(new LineItem(this, items.size()+1, book, quantity)); total += (book.getPrice() * quantity); } diff --git a/openjpa-examples/openbooks/src/main/java/openbook/domain/ShoppingCart.java b/openjpa-examples/openbooks/src/main/java/openbook/domain/ShoppingCart.java index 4cd303fff..396c4b913 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/domain/ShoppingCart.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/domain/ShoppingCart.java @@ -27,8 +27,9 @@ import java.util.Map; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") public class ShoppingCart implements Serializable { + private static final long serialVersionUID = 1L; + /** * The owner of this cart. */ @@ -47,7 +48,7 @@ public class ShoppingCart implements Serializable { */ ShoppingCart(Customer c) { customer = c; - items = new HashMap(); + items = new HashMap<>(); } /** diff --git a/openjpa-examples/openbooks/src/main/java/openbook/server/OpenBookService.java b/openjpa-examples/openbooks/src/main/java/openbook/server/OpenBookService.java index 936bf9ca6..06d9a8f5a 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/server/OpenBookService.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/server/OpenBookService.java @@ -33,7 +33,7 @@ import openbook.domain.ShoppingCart; * */ public interface OpenBookService { - public static final String DEFAULT_UNIT_NAME = "OpenBooks"; + String DEFAULT_UNIT_NAME = "OpenBooks"; /** * Starts a session for the given named Customer. @@ -43,7 +43,7 @@ public interface OpenBookService { * * @return a Customer */ - public Customer login(String name); + Customer login(String name); /** * Selects a list of Books matching the given conditions. @@ -56,7 +56,7 @@ public interface OpenBookService { * @param author name of author * @param decorators to modify the executable query such as its range. */ - public List select(String title, + List select(String title, Double min, Double max, String author, QueryDecorator...decorators); @@ -71,7 +71,7 @@ public interface OpenBookService { * @param author name of author * @param decorators to modify the executable query such as its range. */ - public String getQuery(String title, + String getQuery(String title, Double min, Double max, String author); @@ -92,7 +92,7 @@ public interface OpenBookService { * @param cart a non-empty cart. * @return a PurchaseOrder for the content of the cart. */ - public PurchaseOrder placeOrder(ShoppingCart cart); + PurchaseOrder placeOrder(ShoppingCart cart); /** * Delivers the given order. Delivery changes the status of the order, decrements @@ -102,7 +102,7 @@ public interface OpenBookService { * @return the PurchaseOrder after delivery. * */ - public PurchaseOrder deliver(PurchaseOrder order); + PurchaseOrder deliver(PurchaseOrder order); /** * Add inventory of the given Book by the given quantity. @@ -112,7 +112,7 @@ public interface OpenBookService { * * @return the Book after incrementing its inventory. */ - public Book supply(Book b, int quantity); + Book supply(Book b, int quantity); /** * Gets the list of orders of given status. @@ -121,7 +121,7 @@ public interface OpenBookService { * * @return list of orders sorted by their placement dates. */ - public List getOrders(PurchaseOrder.Status status, Customer customer); + List getOrders(PurchaseOrder.Status status, Customer customer); /** @@ -131,7 +131,7 @@ public interface OpenBookService { * * @return list of Books with inventory lower than the given limit. */ - public List getReorderableBooks(int limit); + List getReorderableBooks(int limit); /** * Count the number of instances of the given persistent type. @@ -139,7 +139,7 @@ public interface OpenBookService { * @param cls a persistent type. * @return number of persistent entity of the given type. */ - public long count(Class cls); + long count(Class cls); /** * Populates the underlying data repository with sample values, only if @@ -150,31 +150,31 @@ public interface OpenBookService { * * @return true if the repository is initialized by this invocation. */ - public boolean initialize(Map loadParameters); + boolean initialize(Map loadParameters); /** * Cleans everything. Be careful. */ - public void clean(); + void clean(); /** * Gets the underlying persistence unit. * */ - public EntityManagerFactory getUnit(); + EntityManagerFactory getUnit(); /** * Gets the name of the underlying persistence unit. * */ - public String getUnitName(); + String getUnitName(); /** * Affirms if the transaction on this persistence unit is managed by a container. * */ - public boolean isManaged(); + boolean isManaged(); } diff --git a/openjpa-examples/openbooks/src/main/java/openbook/server/OpenBookServiceImpl.java b/openjpa-examples/openbooks/src/main/java/openbook/server/OpenBookServiceImpl.java index c3039c4ac..75c42656b 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/server/OpenBookServiceImpl.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/server/OpenBookServiceImpl.java @@ -31,6 +31,8 @@ import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import javax.persistence.metamodel.EntityType; +import org.apache.openjpa.persistence.criteria.OpenJPACriteriaBuilder; + import openbook.domain.Author; import openbook.domain.Author_; import openbook.domain.Book; @@ -47,8 +49,6 @@ import openbook.domain.ShoppingCart; import openbook.util.PropertyHelper; import openbook.util.Randomizer; -import org.apache.openjpa.persistence.criteria.OpenJPACriteriaBuilder; - /** * A demonstrative example of a transaction service with persistent entity using Java Persistence API. *
    @@ -67,9 +67,8 @@ import org.apache.openjpa.persistence.criteria.OpenJPACriteriaBuilder; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") class OpenBookServiceImpl extends PersistenceService implements OpenBookService { - + private static final long serialVersionUID = 1L; public static final int CUSTOMER_COUNT = 10; public static final int BOOK_COUNT = 100; public static final int AUTHOR_COUNT = 40; @@ -78,8 +77,8 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService /** * Range of number of queries executed for a {@linkplain #shop() shopping} trip. */ - public static final Range PRICE_RANGE = new Range(4.99, 120.99); - public static final Range STOCK_RANGE = new Range(5, 50); + public static final Range PRICE_RANGE = new Range<>(4.99, 120.99); + public static final Range STOCK_RANGE = new Range<>(5, 50); public static final int REORDER_LEVEL = 10; OpenBookServiceImpl(String unit, EntityManagerFactory emf, boolean managed, @@ -93,6 +92,7 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService * * @return true if new inventory is created. false otherwise. */ + @Override public boolean initialize(Map config) { if (isInitialized()) { return false; @@ -119,7 +119,7 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService em.persist(customer); } - List allAuthors = new ArrayList(); + List allAuthors = new ArrayList<>(); System.err.println("Creating " + nAuthor + " new Authors"); for (int i = 1; i <= nAuthor; i++) { Author author = new Author(); @@ -164,6 +164,7 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService * * @return a Customer */ + @Override public Customer login(String name) { EntityManager em = begin(); @@ -191,6 +192,7 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService /** * Find books that match title and price range. */ + @Override public List select(String title, Double minPrice, Double maxPrice, String author, QueryDecorator...decorators) { CriteriaQuery q = buildQuery(title, minPrice, maxPrice, author); @@ -208,6 +210,7 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService * But OpenJPA produces a readable form that is quite similar to * equivalent JPQL. */ + @Override public String getQuery(String title, Double minPrice, Double maxPrice, String author) { CriteriaQuery q = buildQuery(title, minPrice, maxPrice, author); return q.toString(); @@ -238,7 +241,7 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService q.select(book); // Builds the predicates conditionally for the filled-in input fields - List predicates = new ArrayList(); + List predicates = new ArrayList<>(); if (!isEmpty(title)) { Predicate matchTitle = cb.like(book.get(Book_.title), title); predicates.add(matchTitle); @@ -280,6 +283,7 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService * The transactions may fail because of either insufficient inventory or * concurrent modification of the same inventory by {@link #supply(Book, int) the supplier}. */ + @Override public PurchaseOrder deliver(PurchaseOrder o) { if (o.isDelivered()) return o; @@ -293,13 +297,14 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService return o; } + @Override public List getOrders(PurchaseOrder.Status status, Customer customer) { EntityManager em = begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery q = cb.createQuery(PurchaseOrder.class); Root order = q.from(PurchaseOrder.class); q.select(order); - List predicates = new ArrayList(); + List predicates = new ArrayList<>(); if (status != null) { predicates.add(cb.equal(order.get(PurchaseOrder_.status), status)); } @@ -326,6 +331,7 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService * * @param cart a non-null Shopping cart. */ + @Override public PurchaseOrder placeOrder(ShoppingCart cart) { EntityManager em = begin(); PurchaseOrder order = new PurchaseOrder(cart); @@ -342,6 +348,7 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService * transaction. Some of the transactions may fail due to concurrent modification on * the {@linkplain Inventory} by the {@linkplain #deliver() delivery} process. */ + @Override public Book supply(Book b, int quantity) { EntityManager em = begin(); b = em.merge(b); @@ -350,6 +357,7 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService return b; } + @Override public List getReorderableBooks(int limit) { EntityManager em = begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); @@ -368,6 +376,7 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService return result; } + @Override public long count(Class cls) { EntityManager em = getEntityManager(); CriteriaBuilder cb = em.getCriteriaBuilder(); @@ -391,6 +400,7 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService return result; } + @Override public List getExtent(Class entityClass) { EntityManager em = begin(); CriteriaQuery c = em.getCriteriaBuilder().createQuery(entityClass); @@ -400,6 +410,7 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService return result; } + @Override public List query(String jpql, Class resultClass, QueryDecorator... decorators) { EntityManager em = begin(); TypedQuery query = em.createQuery(jpql, resultClass); @@ -413,6 +424,7 @@ class OpenBookServiceImpl extends PersistenceService implements OpenBookService return result; } + @Override public void clean() { EntityManager em = begin(); Set> entities = em.getMetamodel().getEntities(); diff --git a/openjpa-examples/openbooks/src/main/java/openbook/server/PersistenceService.java b/openjpa-examples/openbooks/src/main/java/openbook/server/PersistenceService.java index b055c7af1..6317b099f 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/server/PersistenceService.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/server/PersistenceService.java @@ -32,14 +32,14 @@ import javax.persistence.PersistenceContextType; * @author Pinaki Poddar * */ -@SuppressWarnings("serial") abstract class PersistenceService implements Serializable { + private static final long serialVersionUID = 1L; private final EntityManagerFactory emf; private final String unitName; private final boolean isManaged; private final PersistenceContextType scope; - private ThreadLocal thread = new ThreadLocal(); + private ThreadLocal thread = new ThreadLocal<>(); private ReentrantLock lock = new ReentrantLock(); protected PersistenceService(String unit, EntityManagerFactory emf, boolean managed, diff --git a/openjpa-examples/openbooks/src/main/java/openbook/server/ServiceFactory.java b/openjpa-examples/openbooks/src/main/java/openbook/server/ServiceFactory.java index 3c241c886..6000b8260 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/server/ServiceFactory.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/server/ServiceFactory.java @@ -28,7 +28,7 @@ import javax.persistence.PersistenceContextType; * */ public class ServiceFactory { - private static final Map _services = new HashMap(); + private static final Map _services = new HashMap<>(); public synchronized static OpenBookService getService(String unit) { return getService(unit, null); diff --git a/openjpa-examples/openbooks/src/main/java/openbook/tools/CommandProcessor.java b/openjpa-examples/openbooks/src/main/java/openbook/tools/CommandProcessor.java index 52e5388de..f89200e26 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/tools/CommandProcessor.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/tools/CommandProcessor.java @@ -36,8 +36,8 @@ import java.util.Set; * */ public class CommandProcessor { - private final Map registeredOptions = new HashMap(); - private final Set