Here you can find the source of mapToList(final TreeMap
Parameter | Description |
---|---|
map | a parameter |
static <T> List<List<T>> mapToList(final TreeMap<Integer, List<T>> map)
//package com.java2s; /*/*from w ww . j av a 2 s . c o m*/ * libChEBIj (c) University of Manchester 2015 * * libChEBIj is licensed under the MIT License. * * To view a copy of this license, visit <http://opensource.org/licenses/MIT/>. */ import java.util.*; public class Main { /** * * @param map * @return List<Collection<T>> */ static <T> List<List<T>> mapToList(final TreeMap<Integer, List<T>> map) { final int lastIndex = map.lastKey().intValue(); final int capacity = lastIndex + 1; final List<List<T>> list = new ArrayList<>(capacity); for (int i = 0; i < capacity; i++) { list.add(new ArrayList<T>()); } for (Map.Entry<Integer, List<T>> entry : map.entrySet()) { list.set(entry.getKey().intValue(), entry.getValue()); } return list; } /** * * @param id * @param map * @param object */ static <T> void add(final Integer id, final TreeMap<Integer, List<T>> map, T object) { List<T> list = map.get(id); if (list == null) { list = new ArrayList<>(); map.put(id, list); } list.add(object); } }