From cd1dfe669b5d4d155cdb5f4a97554ae91ab10cf9 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 22 Jun 2018 16:06:37 +0100 Subject: [PATCH] JAL-3032 avoid assignments on the same line as synchronized --- src/jalview/analysis/AlignmentSorter.java | 18 +++++++++--------- src/jalview/analysis/CrossRef.java | 14 +++++++------- src/jalview/appletgui/PaintRefresher.java | 6 +++--- src/jalview/commands/EditCommand.java | 20 ++++++++++---------- src/jalview/datamodel/HiddenSequences.java | 4 ++-- src/jalview/gui/PaintRefresher.java | 10 +++++----- src/jalview/gui/SequenceFetcher.java | 6 ++---- src/jalview/io/vamsas/Tree.java | 8 ++++---- .../ws/rest/params/SeqGroupIndexVector.java | 17 +++++++++++++---- 9 files changed, 55 insertions(+), 48 deletions(-) diff --git a/src/jalview/analysis/AlignmentSorter.java b/src/jalview/analysis/AlignmentSorter.java index b5cefe0..7ecce49 100755 --- a/src/jalview/analysis/AlignmentSorter.java +++ b/src/jalview/analysis/AlignmentSorter.java @@ -143,8 +143,8 @@ public class AlignmentSorter } // NOTE: DO NOT USE align.setSequenceAt() here - it will NOT work - List asq; - synchronized (asq = align.getSequences()) + List asq = align.getSequences(); + synchronized (asq) { for (int i = 0; i < len; i++) { @@ -179,10 +179,10 @@ public class AlignmentSorter public static void setOrder(AlignmentI align, SequenceI[] seqs) { // NOTE: DO NOT USE align.setSequenceAt() here - it will NOT work - List algn; - synchronized (algn = align.getSequences()) + List algn = align.getSequences(); + synchronized (algn) { - List tmp = new ArrayList(); + List tmp = new ArrayList<>(); for (int i = 0; i < seqs.length; i++) { @@ -279,7 +279,7 @@ public class AlignmentSorter { // MAINTAINS ORIGNAL SEQUENCE ORDER, // ORDERS BY GROUP SIZE - List groups = new ArrayList(); + List groups = new ArrayList<>(); if (groups.hashCode() != lastGroupHash) { @@ -315,7 +315,7 @@ public class AlignmentSorter // NOW ADD SEQUENCES MAINTAINING ALIGNMENT ORDER // ///////////////////////////////////////////// - List seqs = new ArrayList(); + List seqs = new ArrayList<>(); for (int i = 0; i < groups.size(); i++) { @@ -357,7 +357,7 @@ public class AlignmentSorter // tmp2 = tmp.retainAll(mask); // return tmp2.addAll(mask.removeAll(tmp2)) - ArrayList seqs = new ArrayList(); + ArrayList seqs = new ArrayList<>(); int i, idx; boolean[] tmask = new boolean[mask.size()]; @@ -436,7 +436,7 @@ public class AlignmentSorter { int nSeq = align.getHeight(); - List tmp = new ArrayList(); + List tmp = new ArrayList<>(); tmp = _sortByTree(tree.getTopNode(), tmp, align.getSequences()); diff --git a/src/jalview/analysis/CrossRef.java b/src/jalview/analysis/CrossRef.java index e6bae9b..0e7662b 100644 --- a/src/jalview/analysis/CrossRef.java +++ b/src/jalview/analysis/CrossRef.java @@ -99,7 +99,7 @@ public class CrossRef */ public List findXrefSourcesForSequences(boolean dna) { - List sources = new ArrayList(); + List sources = new ArrayList<>(); for (SequenceI seq : fromSeqs) { if (seq != null) @@ -151,7 +151,7 @@ public class CrossRef * find sequence's direct (dna-to-dna, peptide-to-peptide) xrefs */ DBRefEntry[] lrfs = DBRefUtils.selectDbRefs(fromDna, seq.getDBRefs()); - List foundSeqs = new ArrayList(); + List foundSeqs = new ArrayList<>(); /* * find sequences in the alignment which xref one of these DBRefs @@ -218,7 +218,7 @@ public class CrossRef public Alignment findXrefSequences(String source, boolean fromDna) { - rseqs = new ArrayList(); + rseqs = new ArrayList<>(); AlignedCodonFrame cf = new AlignedCodonFrame(); matcher = new SequenceIdMatcher(dataset.getSequences()); @@ -430,8 +430,8 @@ public class CrossRef if (retrieved != null) { boolean addedXref = false; - List newDsSeqs = new ArrayList(), - doNotAdd = new ArrayList(); + List newDsSeqs = new ArrayList<>(), + doNotAdd = new ArrayList<>(); for (SequenceI retrievedSequence : retrieved) { @@ -1008,8 +1008,8 @@ public class CrossRef System.err.println("Empty dataset sequence set - NO VECTOR"); return false; } - List ds; - synchronized (ds = dataset.getSequences()) + List ds = dataset.getSequences(); + synchronized (ds) { for (SequenceI nxt : ds) { diff --git a/src/jalview/appletgui/PaintRefresher.java b/src/jalview/appletgui/PaintRefresher.java index fe99187..ddf590e 100755 --- a/src/jalview/appletgui/PaintRefresher.java +++ b/src/jalview/appletgui/PaintRefresher.java @@ -52,7 +52,7 @@ public class PaintRefresher { if (components == null) { - components = new Hashtable>(); + components = new Hashtable<>(); } if (components.containsKey(seqSetId)) @@ -191,8 +191,8 @@ public class PaintRefresher { // TODO: the following does not trigger any recalculation of // height/etc, or maintain the dataset - List alsq; - synchronized (alsq = comp.getSequences()) + List alsq = comp.getSequences(); + synchronized (alsq) { alsq.add(i, a1[i]); } diff --git a/src/jalview/commands/EditCommand.java b/src/jalview/commands/EditCommand.java index cac843f..b813dcf 100644 --- a/src/jalview/commands/EditCommand.java +++ b/src/jalview/commands/EditCommand.java @@ -114,7 +114,7 @@ public class EditCommand implements CommandI public abstract Action getUndoAction(); }; - private List edits = new ArrayList(); + private List edits = new ArrayList<>(); String description; @@ -605,8 +605,8 @@ public class EditCommand implements CommandI // readd it to the alignment if (command.alIndex[i] < command.al.getHeight()) { - List sequences; - synchronized (sequences = command.al.getSequences()) + List sequences = command.al.getSequences(); + synchronized (sequences) { if (!(command.alIndex[i] < 0)) { @@ -789,7 +789,7 @@ public class EditCommand implements CommandI if (modifyVisibility && !insert) { // only occurs if a sequence was added or deleted. - command.deletedAnnotationRows = new Hashtable(); + command.deletedAnnotationRows = new Hashtable<>(); } if (command.fullAlignmentHeight) { @@ -948,7 +948,7 @@ public class EditCommand implements CommandI if (!insert) { - command.deletedAnnotations = new Hashtable(); + command.deletedAnnotations = new Hashtable<>(); } int aSize; @@ -1138,7 +1138,7 @@ public class EditCommand implements CommandI return; } - List oldsf = new ArrayList(); + List oldsf = new ArrayList<>(); int cSize = j - i; @@ -1196,7 +1196,7 @@ public class EditCommand implements CommandI if (command.editedFeatures == null) { - command.editedFeatures = new Hashtable>(); + command.editedFeatures = new Hashtable<>(); } command.editedFeatures.put(seq, oldsf); @@ -1233,7 +1233,7 @@ public class EditCommand implements CommandI */ public Map priorState(boolean forUndo) { - Map result = new HashMap(); + Map result = new HashMap<>(); if (getEdits() == null) { return result; @@ -1266,7 +1266,7 @@ public class EditCommand implements CommandI * Work backwards through the edit list, deriving the sequences before each * was applied. The final result is the sequence set before any edits. */ - Iterator editList = new ReverseListIterator(getEdits()); + Iterator editList = new ReverseListIterator<>(getEdits()); while (editList.hasNext()) { Edit oldEdit = editList.next(); @@ -1427,7 +1427,7 @@ public class EditCommand implements CommandI } else { - return new ReverseListIterator(getEdits()); + return new ReverseListIterator<>(getEdits()); } } } diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java index c9dce08..b5efeb4 100755 --- a/src/jalview/datamodel/HiddenSequences.java +++ b/src/jalview/datamodel/HiddenSequences.java @@ -222,8 +222,8 @@ public class HiddenSequences end = hiddenSequences.length - 1; } - List asequences; - synchronized (asequences = alignment.getSequences()) + List asequences = alignment.getSequences(); + synchronized (asequences) { for (int index = end; index > start; index--) { diff --git a/src/jalview/gui/PaintRefresher.java b/src/jalview/gui/PaintRefresher.java index ced5544..54fe488 100755 --- a/src/jalview/gui/PaintRefresher.java +++ b/src/jalview/gui/PaintRefresher.java @@ -39,7 +39,7 @@ import java.util.Map; */ public class PaintRefresher { - static Map> components = new HashMap>(); + static Map> components = new HashMap<>(); /** * Add the given component to those registered under the given sequence set @@ -60,7 +60,7 @@ public class PaintRefresher } else { - List vcoms = new ArrayList(); + List vcoms = new ArrayList<>(); vcoms.add(comp); components.put(seqSetId, vcoms); } @@ -186,8 +186,8 @@ public class PaintRefresher System.err.println( "IMPLEMENTATION PROBLEM: DATASET out of sync due to an insert whilst calling PaintRefresher.validateSequences(AlignmentI, ALignmentI)"); } - List alsq; - synchronized (alsq = comp.getSequences()) + List alsq = comp.getSequences(); + synchronized (alsq) { alsq.add(i, a1[i]); } @@ -240,7 +240,7 @@ public class PaintRefresher { return new AlignmentPanel[0]; } - List tmp = new ArrayList(); + List tmp = new ArrayList<>(); for (Component comp : comps) { if (comp instanceof AlignmentPanel) diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index f545e70..0a51c7f 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -24,7 +24,6 @@ import jalview.api.FeatureSettingsModelI; import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefEntry; -import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.fts.core.GFTSPanel; import jalview.fts.service.pdb.PDBFTSPanel; @@ -1027,9 +1026,8 @@ public class SequenceFetcher extends JPanel implements Runnable // Alignments? } - SequenceFeature[] sfs = null; - List alsqs; - synchronized (alsqs = al.getSequences()) + List alsqs = al.getSequences(); + synchronized (alsqs) { for (SequenceI sq : alsqs) { diff --git a/src/jalview/io/vamsas/Tree.java b/src/jalview/io/vamsas/Tree.java index aa130cc..c0f65c4 100644 --- a/src/jalview/io/vamsas/Tree.java +++ b/src/jalview/io/vamsas/Tree.java @@ -271,14 +271,14 @@ public class Tree extends DatastoreItem * @return vector of alignment sequences in order of SeqCigar array (but * missing unfound seqcigars) */ - private Vector findAlignmentSequences(AlignmentI jal, + private Vector findAlignmentSequences(AlignmentI jal, SeqCigar[] sequences) { SeqCigar[] tseqs = new SeqCigar[sequences.length]; System.arraycopy(sequences, 0, tseqs, 0, sequences.length); - Vector alsq = new Vector(); - List jalsqs; - synchronized (jalsqs = jal.getSequences()) + Vector alsq = new Vector<>(); + List jalsqs = jal.getSequences(); + synchronized (jalsqs) { for (SequenceI asq : jalsqs) { diff --git a/src/jalview/ws/rest/params/SeqGroupIndexVector.java b/src/jalview/ws/rest/params/SeqGroupIndexVector.java index dcb7fab..9210414 100644 --- a/src/jalview/ws/rest/params/SeqGroupIndexVector.java +++ b/src/jalview/ws/rest/params/SeqGroupIndexVector.java @@ -75,6 +75,7 @@ public class SeqGroupIndexVector extends InputType * - alignment to be processed * @return al or a new alignment with appropriate attributes/order for input */ + @Override public AlignmentI prepareAlignment(AlignmentI al) { jalview.analysis.AlignmentSorter.sortByGroup(al); @@ -90,10 +91,10 @@ public class SeqGroupIndexVector extends InputType AlignmentI al = rj.getAlignmentForInput(token, type); // assume that alignment is properly ordered so groups form consecutive // blocks - ArrayList gl = new ArrayList(); + ArrayList gl = new ArrayList<>(); int p = 0, lowest = al.getHeight(), highest = 0; - List sgs; - synchronized (sgs = al.getGroups()) + List sgs = al.getGroups(); + synchronized (sgs) { for (SequenceGroup sg : sgs) { @@ -125,9 +126,13 @@ public class SeqGroupIndexVector extends InputType else { if (p < se[0]) + { se[0] = p; + } if (p > se[1]) + { se[1] = p; + } } } if (se != null) @@ -168,7 +173,9 @@ public class SeqGroupIndexVector extends InputType int[][] vals = gl.toArray(new int[gl.size()][]); int[] srt = new int[gl.size()]; for (int i = 0; i < vals.length; i++) + { srt[i] = vals[i][0]; + } jalview.util.QuickSort.sort(srt, vals); list = false; int last = vals[0][0] - 1; @@ -210,7 +217,7 @@ public class SeqGroupIndexVector extends InputType @Override public List getURLEncodedParameter() { - ArrayList prms = new ArrayList(); + ArrayList prms = new ArrayList<>(); super.addBaseParams(prms); prms.add("minsize='" + minsize + "'"); prms.add("sep='" + sep + "'"); @@ -243,7 +250,9 @@ public class SeqGroupIndexVector extends InputType { minsize = Integer.valueOf(val); if (minsize >= 0) + { return true; + } } catch (Exception x) { -- 1.7.10.2