⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 event.java

📁 对Windows系统产生的非常巨大的日志文件进行分累统计并进行格式打印.手动去搜索统计某个或几个你所关心事件或内容几乎不太可能。
💻 JAVA
字号:
/**
 * 
 */
package logfileAnalyse;

import java.util.Comparator;

/**
 * @author Jack
 *
 */
public class Event implements Comparator<Event> {

	private String Event;
	private int count;
	
	public  int PRINT_MAX_LENGTH;
	
	/*
	 * no arguments constructor for Event
	 */
	public Event() {
		
		PRINT_MAX_LENGTH = 20;
		count = 0;
	}
	
	/**
	 * Stores a String type Event and sets initial number to 1.
     * 
     * @param event
     *           The event to store.
    */
	public Event(String event) {

		this();
		Event = event;
	    count = 1;
	    
	}
	
	/**
	 * @param event
	 * @param count
	 */
	public Event(String event, int count) {
		super();
		Event = event;
		this.count = count;
	}

	/* 
     * Provides a total ordering for the Event class.
     * 
     * @param event1
     *           the first Event in the comparison.
     * @param event2
     *           the second Event in the comparison.
     * @return a negative value if event1 is "less than" event2, 0 if they are
     *         equal. otherwise a positive value.

	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
	 */
	@Override
	public int compare(Event event1, Event event2) {

		int value = event2.count - event1.count;
		if (value == 0) {
			
			return event1.Event.compareTo(event2.Event);
		}
		return value;
	}

	/**
	 * @return the event
	 */
	public String getEvent() {
		return Event;
	}

	/**
	 * @param event the event to set
	 */
	public void setEvent(String event) {
		Event = event;
	}

	/**
	 * @return the count
	 */
	public int getCount() {
		return count;
	}

	/**
	 * @param count the count to set
	 */
	public void setCount(int count) {
		this.count = count;
	}

	/*
	 * Increment the number for the Event
	 */
	public void increment() {
		
		count++;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		
		StringBuffer strb = new StringBuffer();
		String s = " ";
		
		strb = new StringBuffer();
		strb.append(Event);
		for(int i = 0; i < (PRINT_MAX_LENGTH - Event.length() - Integer.toString(count).length()); i++)
			strb.append(s);
		strb.append(count);
		
		return new String(strb);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -