Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sample;
- import java.text.DateFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class RawEvent extends BasicEvent implements Comparable<RawEvent> {
- Date timestamp;
- long id;
- Boolean test;
- public Boolean getTest() {
- return test;
- }
- public void setTest(Boolean test) {
- this.test = test;
- }
- @Override
- public Date getTimestamp() {
- return timestamp;
- }
- @Override
- public void setTimestamp(Date d) {
- timestamp = d;
- }
- public long getId() {
- return id;
- }
- public void setId(long id) {
- this.id = id;
- }
- @Override
- public String toString() {
- DateFormat formatter = new SimpleDateFormat("yyyy MMM dd HH:mm:ss");
- return "timestamp="+formatter.format(timestamp)+", test="+test+", id="+id;
- }
- @Override
- public Boolean parse(String line) {
- DateFormat formatter = new SimpleDateFormat("yyyy MMM dd HH:mm:ss");
- Pattern pattern =
- Pattern.compile("^timestamp=(.*), test=(.*), id=(.*)$");
- Matcher matcher =
- pattern.matcher(line);
- if (!matcher.matches())
- return false;
- try {
- setTimestamp(formatter.parse(matcher.group(1)));
- } catch (ParseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- setTest(matcher.group(2).equals("true"));
- setId(Long.parseLong(matcher.group(3)));
- return true;
- }
- @Override
- public int compareTo(RawEvent o) {
- return (int) (this.timestamp.getTime() - o.timestamp.getTime());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement