Flutter Engine
The Flutter Engine
ElementList.java
Go to the documentation of this file.
1package org.dartlang.vm.service.element;
2
3import com.google.gson.JsonArray;
4import com.google.gson.JsonObject;
5
6import java.util.Iterator;
7
8/**
9 * Simple wrapper around a {@link JsonArray} which lazily converts {@link JsonObject} elements to
10 * subclasses of {@link Element}. Subclasses need only implement {@link #basicGet(JsonArray, int)}
11 * to return an {@link Element} subclass for the {@link JsonObject} at a given index.
12 */
13public abstract class ElementList<T> implements Iterable<T> {
14
15 private final JsonArray array;
16
17 public ElementList(JsonArray array) {
18 this.array = array;
19 }
20
21 public T get(int index) {
22 return basicGet(array, index);
23 }
24
25 public boolean isEmpty() {
26 return size() == 0;
27 }
28
29 @Override
30 public Iterator<T> iterator() {
31 return new Iterator<T>() {
32 int index = 0;
33
34 @Override
35 public boolean hasNext() {
36 return index < size();
37 }
38
39 @Override
40 public T next() {
41 return get(index++);
42 }
43
44 @Override
45 public void remove() {
46 throw new UnsupportedOperationException();
47 }
48 };
49 }
50
51 public int size() {
52 return array.size();
53 }
54
55 protected abstract T basicGet(JsonArray array, int index);
56}
static float next(float f)
abstract T basicGet(JsonArray array, int index)
#define T
Definition: precompiler.cc:65