Last active
July 4, 2019 17:01
-
-
Save dbremner/503118ecd17cb7773ef52d413ff52f0d to your computer and use it in GitHub Desktop.
Iterable from Swing ListModel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jetbrains.annotations.NotNull; | |
import javax.swing.ListModel; | |
import java.util.AbstractList; | |
public enum ListModels | |
{ | |
; | |
public static @NotNull <E> Iterable<E> asIterable(final @NotNull ListModel<E> model) | |
{ | |
return new ListModelList<>(model); | |
} | |
private static final class ListModelList<E> extends AbstractList<E> | |
{ | |
private final @NotNull ListModel<E> model; | |
ListModelList(final @NotNull ListModel<E> model) | |
{ | |
this.model = model; | |
} | |
@Override | |
public E get(final int index) | |
{ | |
return model.getElementAt(index); | |
} | |
@Override | |
public int size() | |
{ | |
return model.getSize(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment