/*
 * Copyright 2010-2011 Ning, Inc.
 *
 * Ning licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.ning.billing.entitlement.api.user;

import java.util.LinkedList;
import java.util.UUID;

import com.ning.billing.entitlement.events.EntitlementEvent;

public class SubscriptionEvents {

    public static final long INITIAL_VERSION = 1;

    private final LinkedList<EntitlementEvent> events;

    private long activeVersion;

    public SubscriptionEvents(final UUID subscriptionId) {
        super();
        final UUID subscriptionId1 = subscriptionId;
        this.events = new LinkedList<EntitlementEvent>();
        this.activeVersion = INITIAL_VERSION;
    }

    public void addEvent(final EntitlementEvent ev) {
        events.add(ev);
    }

    public LinkedList<EntitlementEvent> getCurrentView() {
        return getViewForVersion(activeVersion);
    }

    public LinkedList<EntitlementEvent> getViewForVersion(final long version) {

        final LinkedList<EntitlementEvent> result = new LinkedList<EntitlementEvent>();
        for (final EntitlementEvent cur : events) {
            if (cur.getActiveVersion() == version) {
                result.add(cur);
            }
        }
        return result;
    }


    public long getActiveVersion() {
        return activeVersion;
    }

    public void setActiveVersion(final long activeVersion) {
        this.activeVersion = activeVersion;
    }
}

@@ -694,16 +694,39 @@
 edList;%0A
+import java.util.List;%0A
 import j
@@ -837,17 +837,16 @@
 vents %7B%0A
-%0A
     publ
@@ -902,30 +902,24 @@
 ivate final 
-Linked
 List%3CEntitle
@@ -1005,106 +1005,11 @@
 nts(
-final UUID subscriptionId) %7B%0A        super();%0A        final UUID subscriptionId1 = subscriptionId;
+) %7B
 %0A   
@@ -1204,38 +1204,32 @@
   %7D%0A%0A    public 
-Linked
 List%3CEntitlement
@@ -1321,22 +1321,16 @@
  public 
-Linked
 List%3CEnt
@@ -1384,17 +1384,16 @@
 sion) %7B%0A
-%0A
         
@@ -1626,32 +1626,33 @@
     %7D%0A        %7D%0A
+%0A
         return r
@@ -1665,17 +1665,16 @@
 %0A    %7D%0A%0A
-%0A
     publ
@@ -1849,11 +1849,1040 @@
 n;%0A    %7D
+%0A%0A    @Override%0A    public String toString() %7B%0A        final StringBuilder sb = new StringBuilder();%0A        sb.append(%22SubscriptionEvents%22);%0A        sb.append(%22%7BactiveVersion=%22).append(activeVersion);%0A        sb.append(%22, events=%22).append(events);%0A        sb.append('%7D');%0A        return sb.toString();%0A    %7D%0A%0A    @Override%0A    public boolean equals(final Object o) %7B%0A        if (this == o) %7B%0A            return true;%0A        %7D%0A        if (o == null %7C%7C getClass() != o.getClass()) %7B%0A            return false;%0A        %7D%0A%0A        final SubscriptionEvents that = (SubscriptionEvents) o;%0A%0A        if (activeVersion != that.activeVersion) %7B%0A            return false;%0A        %7D%0A        if (events != null ? !events.equals(that.events) : that.events != null) %7B%0A            return false;%0A        %7D%0A%0A        return true;%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        int result = events != null ? events.hashCode() : 0;%0A        result = 31 * result + (int) (activeVersion %5E (activeVersion %3E%3E%3E 32));%0A        return result;%0A    %7D
 %0A%7D%0A

update SubscriptionEvents to use List, not LinkedList