



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
package org.cloudbus.cloudsim;import java.util.List;/An ordered collection (also known as a sequence)import java.util.Map;/【补充:针对java.util.Map的Value做排序 来源:360doc】针对java.util.Map的Value做排序:/Map的特性:/Map内涵数据是Key - Value的架构集合体,而Key是属于Set的架构集合体,也就是说Key的值是唯一的,而Value的值可以重复。一般常用的对象是HashMap或TreeMap,如果考虑效能的话,建议使用HashMap,如果希望Key值有顺序性,就使用TreeMap吧!所以Map的集合体,数据的摆放方式是没有顺序性的,我们需要借助有顺序性的集合体List来帮忙。/范例数据如下定义:/Map map_Data = new HashMap();/map_Data.put(A, 98);/map_Data.put(B, 50);/map_Data.put(C, 76);/map_Data.put(D, 23);/map_Data.put(E, 85);/System.out.println(map_Data);现在将Map集合体转换成List集合体,而List对象使用ArrayList来实做如下:/将map_Data由Map型态转成List型态的list_Data,以便进行排序/ListMap.Entry list_Data = new ArrayListMap.Entry(map_Data.entrySet();/透过Collections.sort(List l, Comparator c)方法来做排序的动作,由传入参数可以了解List l就是要排序的数据结构体,另外还需要一个Comparator c对象,此对象是用来评估List l中的任两对象的大小值,实做如下:/排序/Collections.sort(list_Data, new ComparatorMap.Entry()/ /public int compare(Map.Entry o1, Map.Entry o2)/ /return (o2.getValue() - o1.getValue();/);/上方的Comparator c参数是使用匿名类别的方式来实做的。所以排序完成的数据内容在list_Data这个对象中,将其印出来看结果:/System.out.println(list_Data); /*【VmAllocationPolicy 抽象类 代表数据中心主机到虚拟机的供应协议】 * VmAllocationPolicy is an abstract class that represents the provisioning * policy of hosts to virtual machines in a Datacentre. It supports【 two-stage * commit of reservation of hosts】: first, we reserve the host and, once * commited by the user, it is effectivelly allocated to he/she * * authorRodrigo N. Calheiros * authorAnton Beloglazov * sinceCloudSim Toolkit 1.0 */public abstract class VmAllocationPolicy /* The host list. 主机列表*/private List hostList;/限制泛型/*分配一新的VmAllocationPolicy对象 * Allocates a new VmAllocationPolicy object. * * param list Machines available in this Datacentre * * pre $none * post $none */public VmAllocationPolicy(List list) setHostList(list);/*分配主机给一特定虚拟机 * Allocates a host for a given VM. The host to be allocated is the one * that was already reserved. * * param vm virtual machine which the host is reserved to * * return $true if the host could be allocated; $false otherwise * * pre $none * post $none */public abstract boolean allocateHostForVm(Vm vm);/*分配一特定主机给指定虚拟机 * Allocates a specified host for a given VM. * * param vm virtual machine which the host is reserved to * * return $true if the host could be allocated; $false otherwise * * pre $none * post $none */public abstract boolean allocateHostForVm(Vm vm, Host host);/*【根据当前利用率最优虚拟机分配】 * Optimize allocation of the VMs according to current utilization. * * param vmList the vm list * param utilizationBound the utilization bound * param time the time * * return the array list hash map */public abstract ListMap optimizeAllocation(List vmList);/*释放主机 * Releases the host used by a VM. * * param vm the vm * * pre $none * post $none */public abstract void deallocateHostForVm(Vm vm);/*指定用户指定虚拟机上的主机 * Get the host that is executing the given VM belonging to the * given user. * * param vm the vm * * return the Host with the given vmID and userID; $null if not found * * pre $none * post $none */public abstract Host getHost(Vm vm);/* 与上面同样的功能 ? * Get the host that is executing the given VM belonging to the * given user. * * param vmId the vm id * param userId the user id * * return the Host with the given vmID and userID; $null if not found * * pre $none * post $none */public abstract Host getHost(int vmId, int userId);/*设置主机列表 * Sets the host list. * * param hostList the new host list */protected void setH
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年下沉市场消费金融发展趋势与应对策略分析报告
- 药品车间现场管理制度
- 药学信息人员管理制度
- 药店库房养护管理制度
- 药店药品调剂管理制度
- 营运内控基础管理制度
- 设备保养检查管理制度
- 设备备件集中管理制度
- 设备报废更新管理制度
- 设备检修进度管理制度
- 山东省菏泽市鄄城县2023-2024学年七年级下学期7月期末英语试题
- 国际法(第七版) 课件 第九章 外交和领事关系法
- 国家开放大学本科《会计实务专题》形考作业一至四试题及答案
- 2024年哈尔滨铁道职业技术学院单招职业适应性测试题库各版本
- 水表检定记录全册
- 安徽省合肥市庐阳区2022-2023学年五年级下学期期末科学试卷
- DG-TJ08-2411-2023 地下结构隔排水主动抗浮技术标准
- 三期(孕期、产期、哺乳期)员工风险评估
- 国家开放大学《土地利用规划》本章自测参考答案
- 多重耐药菌相关知课件
- 竞选车间班长的演讲稿
评论
0/150
提交评论