001: /*
002: Copyright (C) 2003 Know Gate S.L. All rights reserved.
003: C/Oņa, 107 1š2 28050 Madrid (Spain)
004:
005: Redistribution and use in source and binary forms, with or without
006: modification, are permitted provided that the following conditions
007: are met:
008:
009: 1. Redistributions of source code must retain the above copyright
010: notice, this list of conditions and the following disclaimer.
011:
012: 2. The end-user documentation included with the redistribution,
013: if any, must include the following acknowledgment:
014: "This product includes software parts from hipergate
015: (http://www.hipergate.org/)."
016: Alternately, this acknowledgment may appear in the software itself,
017: if and wherever such third-party acknowledgments normally appear.
018:
019: 3. The name hipergate must not be used to endorse or promote products
020: derived from this software without prior written permission.
021: Products derived from this software may not be called hipergate,
022: nor may hipergate appear in their name, without prior written
023: permission.
024:
025: This library is distributed in the hope that it will be useful,
026: but WITHOUT ANY WARRANTY; without even the implied warranty of
027: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
028:
029: You should have received a copy of hipergate License with this code;
030: if not, visit http://www.hipergate.org or mail to info@hipergate.org
031: */
032:
033: package com.knowgate.lucene;
034:
035: import java.util.Date;
036: import java.util.Comparator;
037: import java.text.SimpleDateFormat;
038:
039: /**
040: * @author Sergio Montoro Ten
041: * @version 3.0
042: */
043: public class MailRecord {
044:
045: public static class CompareAuthor implements Comparator {
046: public int compare(Object o1, Object o2) {
047: if (((MailRecord) o1).getAuthor() == null)
048: return -1;
049: return ((MailRecord) o1).getAuthor().compareTo(
050: ((MailRecord) o2).getAuthor());
051: }
052: }
053:
054: public static class CompareSubject implements Comparator {
055: public int compare(Object o1, Object o2) {
056: if (((MailRecord) o1).getSubject() == null)
057: return -1;
058: return ((MailRecord) o1).getSubject().compareTo(
059: ((MailRecord) o2).getSubject());
060: }
061: }
062:
063: public static class CompareDateSent implements Comparator {
064: public int compare(Object o1, Object o2) {
065: if (((MailRecord) o1).getDateSent() == null)
066: return -1;
067: return ((MailRecord) o1).getDateSent().compareTo(
068: ((MailRecord) o2).getDateSent());
069: }
070: }
071:
072: public static class CompareSize implements Comparator {
073: public int compare(Object o1, Object o2) {
074: return ((MailRecord) o1).getSize()
075: - ((MailRecord) o2).getSize();
076: }
077: }
078:
079: public static class CompareFolder implements Comparator {
080: public int compare(Object o1, Object o2) {
081: if (((MailRecord) o1).getFolderName() == null)
082: return -1;
083: return ((MailRecord) o1).getFolderName().compareTo(
084: ((MailRecord) o2).getFolderName());
085: }
086: }
087:
088: private static SimpleDateFormat fmt = new SimpleDateFormat(
089: "yyyy-MM-dd HH:mm:ss");
090: private String guid;
091: private String subject;
092: private String author;
093: private String size;
094: private String number;
095: private String folder;
096: private Date created;
097:
098: public MailRecord() {
099: }
100:
101: public MailRecord(String sGuid, String sSubject, String sAuthor,
102: String sDate, String sSize, String sNumber, String sFolder) {
103: guid = sGuid;
104: subject = sSubject;
105: author = sAuthor;
106: try {
107: created = fmt.parse(sDate);
108: } catch (Exception ignore) {
109: }
110: size = sSize;
111: number = sNumber;
112: folder = sFolder;
113: }
114:
115: public String getFolderName() {
116: return folder;
117: }
118:
119: public Date getDateSent() {
120: return created;
121: }
122:
123: public int getNumber() throws NumberFormatException {
124: return Integer.parseInt(number);
125: }
126:
127: public int getSize() throws NumberFormatException {
128: return Integer.parseInt(size);
129: }
130:
131: public String getGuid() {
132: return guid;
133: }
134:
135: public String getSubject() {
136: return subject;
137: }
138:
139: public String getAuthor() {
140: return author;
141: }
142:
143: public Date getDateCreated() {
144: return created;
145: }
146:
147: public String getDateCreatedAsString() {
148: return fmt.format(created);
149: }
150:
151: public void setFolderName(String sFolderName) {
152: folder = sFolderName;
153: }
154:
155: public void setGuid(String sGuid) {
156: guid = sGuid;
157: }
158:
159: public void setSubject(String sSubject) {
160: subject = sSubject;
161: }
162:
163: public void setAuthor(String sAuthor) {
164: author = sAuthor;
165: }
166:
167: public void setDateCreated(Date oDtCreated) {
168: created = oDtCreated;
169: }
170: }
|