JAL-2349 TODO consider caching contactRanges from getContactRange to improve efficiency
[jalview.git] / src / jalview / datamodel / ContactListImpl.java
index 6eb4cdb..8e806e4 100644 (file)
@@ -10,7 +10,6 @@ public class ContactListImpl implements ContactListI
 {
   ContactListProviderI clist;
 
-
   public static ContactListI newContactList(ContactListProviderI list)
   {
     return new ContactListImpl(list);
@@ -22,6 +21,12 @@ public class ContactListImpl implements ContactListI
   }
 
   @Override
+  public int getPosition()
+  {
+    return clist.getPosition();
+  }
+
+  @Override
   public double getContactAt(int column)
   {
     return clist.getContactAt(column);
@@ -36,6 +41,7 @@ public class ContactListImpl implements ContactListI
   @Override
   public ContactRange getRangeFor(int from_column, int to_column)
   {
+    // TODO: consider caching ContactRange for a particular call ?
     if (clist instanceof ContactListI)
     {
       // clist may implement getRangeFor in a more efficient way, so use theirs
@@ -53,7 +59,7 @@ public class ContactListImpl implements ContactListI
     cr.setFrom_column(from_column);
     cr.setTo_column(to_column);
     double tot = 0;
-    for (int i = from_column; i < to_column; i++)
+    for (int i = from_column; i <= to_column; i++)
     {
       double contact = getContactAt(i);
       tot += contact;
@@ -80,7 +86,7 @@ public class ContactListImpl implements ContactListI
     }
     if (tot > 0)
     {
-      cr.setMean(tot / (to_column - from_column));
+      cr.setMean(tot / (1 + to_column - from_column));
     }
     else
     {