schedule_unknown
2016-02-05 23:17
197 查看
package amazon; import introJAVA.newTestJava; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.PriorityQueue; public class Schedule { /** * @param * */ public static void schedule(){ ArrayList<ArrayList<Content>> lists = new ArrayList<>(); HashMap<String, Content> map = new HashMap<>(); PriorityQueue<Content> queue = new PriorityQueue<Content>(3,new Comparator<Content>() { public int compare(Content c1 , Content c2){ return c1.getEndTime() - c2.getEndTime(); } }); //Read In // Iterator<Content> iterator = readIn(); // while(iterator.hasNext()){ // Content content = iterator.next(); // String location = content.getLocationId(); // //convert char to integer and minus 1 to be the index // int index = location.charAt(location.length()-1)-'1'; // lists.get(index).add(content); // } lists.add(new ArrayList<Content>()); lists.get(0).add(new Content("c9", "a1", 2, 5, 10)); lists.get(0).add(new Content("c1", "a1", 1, 4, 10)); lists.get(0).add(new Content("c5", "a1", 3, 5, 10)); lists.get(0).add(new Content("c7", "a1", 1, 7, 10)); lists.get(0).add(new Content("c2", "a1", 7, 12, 10)); lists.get(0).add(new Content("c3", "a1", 13, 17, 10)); lists.get(0).add(new Content("c1", "a1", 19, 19, 10)); lists.get(0).add(new Content("c6", "a1", 10, 20, 10)); lists.get(0).add(new Content("c1", "a1", 10, 12, 10)); lists.get(0).add(new Content("c8", "a1", 15, 20, 10)); for(int i=0; i < lists.size(); i++){ ArrayList<Content> result = new ArrayList<>(); //sort by content's start time Collections.sort(lists.get(i), new Comparator<Content>() { @Override public int compare(Content c1, Content c2) { return c1.getStartTime()- c2.getStartTime(); } }); for(int j=0; j < lists.get(i).size(); j++){ Content content = lists.get(i).get(j); String contentId = content.getContentId(); if(!map.containsKey(contentId)){ map.put(contentId, content); if(queue.size()<3){ queue.add(content); result.add(content); }else{ Content temp = queue.peek(); if(content.getStartTime()>temp.getEndTime()){ queue.poll(); queue.add(content); result.add(content); } } }else{ if(content.getStartTime()>map.get(contentId).getEndTime()){ map.replace(contentId, content); if(queue.size()<3){ queue.add(content); result.add(content); }else{ Content temp = queue.peek(); if(content.getStartTime()>temp.getEndTime()){ queue.poll(); queue.add(content); result.add(content); } } } } } for(int r=0;r<result.size();r++){ System.out.println(result.get(r).getContentId()); } } } public static void schedule2(){ HashMap<String, ArrayList<Content>> hashMap = new HashMap<>(); //Read In Iterator<Content> iterator = readIn(); while(iterator.hasNext()){ Content content = iterator.next(); if(hashMap.containsKey(content.getLocationId())){} } } public static void main(String[] args){ schedule(); } private static Iterator<Content> readIn() { return null; } }
相关文章推荐
- 关于导出android项目的keystore问题
- Database Link的使用
- Mybatis关于like的字符串模糊处理
- volatile 和 explicit 的作用
- centos 7.0 安装nginx 1.9.10
- 文章标题
- [LeetCode]74. Search a 2D Matrix
- DELPHI语法基础学习笔记-Windows 句柄、回调函数、函数重载等(Delphi中很少需要直接使用句柄,因为句柄藏在窗体、 位图及其他Delphi 对象的内部)
- Android studio获取数字签名
- Master HA彻底解密
- 第十四天
- Delphi体系内部的4种消息传递办法(Send,Post,Perform,Dispatch)
- VS2013下socket新函数代替旧函数引起的编译错误
- cf#AIM Tech Round -B. Making a String-贪心/set
- 我会的东西
- HDU 1029 Ignatius and the Princess IV
- 只用两变量实现两者数据的交换
- 基本算法——第九单元 递推
- 数据结构基础之串
- Intent的两种跳转方式