• 泛型类,泛型方法的使用


    泛型类,泛型方法的使用

    传递入对象类型,返回出对象类型都是泛型

    接口

    public interface CloudParamGetter<IN, OUT> {
    
        OUT get(IN in);
    }
    

    实现

    public class VmParamGetter implements CloudParamGetter<FamaVm, InstanceSpec> {
    
        @Override
        public InstanceSpec get(FamaVm vm) {
            InstanceSpec spec = new InstanceSpec();
            spec.setAz(vm.getAz());
            spec.setName(vm.getName());
            spec.setInstanceType(vm.getInstanceType());
            JsonArray json = vm.getTagJson();
            List<Tag> tagSpecs = Lists.newArrayList();
            for (JsonElement element : json) {
                JsonObject obj = element.getAsJsonObject();
                for (String s : obj.keySet()) {
                    String v = obj.get(s).getAsString();
                    Tag tag = new Tag();
                    tag.setKey(s);
                    tag.setValue(v);
                    tagSpecs.add(tag);
                }
            }
            spec.setUserTags(tagSpecs);
            InstanceDiskAttachmentSpec systemDisk = new InstanceDiskAttachmentSpec();
            int diskSize = vm.getDiskSize();
            if (diskSize <= 50) {
                systemDisk.setDiskCategory("local");
            } else {
                systemDisk.setDiskCategory("cloud");
            }
            systemDisk.setAutoDelete(true);
            DiskSpec diskSpec = new DiskSpec();
            diskSpec.setAz(vm.getAz());
            diskSpec.setDiskType(vm.getDiskType());
            diskSpec.setName(buildDiskName(vm.getAppEnName()));
            diskSpec.setDiskSizeGB(vm.getDiskSize());
            systemDisk.setCloudDiskSpec(diskSpec);
            spec.setSystemDisk(systemDisk);
            spec.setImageId(vm.getImageId());
            InstanceNetworkInterfaceAttachmentSpec primaryNetworkInterface = new InstanceNetworkInterfaceAttachmentSpec();
            NetworkInterfaceSpec networkInterface = new NetworkInterfaceSpec();
            networkInterface.setSubnetId(vm.getSubnetId());
            primaryNetworkInterface.setNetworkInterface(networkInterface);
            spec.setPrimaryNetworkInterface(primaryNetworkInterface);
            if (vm.getEnvType() == EnvType.TEST) {
                spec.setPassword("Focus2!_+");
            }
            return spec;
        }
    
        public String buildDiskName(String appEnName){
            String diskName = "DISK-" + appEnName.replace(".","_");
            if (diskName.length() <= 32){
                return diskName;
            }
            return diskName.substring(0,32);
        }
    }
    
    原创:做时间的朋友
  • 相关阅读:
    Yahoo 14条 雅虎十四条 优化原则【转】
    从HTML1到HTML5,回首HTML发展历史【转】
    HTML的发展历史【转】
    jquery中prop()方法和attr()方法的区别【转】
    一个文献综述的写法
    ammunition用法
    混了SQL连接就运行这个
    cruel用法
    ball up用法
    episode用法
  • 原文地址:https://www.cnblogs.com/PythonOrg/p/14837440.html
Copyright © 2020-2023  润新知