org.gstreamer.GstIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gstreamer-java Show documentation
Show all versions of gstreamer-java Show documentation
Java binding for the Gstreamer framework
/*
* Copyright (c) 2009 Levente Farkas
* Copyright (c) 2007 Wayne Meissner
*
* This file is part of gstreamer-java.
*
* This code is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3 only, as
* published by the Free Software Foundation.
*
* This code 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 Lesser General Public License
* version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with this work. If not, see .
*/
package org.gstreamer;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.gstreamer.lowlevel.GstNative;
import org.gstreamer.lowlevel.NativeObject;
import org.gstreamer.lowlevel.GstIteratorAPI;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.PointerByReference;
/**
*
*/
class GstIterator extends NativeObject implements java.lang.Iterable {
private static final GstIteratorAPI gst = GstNative.load(GstIteratorAPI.class);
private Class objectType;
GstIterator(Pointer ptr, Class cls) {
super(initializer(ptr));
objectType = cls;
}
public Iterator iterator() {
return new IteratorImpl();
}
protected void disposeNativeHandle(Pointer ptr) {
gst.gst_iterator_free(ptr);
}
public List asList() {
List list = new LinkedList();
for (java.util.Iterator it = iterator(); it.hasNext(); ) {
list.add(it.next());
}
return Collections.unmodifiableList(list);
}
class IteratorImpl implements java.util.Iterator {
T next;
IteratorImpl() {
next = getNext();
}
private T getNext() {
PointerByReference nextRef = new PointerByReference();
if (gst.gst_iterator_next(handle(), nextRef) == 1) {
return NativeObject.objectFor(nextRef.getValue(), objectType, false);
}
return null;
}
public boolean hasNext() {
return next != null;
}
public T next() {
T result = next;
next = getNext();
return result;
}
public void remove() {
throw new UnsupportedOperationException("Items cannot be removed.");
}
}
}