Advertisement
Guest User

RawEvent.java

a guest
Sep 1st, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. package com.sample;
  2.  
  3. import java.text.DateFormat;
  4. import java.text.ParseException;
  5. import java.text.SimpleDateFormat;
  6. import java.util.Date;
  7. import java.util.regex.Matcher;
  8. import java.util.regex.Pattern;
  9.  
  10. public class RawEvent extends BasicEvent implements Comparable<RawEvent> {
  11.     Date    timestamp;
  12.     long    id;
  13.     Boolean test;
  14.     public Boolean getTest() {
  15.         return test;
  16.     }
  17.     public void setTest(Boolean test) {
  18.         this.test = test;
  19.     }
  20.     @Override
  21.     public Date getTimestamp() {
  22.         return timestamp;
  23.     }
  24.     @Override
  25.     public void setTimestamp(Date d) {
  26.         timestamp = d;
  27.     }
  28.     public long getId() {
  29.         return id;
  30.     }
  31.     public void setId(long id) {
  32.         this.id = id;
  33.     }
  34.     @Override
  35.     public String toString() {
  36.         DateFormat formatter = new SimpleDateFormat("yyyy MMM dd HH:mm:ss");
  37.         return "timestamp="+formatter.format(timestamp)+", test="+test+", id="+id;
  38.     }
  39.     @Override
  40.     public Boolean parse(String line) {
  41.         DateFormat formatter = new SimpleDateFormat("yyyy MMM dd HH:mm:ss");
  42.         Pattern pattern =
  43.             Pattern.compile("^timestamp=(.*), test=(.*), id=(.*)$");
  44.         Matcher matcher =
  45.             pattern.matcher(line);
  46.         if (!matcher.matches())
  47.             return false;
  48.         try {
  49.             setTimestamp(formatter.parse(matcher.group(1)));
  50.         } catch (ParseException e) {
  51.             // TODO Auto-generated catch block
  52.             e.printStackTrace();
  53.         }
  54.         setTest(matcher.group(2).equals("true"));
  55.         setId(Long.parseLong(matcher.group(3)));
  56.         return true;
  57.     }
  58.     @Override
  59.     public int compareTo(RawEvent o) {
  60.         return (int) (this.timestamp.getTime() - o.timestamp.getTime());
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement