com.facebook.widget.SimpleGraphObjectCursor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of facebook-android-api Show documentation
Show all versions of facebook-android-api Show documentation
The Mavenized Facebook Android api available in Maven Central repo.
/**
* Copyright 2010-present Facebook.
*
* 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.facebook.widget;
import android.database.CursorIndexOutOfBoundsException;
import com.facebook.model.GraphObject;
import java.util.ArrayList;
import java.util.Collection;
class SimpleGraphObjectCursor implements GraphObjectCursor {
private int pos = -1;
private boolean closed = false;
private ArrayList graphObjects = new ArrayList();
private boolean moreObjectsAvailable = false;
private boolean fromCache = false;
SimpleGraphObjectCursor() {
}
SimpleGraphObjectCursor(SimpleGraphObjectCursor other) {
pos = other.pos;
closed = other.closed;
graphObjects = new ArrayList();
graphObjects.addAll(other.graphObjects);
fromCache = other.fromCache;
// We do not copy observers.
}
public void addGraphObjects(Collection graphObjects, boolean fromCache) {
this.graphObjects.addAll(graphObjects);
// We consider this cached if ANY results were from the cache.
this.fromCache |= fromCache;
}
public boolean isFromCache() {
return fromCache;
}
public void setFromCache(boolean fromCache) {
this.fromCache = fromCache;
}
public boolean areMoreObjectsAvailable() {
return moreObjectsAvailable;
}
public void setMoreObjectsAvailable(boolean moreObjectsAvailable) {
this.moreObjectsAvailable = moreObjectsAvailable;
}
@Override
public int getCount() {
return graphObjects.size();
}
@Override
public int getPosition() {
return pos;
}
@Override
public boolean move(int offset) {
return moveToPosition(pos + offset);
}
@Override
public boolean moveToPosition(int position) {
final int count = getCount();
if (position >= count) {
pos = count;
return false;
}
if (position < 0) {
pos = -1;
return false;
}
pos = position;
return true;
}
@Override
public boolean moveToFirst() {
return moveToPosition(0);
}
@Override
public boolean moveToLast() {
return moveToPosition(getCount() - 1);
}
@Override
public boolean moveToNext() {
return moveToPosition(pos + 1);
}
@Override
public boolean moveToPrevious() {
return moveToPosition(pos - 1);
}
@Override
public boolean isFirst() {
return (pos == 0) && (getCount() != 0);
}
@Override
public boolean isLast() {
final int count = getCount();
return (pos == (count - 1)) && (count != 0);
}
@Override
public boolean isBeforeFirst() {
return (getCount() == 0) || (pos == -1);
}
@Override
public boolean isAfterLast() {
final int count = getCount();
return (count == 0) || (pos == count);
}
@Override
public T getGraphObject() {
if (pos < 0) {
throw new CursorIndexOutOfBoundsException("Before first object.");
}
if (pos >= graphObjects.size()) {
throw new CursorIndexOutOfBoundsException("After last object.");
}
return graphObjects.get(pos);
}
@Override
public void close() {
closed = true;
}
@Override
public boolean isClosed() {
return closed;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy