| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 459 人关注过本帖
标题:关于在事件处理系统中排序的问题求教,急!
取消只看楼主 加入收藏
secular12345
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-9-2
收藏
 问题点数:0 回复次数:1 
关于在事件处理系统中排序的问题求教,急!

一、 现有一事件处理系统,事件的数据结构如下:

package com.cyaline;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Event {

/**
* Event ID, uniquly identify the event in the system
*/
private int id;

/**
* Name of the event.
*/
private String name;

/**
* Description of the event;
*/
private String description;

/**
* Time in milliseconds of the event
*/
private long time;

private Priority priority;

public enum Priority {
Critical, Warning, Information
}

public String toString(){
StringBuffer sb = new StringBuffer();
sb.append("ID:").append(id).append("\n");
sb.append("Name:").append(name).append("\n");
sb.append("Description:").append(description).append("\n");
sb.append("Time:").append(time).append("\n");
sb.append("Priority:").append(priority).append("\n");
return sb.toString();
}

/**
* If the event.time is equal, then return the most recent events in its
* priority order.
*
* @param events
* @return
*/
public static Event[] findMostRecentEvent(List<Event> events) {

//TODO:找出最近的事件,如果有多个最近的事件(事件时间相同),则按照优先度的重要性排序由高到低次序返回).

}

public static void main(String[] args) {

List<Event> events = new ArrayList<Event>();

{
Event event = new Event();
event.id = 1;
event.name = "PrinterError";
event.description = "Shortage of paper";
event.time = System.currentTimeMillis() - 2000000;
event.priority = Priority.Warning;
events.add(event);
}

{
Event event = new Event();
event.id = 2;
event.name = "DeviceMaintenance";
event.description = "Device is out of service now.";
event.time = System.currentTimeMillis() - 1000000;
event.priority = Priority.Information;
events.add(event);
}

{
Event event = new Event();
event.id = 3;
event.name = "DeviceError";
event.description = "Device is not connected.";
event.time = System.currentTimeMillis() - 1000000;
event.priority = Priority.Critical;
events.add(event);
}

{
Event event = new Event();
event.id = 4;
event.name = "DeviceBusy";
event.description = "Device is busy.";
event.time = System.currentTimeMillis() - 1000000;
event.priority = Priority.Warning;
events.add(event);
}

{
Event event = new Event();
event.id = 6;
event.name = "PrinterError";
event.description = "Shortage of paper";
event.time = System.currentTimeMillis() - 1500000;
event.priority = Priority.Warning;
events.add(event);
}

Event[] evs = Event.findMostRecentEvent(events);

for(Event event:evs){
System.out.println(event);
}
}
}

搜索更多相关主题的帖子: 系统 
2007-09-02 09:57
secular12345
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-9-2
收藏
得分:0 
请问如何来处理这个函数?
2007-09-02 10:19
快速回复:关于在事件处理系统中排序的问题求教,急!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016531 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved