Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Arrays;
import java.util.Comparator;

import java.util.List;

import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;

public class Main {
    public static List<Message> getMessagesWithPage(Folder folder, int pageNum, int pageSize)
            throws MessagingException {
        Message[] messages = folder.getMessages();
        Arrays.sort(messages, new Comparator<Message>() {

            public int compare(Message o1, Message o2) {
                Message m1 = (Message) o1;
                Message m2 = (Message) o2;
                if (m1.getMessageNumber() > m2.getMessageNumber()) {
                    return -1;
                }
                return 1;
            }

        });
        List<Message> list = Arrays.asList(messages);
        int start = (pageNum - 1) * pageSize;
        int end = pageNum * pageSize;
        return list.subList(start, end);
    }
}