Example usage for java.util AbstractList AbstractList

List of usage examples for java.util AbstractList AbstractList

Introduction

In this page you can find the example usage for java.util AbstractList AbstractList.

Prototype

protected AbstractList() 

Source Link

Document

Sole constructor.

Usage

From source file:Main.java

static List<Node> listOf(final NodeList nodeList) {
    return new AbstractList<Node>() {
        public Node get(int index) {
            return nodeList.item(index);
        }/*from w ww  .  j  a  v  a  2s  . com*/

        public int size() {
            return nodeList.getLength();
        }
    };
}

From source file:Main.java

/**
 * takes a float array and returns a List of Float backed by the array
 * @param a// w ww  .  j  a  v  a 2  s  .  co  m
 * @return
 */
public static List<Float> asList(final float[] a) {
    return new AbstractList<Float>() {
        public Float get(int i) {
            return a[i];
        }

        // Throws NullPointerException if val == null
        public Float set(int i, Integer val) {
            Float oldVal = a[i];
            a[i] = val;
            return oldVal;
        }

        public int size() {
            return a.length;
        }
    };
}

From source file:Main.java

/**
 * Creates and returns an unmodifiable List that wraps the given array.
 * Changes to the array will be reflected in the List.
 * @param arr The array to wrap as a List
 * @param fillValue The value to use in place of Float.NaNs
 * @return an unmodifiable List that wraps the array
 * @throws NullPointerException if the array is null
 *///from  ww w.j a  va2  s.c  om
public static List<Float> listFromFloatArray(final float[] arr, final Float fillValue) {
    if (arr == null)
        throw new NullPointerException("array cannot be null");
    return new AbstractList<Float>() {
        @Override
        public Float get(int index) {
            float val = arr[index];
            if (Float.isNaN(val)) {
                return fillValue;
            } else {
                return val;
            }
            //                return Float.isNaN(val) ? fillValue : val;
        }

        @Override
        public int size() {
            return arr.length;
        }
    };
}

From source file:com.vaadin.framework8.demo.restjson.RestDataProvider.java

/**
 * Creates a stream from a JSON array.//from  w w w  .  j a  v a 2s .  c  om
 *
 * @param array
 *            the JSON array to create a stream from
 * @return a stream of JSON values
 */
private static <T extends JsonValue> Stream<T> stream(JsonArray array) {
    assert array != null;
    return new AbstractList<T>() {
        @Override
        public T get(int index) {
            return array.get(index);
        }

        @Override
        public int size() {
            return array.length();
        }
    }.stream();
}

From source file:net.ontopia.topicmaps.rest.v1.topicmap.SearcherResource.java

@Post
public List<Map<String, Object>> search(String value) throws IOException {

    if (StringUtils.isEmpty(value)) {
        throw OntopiaRestErrors.MANDATORY_ATTRIBUTE_IS_NULL.build("value", "String");
    }// w  w  w  .j a  va2  s  .com

    final TopicMapIF tm = getTopicMap();
    SearcherIF index = getIndex(SearcherIF.class);
    try {
        final SearchResultIF result = index.search(value);
        return new AbstractList<Map<String, Object>>() {
            @Override
            public Map<String, Object> get(int index) {
                try {
                    Map<String, Object> object = new HashMap<>();
                    object.put("object",
                            tm.getObjectById(result.getDocument(index).getField("object_id").getValue()));
                    object.put("class", result.getDocument(index).getField("class").getValue());
                    object.put("score", result.getScore(index));
                    return object;
                } catch (IOException e) {
                    throw OntopiaRestErrors.INDEX_USAGE_ERROR.build(e, "SearcherIF");
                }
            }

            @Override
            public int size() {
                try {
                    return result.hits();
                } catch (IOException e) {
                    throw OntopiaRestErrors.INDEX_USAGE_ERROR.build(e, "SearcherIF");
                }
            }
        };
    } catch (IOException e) {
        throw OntopiaRestErrors.INDEX_USAGE_ERROR.build(e, "SearcherIF");
    }
}

From source file:kindleclippings.quizlet.TermSet.java

public Collection<Term> getTerms() {
    try {/*from  w ww .  j a va  2s .  co  m*/
        final JSONArray terms = data.getJSONArray("terms");
        return new AbstractList<Term>() {

            @Override
            public Term get(int index) {
                try {
                    return new Term(terms.getJSONObject(index));
                } catch (JSONException e) {
                    throw new RuntimeException(e);
                }
            }

            @Override
            public int size() {
                return terms.length();
            }
        };
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:sf.net.experimaestro.manager.js.MethodFunction.java

@Override
protected Iterable<MethodDeclaration> declarations() {
    return Iterables.concat(new AbstractList<Iterable<MethodDeclaration>>() {
        @Override/*from  w w w .  j  a v  a  2 s .c o m*/
        public Iterable<MethodDeclaration> get(final int index) {
            Group group = groups.get(index);
            return Iterables.transform(group.methods, m -> new MethodDeclaration(group.thisObject, m));
        }

        @Override
        public int size() {
            return groups.size();
        }
    });
}

From source file:edu.dfci.cccb.mev.domain.MatrixData.java

/**
 * Gets the matrix values as a single dimmensional array row by row
 * //from  ww w  .j a v  a  2 s  . c  om
 * @return
 */
@JsonView
public List<Double> values() {
    return new AbstractList<Double>() {

        /* (non-Javadoc)
         * @see java.util.AbstractList#get(int) */
        @Override
        public Double get(int index) {
            if (data == null)
                throw new IndexOutOfBoundsException();
            try {
                return data.getEntry(index / data.getColumnDimension(), index % data.getColumnDimension());
            } catch (OutOfRangeException e) {
                throw new IndexOutOfBoundsException();
            }
        }

        /* (non-Javadoc)
         * @see java.util.AbstractCollection#size() */
        @Override
        public int size() {
            return data == null ? 0 : data.getColumnDimension() * data.getRowDimension();
        }
    };
}

From source file:edu.dfci.cccb.mev.stats.domain.cli.CliRWilcoxonBuilder.java

@SuppressWarnings("unchecked")
private List<Double> column(final String column) {
    return column != null ? new AbstractList<Double>() {

        @Override/*from  ww w  . j  a v a2s .c  o m*/
        @SneakyThrows(DatasetException.class)
        public Double get(int index) {
            return dataset().values().get(dataset().dimension(Type.ROW).keys().get(index), column);
        }

        @Override
        @SneakyThrows(InvalidDimensionTypeException.class)
        public int size() {
            return dataset().dimension(Type.ROW).keys().size();
        }
    } : ((List<Double>) Collections.EMPTY_LIST);
}

From source file:fr.free.movierenamer.utils.JSONUtils.java

private static List<JSONObject> jsonList(final Object array) {
    return new AbstractList<JSONObject>() {

        @Override/*from   w  ww . j a v  a2  s .  c  o m*/
        public JSONObject get(int index) {
            if (array == null)
                return null;
            return (JSONObject) ((JSONArray) array).get(index);
        }

        @Override
        public int size() {
            if (array == null)
                return 0;
            return ((JSONArray) array).size();
        }
    };
}