コード例 #1
0
 /**
  * Return a map of pool URI to a list of descriptors in that pool.
  *
  * @param descriptors List<VolumeDescriptors>
  * @return Map of pool URI to List<VolumeDescriptors> in that pool
  */
 public static Map<URI, List<VolumeDescriptor>> getPoolMap(List<VolumeDescriptor> descriptors) {
   HashMap<URI, List<VolumeDescriptor>> poolMap = new HashMap<URI, List<VolumeDescriptor>>();
   for (VolumeDescriptor desc : descriptors) {
     if (poolMap.get(desc.getPoolURI()) == null) {
       poolMap.put(desc.getPoolURI(), new ArrayList<VolumeDescriptor>());
     }
     poolMap.get(desc.getPoolURI()).add(desc);
   }
   return poolMap;
 }
コード例 #2
0
  /**
   * Return a map of pool URI to a list of descriptors in that pool of each size.
   *
   * @param descriptors List<VolumeDescriptors>
   * @return Map of pool URI to a map of identical sized volumes to List<VolumeDescriptors> in that
   *     pool of that size
   */
  public static Map<URI, Map<Long, List<VolumeDescriptor>>> getPoolSizeMap(
      List<VolumeDescriptor> descriptors) {
    Map<URI, Map<Long, List<VolumeDescriptor>>> poolSizeMap =
        new HashMap<URI, Map<Long, List<VolumeDescriptor>>>();
    for (VolumeDescriptor desc : descriptors) {

      // If the outside pool map doesn't exist, create it.
      if (poolSizeMap.get(desc.getPoolURI()) == null) {
        poolSizeMap.put(desc.getPoolURI(), new HashMap<Long, List<VolumeDescriptor>>());
      }

      // If the inside size map doesn't exist, create it.
      if (poolSizeMap.get(desc.getPoolURI()).get(desc.getVolumeSize()) == null) {
        poolSizeMap
            .get(desc.getPoolURI())
            .put(desc.getVolumeSize(), new ArrayList<VolumeDescriptor>());
      }

      // Add volume to the list
      poolSizeMap.get(desc.getPoolURI()).get(desc.getVolumeSize()).add(desc);
    }

    return poolSizeMap;
  }