Changeset 409

Show
Ignore:
Timestamp:
06/14/10 14:36:59 (20 months ago)
Author:
martijn
Message:

Extra utility method, more documentation of utility methods

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/org.bridgedb/src/org/bridgedb/impl/InternalUtils.java

    r308 r409  
    192192    /** 
    193193     * Generic method for multimaps, a map that can contain multiple values per key. 
    194      */ 
     194     * Unlike a regular map, if you insert a value for a key that already exists, the previous value  
     195     * will not be discared.  
     196     * @param <T> key type of multimap 
     197     * @param <U> value type of multimap 
     198     * @param map multimap to work on 
     199     * @param key key of the value to insert 
     200     * @param val value to insert. 
     201    */ 
    195202    public static <T, U> void multiMapPut(Map<T, Set<U>> map, T key, U val) 
    196203    { 
     
    210217    /** 
    211218     * Generic method for multimaps, a map that can contain multiple values per key. 
     219     * Unlike a regular map, if you insert a value for a key that already exists, the previous value  
     220     * will not be discared. 
     221     * <p> 
     222     * multiMapPutAll let's you insert a collection of items at once.  
     223     * @param <T> key type of multimap 
     224     * @param <U> value type of multimap 
     225     * @param map multimap to work on 
     226     * @param key key of the value to insert 
     227     * @param vals values to insert. 
    212228     */ 
    213229    public static <T, U> void multiMapPutAll(Map<T, Set<U>> map, T key, Collection<U> vals) 
     
    226242    } 
    227243 
     244    /** 
     245     * Split a heterogeneous Xref set into multiple homogeneous Xref sets. 
     246     * <p> 
     247     * If the input contains {L:3643, L:1234, X:1004_at, X:1234_at}, 
     248     * then the output will contain 
     249     * { L=> {L:3643, L:1234}, X=> {X:1004_at, X:1234_at} }. 
     250     * @param srcXrefs the set to split 
     251     * @return map with datasources as keys and homogeneous sets as values. 
     252     */ 
     253        public static Map<DataSource, Set<Xref>> groupByDataSource(Collection<Xref> srcXrefs) 
     254        { 
     255                Map<DataSource, Set<Xref>> result = new HashMap<DataSource, Set<Xref>>(); 
     256                for (Xref ref : srcXrefs)  
     257                {   
     258                        multiMapPut(result, ref.getDataSource(), ref); 
     259                } 
     260                return result; 
     261        } 
     262 
    228263}