forked from I2P_Developers/i2p.i2p
susimail:
- Generics in Folder - for each - type arguments
This commit is contained in:
@@ -41,7 +41,7 @@ import java.util.Iterator;
|
||||
*
|
||||
* @author susi
|
||||
*/
|
||||
public class Folder {
|
||||
public class Folder<O extends Object> {
|
||||
|
||||
public static final String PAGESIZE = "pager.pagesize";
|
||||
public static final int DEFAULT_PAGESIZE = 10;
|
||||
@@ -50,10 +50,10 @@ public class Folder {
|
||||
public static final boolean UP = true;
|
||||
|
||||
private int pages, pageSize, currentPage;
|
||||
private Object[] unsortedElements, elements;
|
||||
private Hashtable sorter;
|
||||
private O[] unsortedElements, elements;
|
||||
private Hashtable<String, Comparator<O>> sorter;
|
||||
private boolean sortingDirection;
|
||||
Comparator currentSorter;
|
||||
Comparator<O> currentSorter;
|
||||
|
||||
public Folder()
|
||||
{
|
||||
@@ -61,7 +61,7 @@ public class Folder {
|
||||
pageSize = 0;
|
||||
currentPage = 1;
|
||||
unsortedElements = null;
|
||||
sorter = new Hashtable();
|
||||
sorter = new Hashtable<String, Comparator<O>>();
|
||||
sortingDirection = UP;
|
||||
currentSorter = null;
|
||||
}
|
||||
@@ -129,12 +129,13 @@ public class Folder {
|
||||
* @param source Array to copy.
|
||||
* @return Copy of source.
|
||||
*/
|
||||
private Object[] copyArray( Object[] source )
|
||||
@SuppressWarnings("unchecked")
|
||||
private O[] copyArray( O[] source )
|
||||
{
|
||||
Object[] destination = new Object[source.length];
|
||||
for( int i = 0; i < source.length; i++ )
|
||||
destination[i] = source[i];
|
||||
return destination;
|
||||
return (O[])destination;
|
||||
}
|
||||
/**
|
||||
* Recalculates variables.
|
||||
@@ -171,9 +172,9 @@ public class Folder {
|
||||
/**
|
||||
* Set the array of objects the folder should manage.
|
||||
*
|
||||
* @param elements Array of Objects.
|
||||
* @param elements Array of Os.
|
||||
*/
|
||||
public void setElements( Object[] elements )
|
||||
public void setElements( O[] elements )
|
||||
{
|
||||
this.unsortedElements = elements;
|
||||
if( currentSorter != null )
|
||||
@@ -187,9 +188,9 @@ public class Folder {
|
||||
* Returns an iterator containing the elements on the current page.
|
||||
* @return Iterator containing the elements on the current page.
|
||||
*/
|
||||
public Iterator currentPageIterator()
|
||||
public Iterator<O> currentPageIterator()
|
||||
{
|
||||
ArrayList list = new ArrayList();
|
||||
ArrayList<O> list = new ArrayList<O>();
|
||||
if( elements != null ) {
|
||||
int pageSize = getPageSize();
|
||||
int offset = ( currentPage - 1 ) * pageSize;
|
||||
@@ -249,7 +250,7 @@ public class Folder {
|
||||
* @param id ID to identify the Comparator with @link sortBy()
|
||||
* @param sorter a Comparator to sort the Array given by @link setElements()
|
||||
*/
|
||||
public void addSorter( String id, Comparator sorter )
|
||||
public void addSorter( String id, Comparator<O> sorter )
|
||||
{
|
||||
this.sorter.put( id, sorter );
|
||||
}
|
||||
@@ -263,7 +264,7 @@ public class Folder {
|
||||
*/
|
||||
public void sortBy( String id )
|
||||
{
|
||||
currentSorter = (Comparator)sorter.get( id );
|
||||
currentSorter = sorter.get( id );
|
||||
sort();
|
||||
}
|
||||
|
||||
@@ -273,9 +274,9 @@ public class Folder {
|
||||
* @param x Position of the element on the current page.
|
||||
* @return Element on the current page on the given position.
|
||||
*/
|
||||
public Object getElementAtPosXonCurrentPage( int x )
|
||||
public O getElementAtPosXonCurrentPage( int x )
|
||||
{
|
||||
Object result = null;
|
||||
O result = null;
|
||||
if( elements != null ) {
|
||||
int pageSize = getPageSize();
|
||||
int offset = ( currentPage - 1 ) * pageSize;
|
||||
@@ -306,7 +307,7 @@ public class Folder {
|
||||
*
|
||||
* @return First element.
|
||||
*/
|
||||
public Object getFirstElement()
|
||||
public O getFirstElement()
|
||||
{
|
||||
/*
|
||||
* sorting direction is taken into account from getElement
|
||||
@@ -319,7 +320,7 @@ public class Folder {
|
||||
*
|
||||
* @return Last element.
|
||||
*/
|
||||
public Object getLastElement()
|
||||
public O getLastElement()
|
||||
{
|
||||
/*
|
||||
* sorting direction is taken into account from getElement
|
||||
@@ -333,7 +334,7 @@ public class Folder {
|
||||
* @param element
|
||||
* @return index
|
||||
*/
|
||||
private int getIndexOf( Object element )
|
||||
private int getIndexOf( O element )
|
||||
{
|
||||
if( elements != null ) {
|
||||
for( int i = 0; i < elements.length; i++ )
|
||||
@@ -350,9 +351,9 @@ public class Folder {
|
||||
* @param element
|
||||
* @return The next element
|
||||
*/
|
||||
public Object getNextElement( Object element )
|
||||
public O getNextElement( O element )
|
||||
{
|
||||
Object result = null;
|
||||
O result = null;
|
||||
|
||||
int i = getIndexOf( element );
|
||||
|
||||
@@ -371,9 +372,9 @@ public class Folder {
|
||||
* @param element
|
||||
* @return The previous element
|
||||
*/
|
||||
public Object getPreviousElement( Object element )
|
||||
public O getPreviousElement( O element )
|
||||
{
|
||||
Object result = null;
|
||||
O result = null;
|
||||
|
||||
int i = getIndexOf( element );
|
||||
|
||||
@@ -390,9 +391,9 @@ public class Folder {
|
||||
* @param i
|
||||
* @return Element at index i
|
||||
*/
|
||||
private Object getElement( int i )
|
||||
private O getElement( int i )
|
||||
{
|
||||
Object result = null;
|
||||
O result = null;
|
||||
|
||||
if( elements != null ) {
|
||||
if( sortingDirection == DOWN )
|
||||
@@ -424,7 +425,7 @@ public class Folder {
|
||||
*
|
||||
* @param element
|
||||
*/
|
||||
public boolean isLastElement( Object element )
|
||||
public boolean isLastElement( O element )
|
||||
{
|
||||
if( elements == null )
|
||||
return false;
|
||||
@@ -437,7 +438,7 @@ public class Folder {
|
||||
*
|
||||
* @param element
|
||||
*/
|
||||
public boolean isFirstElement( Object element )
|
||||
public boolean isFirstElement( O element )
|
||||
{
|
||||
if( elements == null )
|
||||
return false;
|
||||
|
@@ -49,7 +49,6 @@ import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Locale;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
@@ -316,7 +315,7 @@ public class WebMail extends HttpServlet
|
||||
int state, smtpPort;
|
||||
POP3MailBox mailbox;
|
||||
MailCache mailCache;
|
||||
Folder folder;
|
||||
Folder<String> folder;
|
||||
String user, pass, host, error, info;
|
||||
String replyTo, replyCC;
|
||||
String subject, body, showUIDL;
|
||||
@@ -413,8 +412,7 @@ public class WebMail extends HttpServlet
|
||||
if( mailPart.multipart ) {
|
||||
if( mailPart.type.compareTo( "multipart/alternative" ) == 0 ) {
|
||||
MailPart chosen = null;
|
||||
for( ListIterator li = mailPart.parts.listIterator(); li.hasNext(); ) {
|
||||
MailPart subPart = (MailPart)li.next();
|
||||
for( MailPart subPart : mailPart.parts ) {
|
||||
if( subPart.type != null && subPart.type.compareTo( "text/plain" ) == 0 )
|
||||
chosen = subPart;
|
||||
}
|
||||
@@ -423,16 +421,12 @@ public class WebMail extends HttpServlet
|
||||
return;
|
||||
}
|
||||
}
|
||||
for( ListIterator li = mailPart.parts.listIterator(); li.hasNext(); ) {
|
||||
MailPart part = (MailPart)li.next();
|
||||
for( MailPart part : mailPart.parts )
|
||||
showPart( out, part, level + 1, html );
|
||||
}
|
||||
}
|
||||
else if( mailPart.message ) {
|
||||
for( ListIterator li = mailPart.parts.listIterator(); li.hasNext(); ) {
|
||||
MailPart part = (MailPart)li.next();
|
||||
for( MailPart part : mailPart.parts )
|
||||
showPart( out, part, level + 1, html );
|
||||
}
|
||||
}
|
||||
else {
|
||||
boolean showBody = false;
|
||||
@@ -627,7 +621,7 @@ public class WebMail extends HttpServlet
|
||||
sessionObject.smtpPort = smtpPortNo;
|
||||
sessionObject.state = STATE_LIST;
|
||||
sessionObject.mailCache = new MailCache( sessionObject.mailbox );
|
||||
sessionObject.folder = new Folder();
|
||||
sessionObject.folder = new Folder<String>();
|
||||
sessionObject.folder.setElements( sessionObject.mailbox.getUIDLs() );
|
||||
sessionObject.folder.addSorter( SORT_ID, new IDSorter( sessionObject.mailCache ) );
|
||||
sessionObject.folder.addSorter( SORT_SENDER, new SenderSorter( sessionObject.mailCache ) );
|
||||
@@ -1052,8 +1046,8 @@ public class WebMail extends HttpServlet
|
||||
return part;
|
||||
|
||||
if( part.multipart || part.message ) {
|
||||
for( Iterator it = part.parts.iterator(); it.hasNext(); ) {
|
||||
MailPart subPart = getMailPartFromHashCode( (MailPart)it.next(), hashCode );
|
||||
for( MailPart p : part.parts ) {
|
||||
MailPart subPart = getMailPartFromHashCode( p, hashCode );
|
||||
if( subPart != null )
|
||||
return subPart;
|
||||
}
|
||||
@@ -1275,7 +1269,7 @@ public class WebMail extends HttpServlet
|
||||
|
||||
if( sessionObject.state == STATE_LIST ) {
|
||||
processFolderButtons( sessionObject, request );
|
||||
for( Iterator it = sessionObject.folder.currentPageIterator(); it != null && it.hasNext(); ) {
|
||||
for( Iterator<String> it = sessionObject.folder.currentPageIterator(); it != null && it.hasNext(); ) {
|
||||
String uidl = (String)it.next();
|
||||
Mail mail = sessionObject.mailCache.getMail( uidl, MailCache.FETCH_HEADER );
|
||||
if( mail != null && mail.error.length() > 0 ) {
|
||||
@@ -1520,8 +1514,7 @@ public class WebMail extends HttpServlet
|
||||
}
|
||||
|
||||
if( multipart ) {
|
||||
for( Iterator it = sessionObject.attachments.iterator(); it.hasNext(); ) {
|
||||
Attachment attachment = (Attachment)it.next();
|
||||
for( Attachment attachment : sessionObject.attachments ) {
|
||||
body.append( "\r\n--" + boundary + "\r\nContent-type: " + attachment.getContentType() + "\r\nContent-Disposition: attachment; filename=\"" + attachment.getFileName() + "\"\r\nContent-Transfer-Encoding: " + attachment.getTransferEncoding() + "\r\n\r\n" );
|
||||
body.append( attachment.getData() );
|
||||
}
|
||||
@@ -1615,12 +1608,11 @@ public class WebMail extends HttpServlet
|
||||
|
||||
if( sessionObject.attachments != null && !sessionObject.attachments.isEmpty() ) {
|
||||
boolean wroteHeader = false;
|
||||
for( Iterator it = sessionObject.attachments.iterator(); it.hasNext(); ) {
|
||||
for( Attachment attachment : sessionObject.attachments ) {
|
||||
if( !wroteHeader ) {
|
||||
out.println( "<tr><td colspan=\"2\" align=\"center\">" + _("Attachments:") + "</td></tr>" );
|
||||
wroteHeader = true;
|
||||
}
|
||||
Attachment attachment = (Attachment)it.next();
|
||||
out.println( "<tr><td colspan=\"2\" align=\"center\"><input type=\"checkbox\" class=\"optbox\" name=\"check" + attachment.hashCode() + "\" value=\"1\"> " + attachment.getFileName() + "</td></tr>");
|
||||
}
|
||||
}
|
||||
@@ -1682,7 +1674,7 @@ public class WebMail extends HttpServlet
|
||||
thSpacer + "<th>" + sortHeader( SORT_SIZE, _("Size"), sessionObject.imgPath ) + "</th></tr>" );
|
||||
int bg = 0;
|
||||
int i = 0;
|
||||
for( Iterator it = sessionObject.folder.currentPageIterator(); it != null && it.hasNext(); ) {
|
||||
for( Iterator<String> it = sessionObject.folder.currentPageIterator(); it != null && it.hasNext(); ) {
|
||||
String uidl = (String)it.next();
|
||||
Mail mail = sessionObject.mailCache.getMail( uidl, MailCache.FETCH_HEADER );
|
||||
String link = "<a href=\"" + myself + "?" + SHOW + "=" + i + "\">";
|
||||
|
@@ -59,8 +59,6 @@ public class POP3MailBox {
|
||||
|
||||
private Object synchronizer = null;
|
||||
|
||||
private Object[] uidls = null;
|
||||
|
||||
/**
|
||||
* @param host
|
||||
* @param port
|
||||
@@ -275,7 +273,6 @@ public class POP3MailBox {
|
||||
|
||||
uidlToID.clear();
|
||||
uidlList.clear();
|
||||
uidls = null;
|
||||
|
||||
readBuffer = sendCmdNa( "UIDL", DEFAULT_BUFSIZE );
|
||||
if( readBuffer != null ) {
|
||||
@@ -295,7 +292,6 @@ public class POP3MailBox {
|
||||
}
|
||||
}
|
||||
}
|
||||
uidls = uidlList.toArray();
|
||||
}
|
||||
else {
|
||||
System.err.println( "Error getting UIDL list from pop3 server.");
|
||||
@@ -350,7 +346,6 @@ public class POP3MailBox {
|
||||
uidlList.clear();
|
||||
uidlToID.clear();
|
||||
sizes.clear();
|
||||
uidls = null;
|
||||
mails = 0;
|
||||
}
|
||||
/**
|
||||
@@ -649,7 +644,7 @@ public class POP3MailBox {
|
||||
private int getIDfromUIDL( String uidl )
|
||||
{
|
||||
int result = -1;
|
||||
Integer intObject = (Integer)uidlToID.get( uidl );
|
||||
Integer intObject = uidlToID.get( uidl );
|
||||
if( intObject != null ) {
|
||||
result = intObject.intValue();
|
||||
}
|
||||
@@ -662,15 +657,15 @@ public class POP3MailBox {
|
||||
*/
|
||||
public String getUIDLfromID( int id )
|
||||
{
|
||||
return (String)uidlList.get( id );
|
||||
return uidlList.get( id );
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return A list of the available UIDLs.
|
||||
*/
|
||||
public Object[] getUIDLs()
|
||||
public String[] getUIDLs()
|
||||
{
|
||||
return uidls;
|
||||
return uidlList.toArray(new String[uidlList.size()]);
|
||||
}
|
||||
/**
|
||||
*
|
||||
|
Reference in New Issue
Block a user