KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > lucene > MailRecord


1 /*
2   Copyright (C) 2003 Know Gate S.L. All rights reserved.
3                       C/Oņa, 107 1š2 28050 Madrid (Spain)
4
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions
7   are met:
8
9   1. Redistributions of source code must retain the above copyright
10      notice, this list of conditions and the following disclaimer.
11
12   2. The end-user documentation included with the redistribution,
13      if any, must include the following acknowledgment:
14      "This product includes software parts from hipergate
15      (http://www.hipergate.org/)."
16      Alternately, this acknowledgment may appear in the software itself,
17      if and wherever such third-party acknowledgments normally appear.
18
19   3. The name hipergate must not be used to endorse or promote products
20      derived from this software without prior written permission.
21      Products derived from this software may not be called hipergate,
22      nor may hipergate appear in their name, without prior written
23      permission.
24
25   This library is distributed in the hope that it will be useful,
26   but WITHOUT ANY WARRANTY; without even the implied warranty of
27   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28
29   You should have received a copy of hipergate License with this code;
30   if not, visit http://www.hipergate.org or mail to info@hipergate.org
31 */

32
33 package com.knowgate.lucene;
34
35 import java.util.Date JavaDoc;
36 import java.util.Comparator JavaDoc;
37 import java.text.SimpleDateFormat JavaDoc;
38
39 /**
40  * @author Sergio Montoro Ten
41  * @version 3.0
42  */

43 public class MailRecord {
44
45   public static class CompareAuthor implements Comparator JavaDoc {
46     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
47       if (((MailRecord)o1).getAuthor()==null) return -1;
48       return ((MailRecord)o1).getAuthor().compareTo(((MailRecord)o2).getAuthor());
49     }
50   }
51
52   public static class CompareSubject implements Comparator JavaDoc {
53     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
54       if (((MailRecord)o1).getSubject()==null) return -1;
55       return ((MailRecord)o1).getSubject().compareTo(((MailRecord)o2).getSubject());
56     }
57   }
58
59   public static class CompareDateSent implements Comparator JavaDoc {
60     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
61       if (((MailRecord)o1).getDateSent()==null) return -1;
62       return ((MailRecord)o1).getDateSent().compareTo(((MailRecord)o2).getDateSent());
63     }
64   }
65
66   public static class CompareSize implements Comparator JavaDoc {
67     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
68       return ((MailRecord)o1).getSize() - ((MailRecord)o2).getSize();
69     }
70   }
71
72   public static class CompareFolder implements Comparator JavaDoc {
73     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
74       if (((MailRecord)o1).getFolderName()==null) return -1;
75       return ((MailRecord)o1).getFolderName().compareTo(((MailRecord)o2).getFolderName());
76     }
77   }
78
79   private static SimpleDateFormat JavaDoc fmt = new SimpleDateFormat JavaDoc("yyyy-MM-dd HH:mm:ss");
80   private String JavaDoc guid;
81   private String JavaDoc subject;
82   private String JavaDoc author;
83   private String JavaDoc size;
84   private String JavaDoc number;
85   private String JavaDoc folder;
86   private Date JavaDoc created;
87
88   public MailRecord() { }
89
90   public MailRecord(String JavaDoc sGuid, String JavaDoc sSubject, String JavaDoc sAuthor, String JavaDoc sDate,
91                     String JavaDoc sSize, String JavaDoc sNumber, String JavaDoc sFolder) {
92     guid = sGuid;
93     subject = sSubject;
94     author = sAuthor;
95     try { created = fmt.parse(sDate); } catch (Exception JavaDoc ignore) {}
96     size = sSize;
97     number = sNumber;
98     folder = sFolder;
99   }
100
101   public String JavaDoc getFolderName() {
102     return folder;
103   }
104
105   public Date JavaDoc getDateSent() {
106     return created;
107   }
108
109   public int getNumber() throws NumberFormatException JavaDoc{
110     return Integer.parseInt(number);
111   }
112
113   public int getSize() throws NumberFormatException JavaDoc{
114     return Integer.parseInt(size);
115   }
116
117   public String JavaDoc getGuid() {
118     return guid;
119   }
120
121   public String JavaDoc getSubject() {
122     return subject;
123   }
124
125   public String JavaDoc getAuthor() {
126     return author;
127   }
128
129   public Date JavaDoc getDateCreated() {
130     return created;
131   }
132
133   public String JavaDoc getDateCreatedAsString() {
134     return fmt.format(created);
135   }
136
137   public void setFolderName(String JavaDoc sFolderName) {
138     folder = sFolderName;
139   }
140
141   public void setGuid(String JavaDoc sGuid) {
142     guid = sGuid;
143   }
144
145   public void setSubject(String JavaDoc sSubject) {
146     subject = sSubject;
147   }
148
149   public void setAuthor(String JavaDoc sAuthor) {
150     author = sAuthor;
151   }
152
153   public void setDateCreated(Date JavaDoc oDtCreated) {
154     created = oDtCreated;
155   }
156 }
157
Popular Tags