/*
 * LensKit, an open source recommender systems toolkit.
 * Copyright 2010-2013 Regents of the University of Minnesota and contributors
 * Work on LensKit has been funded by the National Science Foundation under
 * grants IIS 05-34939, 08-08692, 08-12148, and 10-17697.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
package org.grouplens.lenskit.data.dao.packed;

import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import org.grouplens.lenskit.data.event.Event;
import org.grouplens.lenskit.data.event.Rating;
import org.grouplens.lenskit.data.history.AbstractUserHistory;
import org.grouplens.lenskit.data.history.History;
import org.grouplens.lenskit.data.history.UserHistory;

/**
 * @author <a href="http://www.grouplens.org">GroupLens Research</a>
 */
public class BinaryUserHistory<E extends Event> extends AbstractUserHistory<Rating> {
    private final long userId;
    private final BinaryRatingList ratings;

    BinaryUserHistory(long user, BinaryRatingList rs) {
        userId = user;
        ratings = rs;
    }

    @Override
    public Rating get(int index) {
        return ratings.get(index);
    }

    @Override
    public int size() {
        return ratings.size();
    }

    @Override
    public long getUserId() {
        return userId;
    }

    @Override
    public <T extends Event> UserHistory<T> filter(Class<T> type) {
        if (type.isAssignableFrom(Rating.class)) {
            return (UserHistory<T>) this;
        } else {
            return History.forUser(userId);
        }
    }

    @Override
    public UserHistory<Rating> filter(Predicate<? super Rating> pred) {
        return History.forUser(userId, FluentIterable.from(ratings).filter(pred).toList());
    }
}

@@ -1136,16 +1136,73 @@
 erable;%0A
+import org.grouplens.lenskit.collections.FastCollection;%0A
 import o
@@ -1240,16 +1240,16 @@
 .Event;%0A
-
 import o
@@ -1458,16 +1458,44 @@
 story;%0A%0A
+import java.util.Iterator;%0A%0A
 /**%0A * @
@@ -1646,16 +1646,50 @@
 %3CRating%3E
+ implements FastCollection%3CRating%3E
  %7B%0A    p
@@ -2074,24 +2074,24 @@
 tUserId() %7B%0A
-
         retu
@@ -2100,32 +2100,234 @@
  userId;%0A    %7D%0A%0A
+    @Override%0A    public Iterator%3CRating%3E fastIterator() %7B%0A        return ratings.fastIterator();%0A    %7D%0A%0A    @Override%0A    public Iterator%3CRating%3E iterator() %7B%0A        return ratings.iterator();%0A    %7D%0A%0A
     @Override%0A  

Make binary user histories fast-iterable