/*
 * Copyright 2018 The twicalico authors
 *
 * Licensed 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.github.moko256.mastodon;

import com.sys1yagi.mastodon4j.api.Pageable;
import com.sys1yagi.mastodon4j.api.entity.Account;

import java.util.ArrayList;

import twitter4j.PagableResponseList;
import twitter4j.RateLimitStatus;
import twitter4j.TwitterResponse;
import twitter4j.User;

/**
 * Created by moko256 on 2017/10/23.
 *
 * @author moko256
 */

public class MTPagableResponseList<E extends TwitterResponse> extends ArrayList<E> implements PagableResponseList<E> {
    Long previous;
    Long next;

    MTPagableResponseList(Pageable p){
        super();
        next = p.getLink().getMaxId();
        previous = p.getLink().getSinceId();
    }

    static MTPagableResponseList<User> convert(Pageable<Account> p){
        MTPagableResponseList<User> users = new MTPagableResponseList<>(p);
        for (Account a : p.getPart()) {
            users.add(new MTUser(a));
        }
        return users;
    }

    @Override
    public boolean hasPrevious() {
        return previous != null;
    }

    @Override
    public long getPreviousCursor() {
        return hasPrevious()? previous: -1;
    }

    @Override
    public boolean hasNext() {
        return next != null;
    }

    @Override
    public long getNextCursor() {
        return hasNext()? next: -1;
    }

    @Override
    public RateLimitStatus getRateLimitStatus() {
        return null;
    }

    @Override
    public int getAccessLevel() {
        return 0;
    }
}

@@ -1080,24 +1080,32 @@
 st%3CE%3E %7B%0A    
+private 
 Long previou
@@ -1111,16 +1111,24 @@
 us;%0A    
+private 
 Long nex
@@ -1183,24 +1183,63 @@
    super();%0A
+        if (p.getLink() != null) %7B%0A    
         next
@@ -1273,16 +1273,20 @@
         
+ 
+   
 previous
@@ -1310,24 +1310,34 @@
 tSinceId();%0A
+        %7D%0A
     %7D%0A%0A    s

fix bug cause NullPointerException