From f2a83f0360d406859b80cc798099a9d270461bb3 Mon Sep 17 00:00:00 2001 From: kiramt Date: Mon, 5 Feb 2018 13:41:52 +0000 Subject: [PATCH] JAL-2788 possible adjustments to sequence accesses --- src/jalview/datamodel/Alignment.java | 44 ++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index baa8e83..c564618 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -49,7 +49,7 @@ public class Alignment implements AlignmentI { private Alignment dataset; - protected List sequences; + private List sequences; protected List groups; @@ -191,10 +191,12 @@ public class Alignment implements AlignmentI @Override public SequenceI getSequenceAt(int i) { - // don't need to synchronise here as sequences is a synchronizedList - if (i > -1 && i < sequences.size()) + synchronized (sequences) { - return sequences.get(i); + if (i > -1 && i < sequences.size()) + { + return sequences.get(i); + } } return null; @@ -705,7 +707,7 @@ public class Alignment implements AlignmentI public int getWidth() { int maxLength = -1; - + for (int i = 0; i < sequences.size(); i++) { if (getSequenceAt(i).getLength() > maxLength) @@ -713,9 +715,34 @@ public class Alignment implements AlignmentI maxLength = getSequenceAt(i).getLength(); } } - + return maxLength; } + /* + @Override + public int getWidth() + { + final Wrapper temp = new Wrapper(); + + forEachSequence(new Consumer() + { + @Override + public void accept(SequenceI s) + { + if (s.getLength() > temp.inner) + { + temp.inner = s.getLength(); + } + } + }, 0, sequences.size() - 1); + + return temp.inner; + } + + public static class Wrapper + { + public int inner; + }*/ /** * DOCUMENT ME! @@ -1917,7 +1944,10 @@ public class Alignment implements AlignmentI @Override public void forEachSequence(Consumer c, int start, int end) { - sequences.subList(start, end).forEach(c); + synchronized (sequences) + { + sequences.subList(start, end).forEach(c); + } } } -- 1.7.10.2