Class InternalUtils
- java.lang.Object
-
- org.bridgedb.impl.InternalUtils
-
public final class InternalUtils extends Object
To prevent duplication and redundancy, functions that are common to multiple IDMapper implementations can be placed here.Warning! This class is not part of the public API of BridgeDb. Methods in this class may disappear or change in backwards-incompatible ways. This class should not be used by applications!
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static InputStreamgetInputStream(String source)static InputStreamgetInputStream(URL source)Start downloading a file from the web and open an InputStream to it.static Map<DataSource,Set<Xref>>groupByDataSource(Collection<Xref> srcXrefs)Split a heterogeneousXrefset into multiple homogeneous Xref sets.static StringjoinIds(Collection<Xref> refs, String sep)Join the ID part of a collection of Xrefs with a custom separator.static Map<Xref,Set<Xref>>mapMultiFromSingle(IDMapper mapper, Collection<Xref> srcXrefs, DataSource... tgt)call the "single" mapID (Xref, ...) multiple times to perform mapping of a Set.static Set<Xref>mapSingleFromMulti(IDMapper mapper, Xref src, DataSource... tgt)call the "multi" mapID (Set, ...) using a Set with one item to perform mapping of a single ID.static <T,U>
voidmultiMapAdd(Map<T,List<U>> map, T key, U val)Generic method for multimaps, a map that can contain multiple values per key.static <T,U>
voidmultiMapPut(Map<T,Set<U>> map, T key, U val)Generic method for multimaps, a map that can contain multiple values per key.static <T,U>
voidmultiMapPutAll(Map<T,Set<U>> map, T key, Collection<U> vals)Generic method for multimaps, a map that can contain multiple values per key.static Map<String,String>parseLocation(String location, String... allowedParams)parse configuration params of the connection string.static voidreadXmlConfig(InputSource is)read a configuration file in the bridgedb xml format
-
-
-
Method Detail
-
mapMultiFromSingle
public static Map<Xref,Set<Xref>> mapMultiFromSingle(IDMapper mapper, Collection<Xref> srcXrefs, DataSource... tgt) throws IDMapperException
call the "single" mapID (Xref, ...) multiple times to perform mapping of a Set.This is intended for IDMappers that don't gain any advantage of mapping multiple ID's at a time. They can implement mapID(Xref, ...), and use mapMultiFromSingle to simulate mapID(Set, ...)
- Parameters:
mapper- used for performing a single mappingsrcXrefs- xrefs to translatetgt- DataSource(s) to map to, optional.- Returns:
- mappings with the translated result for each input Xref. Never returns null, but not each input is a key in the output map.
- Throws:
IDMapperException- when mapper.mapID throws IDMapperException
-
mapSingleFromMulti
public static Set<Xref> mapSingleFromMulti(IDMapper mapper, Xref src, DataSource... tgt) throws IDMapperException
call the "multi" mapID (Set, ...) using a Set with one item to perform mapping of a single ID.This is intended for IDMappers that have a performance advantage of mapping multiple ID's at a time. They can implement mapID(Set, ...), and use mapSingleFromMulti to simulate mapID(Xref, ...)
- Parameters:
mapper- used for performing a multi-mappingsrc- xref to translatetgt- DataSource(s) to map to, optional.- Returns:
- Set of translated Xrefs, or an empty set if none were found.
- Throws:
IDMapperException- when mapper.mapID throws IDMapperException
-
parseLocation
public static Map<String,String> parseLocation(String location, String... allowedParams)
parse configuration params of the connection string. Connection strings are expected to have a formatting like{base?arg1=val&arg2=val}.- Parameters:
location- - configuration string to parse.allowedParams- - allowed argument names to appear before =- Returns:
- key / value Map of configuration arguments. The base (the part before the ?) is returned in the special key "BASE". If the part before ? is empty, the "BASE" key is not created.
- Throws:
IllegalArgumentException- if arguments do not follow the key=val structure, or if the key is not in allowedParams
-
getInputStream
public static InputStream getInputStream(String source) throws IOException
- Throws:
IOException
-
getInputStream
public static InputStream getInputStream(URL source) throws IOException
Start downloading a file from the web and open an InputStream to it.- Parameters:
source- location of file to download.- Returns:
- InputStream
- Throws:
IOException- after a number of attempts to connect to the remote server have failed.
-
multiMapPut
public static <T,U> void multiMapPut(Map<T,Set<U>> map, T key, U val)
Generic method for multimaps, a map that can contain multiple values per key. Unlike a regular map, if you insert a value for a key that already exists, the previous value will not be discared.- Type Parameters:
T- key type of multimapU- value type of multimap- Parameters:
map- multimap to work onkey- key of the value to insertval- value to insert.
-
multiMapAdd
public static <T,U> void multiMapAdd(Map<T,List<U>> map, T key, U val)
Generic method for multimaps, a map that can contain multiple values per key. Unlike a regular map, if you insert a value for a key that already exists, the previous value will not be discarded.This is like multiMapPut, but uses a list instead of a set for each value of the map.
- Type Parameters:
T- key type of multimapU- value type of multimap- Parameters:
map- multimap to work onkey- key of the value to insertval- value to insert.
-
multiMapPutAll
public static <T,U> void multiMapPutAll(Map<T,Set<U>> map, T key, Collection<U> vals)
Generic method for multimaps, a map that can contain multiple values per key. Unlike a regular map, if you insert a value for a key that already exists, the previous value will not be discarded.multiMapPutAll let's you insert a collection of items at once.
- Type Parameters:
T- key type of multimapU- value type of multimap- Parameters:
map- multimap to work onkey- key of the value to insertvals- values to insert.
-
groupByDataSource
public static Map<DataSource,Set<Xref>> groupByDataSource(Collection<Xref> srcXrefs)
Split a heterogeneousXrefset into multiple homogeneous Xref sets.If the input contains {L:3643, L:1234, X:1004_at, X:1234_at}, then the output will contain { L=> {L:3643, L:1234}, X=> {X:1004_at, X:1234_at} }.
- Parameters:
srcXrefs- the set to split- Returns:
- map with datasources as keys and homogeneous sets as values.
-
joinIds
public static String joinIds(Collection<Xref> refs, String sep)
Join the ID part of a collection of Xrefs with a custom separator.- Parameters:
refs- Xrefs from which the ids will be concatenatedsep- separator string.- Returns:
- concatenation of the ids.
-
readXmlConfig
public static void readXmlConfig(InputSource is) throws ParserConfigurationException, SAXException, IOException
read a configuration file in the bridgedb xml format- Parameters:
is- - the input source- Throws:
ParserConfigurationException- - exception classSAXException- - exception classIOException- - exception class
-
-