001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.model.impl;
016    
017    import com.liferay.message.boards.kernel.model.MBMessage;
018    import com.liferay.message.boards.kernel.model.MBMessageIterator;
019    
020    import java.util.List;
021    
022    /**
023     * @author Sergio Gonz??lez
024     */
025    public class MBMessageIteratorImpl implements MBMessageIterator {
026    
027            public MBMessageIteratorImpl(List<MBMessage> messages, int from, int to) {
028                    _messages = messages;
029                    _from = from;
030                    _to = to;
031            }
032    
033            @Override
034            public int getIndexPage() {
035                    return _from;
036            }
037    
038            @Override
039            public boolean hasNext() {
040                    if (_from < _to) {
041                            return true;
042                    }
043    
044                    return false;
045            }
046    
047            @Override
048            public MBMessage next() {
049                    MBMessage message = _messages.get(_from);
050    
051                    _from++;
052    
053                    return message;
054            }
055    
056            @Override
057            public void remove() {
058                    throw new UnsupportedOperationException();
059            }
060    
061            private int _from;
062            private final List<MBMessage> _messages;
063            private final int _to;
064    
065    }