Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to jclouds, Inc. (jclouds) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. jclouds licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.jclouds.cloudsigma.functions;
 
 import java.util.Map;
 
 
 

Author(s):
Adrian Cole
 
 public class MapToDevices implements Function<Map<StringString>, Map<String, ? extends Device>> {
    @Singleton
    public static class DeviceToId implements Function<DeviceString> {
       @Override
       public String apply(Device input) {
          return input.getId();
       }
    }
 
    private final Function<DeviceStringdeviceToId;
 
    @Inject
    public MapToDevices(Function<DeviceStringdeviceToId) {
       this. = deviceToId;
    }
 
    public Map<String, ? extends Deviceapply(Map<StringStringfrom) {
       Builder<Devicedevices = ImmutableSet.builder();
       addIDEDevices(fromdevices);
       addSCSIDevices(fromdevices);
       addBlockDevices(fromdevices);
 
       return Maps.uniqueIndex(devices.build(), );
    }
 
    protected void addBlockDevices(Map<StringStringfromBuilder<Devicedevices) {
       BLOCK: for (int index : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) {
          String key = String.format("block:0:%d"index);
          if (!from.containsKey(key))
             break BLOCK;
          devices.add(populateBuilder(new BlockDevice.Builder(index), keyfrom).build());
       }
    }
 
    protected void addSCSIDevices(Map<StringStringfromBuilder<Devicedevices) {
       SCSI: for (int unit : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) {
          String key = String.format("scsi:0:%d"unit);
          if (!from.containsKey(key))
             break SCSI;
          devices.add(populateBuilder(new SCSIDevice.Builder(unit), keyfrom).build());
       }
    }
 
    protected void addIDEDevices(Map<StringStringfromBuilder<Devicedevices) {
       IDE: for (int bus : new int[] { 0, 1 })
          for (int unit : new int[] { 0, 1 }) {
             String key = String.format("ide:%d:%d"busunit);
             if (!from.containsKey(key))
                break IDE;
             devices.add(populateBuilder(new IDEDevice.Builder(busunit), keyfrom).build());
          }
    }
 
    protected Device.Builder populateBuilder(Device.Builder deviceBuilderString keyMap<StringStringfrom) {
       deviceBuilder.uuid(from.get(key));
       if (from.containsKey(key + ":media"))
          deviceBuilder.mediaType(MediaType.fromValue(from.get(key + ":media")));
       return deviceBuilder;
   }
New to GrepCode? Check out our FAQ X