Clover icon

Coverage Report

  1. Project Clover database Thu Nov 28 2024 18:06:40 GMT
  2. Package jalview.urls

File UrlProviderImpl.java

 

Coverage histogram

../../img/srcFileCovDistChart9.png
13% of files have more coverage

Code metrics

10
26
5
1
123
84
12
0.46
5.2
5
2.4

Classes

Class Line # Actions
UrlProviderImpl 39 26 12
0.8536585685.4%
 

Contributing tests

This file is covered by 18 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.urls;
22   
23    import jalview.urls.api.UrlProviderI;
24    import jalview.util.UrlLink;
25   
26    import java.util.ArrayList;
27    import java.util.HashMap;
28    import java.util.List;
29    import java.util.Map.Entry;
30    import java.util.regex.Pattern;
31   
32    /**
33    * Leaf node of UrlProvider composite
34    *
35    * @author $author$
36    * @version $Revision$
37    */
38   
 
39    public abstract class UrlProviderImpl implements UrlProviderI
40    {
41    // minimum length of substitution in url link string
42    protected static final int MIN_SUBST_LENGTH = 4;
43   
44    private static final Pattern MIRIAM_PATTERN = Pattern
45    .compile("^MIR:\\d{8}$");
46   
47    protected String primaryUrl;
48   
 
49  19 toggle protected String getPrimaryUrl(String seqid,
50    HashMap<String, UrlLink> urls)
51    {
52  19 if (seqid.length() < MIN_SUBST_LENGTH)
53    {
54  3 return null;
55    }
56  16 else if (primaryUrl == null)
57    {
58  7 return null;
59    }
60  9 else if (!urls.containsKey(primaryUrl))
61    {
62  0 return null;
63    }
64    else
65    {
66  9 String url = null;
67  9 UrlLink urlLink = urls.get(primaryUrl);
68  9 String[] primaryUrls = urlLink.makeUrls(seqid, true);
69  9 if (primaryUrls == null || primaryUrls[0] == null
70    || primaryUrls[0].length() < MIN_SUBST_LENGTH)
71    {
72  0 url = null;
73    }
74    else
75    {
76    // just take first URL made from regex
77  9 url = primaryUrls[1];
78    }
79  9 return url;
80    }
81    }
82   
 
83  0 toggle @Override
84    public List<UrlLinkDisplay> getLinksForTable()
85    {
86  0 return null;
87    }
88   
 
89  63 toggle protected ArrayList<UrlLinkDisplay> getLinksForTable(
90    HashMap<String, UrlLink> urls, ArrayList<String> selectedUrls,
91    boolean selected)
92    {
93  63 ArrayList<UrlLinkDisplay> displayLinks = new ArrayList<UrlLinkDisplay>();
94  63 for (Entry<String, UrlLink> entry : urls.entrySet())
95    {
96  6347 String key = entry.getKey();
97  6347 boolean isPrimary = (key.equals(primaryUrl));
98  6347 boolean isSelected;
99  6347 if (selectedUrls != null)
100    {
101  6274 isSelected = selectedUrls.contains(key);
102    }
103    else
104    {
105  73 isSelected = selected;
106    }
107  6347 displayLinks.add(new UrlLinkDisplay(key, entry.getValue(), isSelected,
108    isPrimary));
109    }
110  63 return displayLinks;
111    }
112   
 
113  662 toggle protected boolean isMiriamId(String id)
114    {
115  662 return MIRIAM_PATTERN.matcher(id).matches();
116    }
117   
 
118  20 toggle @Override
119    public boolean isUserEntry(String id)
120    {
121  20 return !isMiriamId(id);
122    }
123    }