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

public static List<Node> listize(final NodeList list) {
    return new AbstractList<Node>() {
        public Node get(int i) {
            return list.item(i);
        }/* w  ww.j a v a2  s.c o  m*/

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

From source file:Main.java

public static List<Node> childrenAsList(Node node) {
    final NodeList children = node.getChildNodes();
    return new AbstractList<Node>() {

        @Override/*from   w w w .ja  va2 s  . c o m*/
        public Node get(int index) {
            return children.item(index);
        }

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

    };
}

From source file:Main.java

public static <T1, T2> List<T2> lazyMap(final List<T1> lst, final Function<T1, T2> mapper) {
    if (lst == null) {
        return null;
    }//from  w w  w .ja v a 2  s. c o m
    return new AbstractList<T2>() {
        @Override
        public T2 get(int index) {
            return mapper.apply(lst.get(index));
        }

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

From source file:Main.java

/**
 * takes an int array and returns a List of Integer backed by the array
 * @param a/*from  ww  w.  j  a v a2s.  c  om*/
 * @return
 */
public static List<Integer> asList(final int[] a) {
    return new AbstractList<Integer>() {
        public Integer get(int i) {
            return a[i];
        }

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

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

From source file:Main.java

public static <T> List<T> reversedView(final List<T> list) {
    return new AbstractList<T>() {
        @Override//from w ww  . ja v  a2s . com
        public T get(int index) {
            return list.get(list.size() - 1 - index);
        }

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

From source file:Main.java

public static List<Node> listize(final NamedNodeMap nnm) {
    return new AbstractList<Node>() {
        public Node get(int i) {
            return nnm.item(i);
        }//w  w w  .j  av a2s. c  o  m

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

    };
}

From source file:Main.java

/**
 * a very space+time effectvie way to construct a (read-only) List of a repeated value.
 *
 * @param value the value we want repreated in a list
 * @param times the size of the desired list
 * @return a list containing <code>value</code> <code>times</code> times.
 *///from  w  ww .  j a  v  a2 s .c om
public static <T> List<T> repeat(final T value, final int times) {
    return new AbstractList<T>() {
        public T get(int i) {
            return value;
        }

        public int size() {
            return times;
        }
    };
}

From source file:Main.java

/**
 * Make a Java List out of a DOM NodeList.
 *
 * @param nl/*from w  w w  . j  a  va2  s . c o m*/
 */
public static List<Node> nodeCollection(final NodeList nl) {
    return new AbstractList<Node>() {

        @Override
        public Node get(int index) {
            return nl.item(index);
        }

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

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
 * @return an unmodifiable List that wraps the array
 * @throws NullPointerException if the array is null
 *///from   www.j av a  2  s. co m
public static List<Double> listFromDoubleArray(final double[] arr) {
    if (arr == null)
        throw new NullPointerException("array cannot be null");
    return new AbstractList<Double>() {
        @Override
        public Double get(int index) {
            return arr[index];
        }

        @Override
        public int size() {
            return arr.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
 * @return an unmodifiable List that wraps the array
 * @throws NullPointerException if the array is null
 *//*from   www . jav a  2s  . c  o m*/
public static List<Float> listFromFloatArray(final float[] arr) {
    if (arr == null)
        throw new NullPointerException("array cannot be null");
    return new AbstractList<Float>() {
        @Override
        public Float get(int index) {
            return arr[index];
        }

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