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:org.briljantframework.array.AbstractBooleanArray.java

@Override
public List<Boolean> toList() {
    return new AbstractList<Boolean>() {
        @Override//from w  w  w.  j  a  v a 2s  .c o m
        public int size() {
            return AbstractBooleanArray.this.size();
        }

        @Override
        public Boolean get(int index) {
            return AbstractBooleanArray.this.get(index);
        }

        @Override
        public Boolean set(int index, Boolean element) {
            Boolean old = get(index);
            AbstractBooleanArray.this.set(index, element);
            return old;
        }

    };
}

From source file:ec.util.chart.swing.Charts.java

@Nonnull
public static List<XYDataset> asDatasetList(@Nonnull final XYPlot plot) {
    return new AbstractList<XYDataset>() {

        @Override/*  w ww.j  a v a2 s  .co m*/
        public XYDataset get(int index) {
            return plot.getDataset(index);
        }

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

From source file:org.briljantframework.array.AbstractLongArray.java

@Override
public List<Long> toList() {
    return new AbstractList<Long>() {
        @Override/*  w  w  w .  j a  v  a 2 s  .co m*/
        public int size() {
            return 0;
        }

        @Override
        public Long get(int index) {
            return AbstractLongArray.this.get(index);
        }

        @Override
        public Long set(int index, Long element) {
            Long old = get(index);
            AbstractLongArray.this.set(index, element);
            return old;
        }

    };
}

From source file:org.briljantframework.array.AbstractArray.java

@Override
public List<T> toList() {
    return new AbstractList<T>() {

        @Override//from   w  w w.j a v a  2  s.c o  m
        public int size() {
            return AbstractArray.this.size();
        }

        @Override
        public T get(int index) {
            return AbstractArray.this.get(index);
        }

        @Override
        public T set(int index, T element) {
            T oldElement = get(index);
            AbstractArray.this.set(index, element);
            return oldElement;
        }

    };
}

From source file:org.alfresco.rest.api.impl.SitesImpl.java

public CollectionWithPagingInfo<Site> getSites(final Parameters parameters) {
    final BeanPropertiesFilter filter = parameters.getFilter();

    Paging paging = parameters.getPaging();
    PagingRequest pagingRequest = Util.getPagingRequest(paging);
    //       pagingRequest.setRequestTotalCountMax(requestTotalCountMax)
    List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>();
    sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_NAME, Boolean.TRUE));
    final PagingResults<SiteInfo> pagingResult = siteService.listSites(null, sortProps, pagingRequest);
    final List<SiteInfo> sites = pagingResult.getPage();
    int totalItems = pagingResult.getTotalResultCount().getFirst();
    final String personId = AuthenticationUtil.getFullyAuthenticatedUser();
    List<Site> page = new AbstractList<Site>() {
        @Override/*from  ww  w.j a v a 2 s.c om*/
        public Site get(int index) {
            SiteInfo siteInfo = sites.get(index);

            String role = null;
            if (filter.isAllowed(Site.ROLE)) {
                role = siteService.getMembersRole(siteInfo.getShortName(), personId);
            }
            return new Site(siteInfo, role);
        }

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

    return CollectionWithPagingInfo.asPaged(paging, page, pagingResult.hasMoreItems(), totalItems);
}

From source file:com.analog.lyric.dimple.solvers.core.parameterizedMessages.MultivariateNormalParameters.java

public @Nullable List<Normal> getDiagonalNormals() {
    if (isDiagonal()) {

        return new AbstractList<Normal>() {
            @Override/*from w  w w  .j  a  v a2 s  . co m*/
            public Normal get(int index) {
                return requireNonNull(getDiagonalNormal(index));
            }

            @Override
            public int size() {
                return _size;
            }
        };
    }

    return null;
}

From source file:org.openstreetmap.josm.tools.Utils.java

/**
 * Transforms the list {@code l} into an unmodifiable list and
 * applies the {@link Function} {@code f} on each element upon access.
 * @param <A> class of input collection
 * @param <B> class of transformed collection
 * @param l a collection// ww  w .  java2s .  c  o  m
 * @param f a function that transforms objects of {@code A} to objects of {@code B}
 * @return the transformed unmodifiable list
 */
public static <A, B> List<B> transform(final List<? extends A> l, final Function<A, B> f) {
    return new AbstractList<B>() {

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

        @Override
        public B get(int index) {
            return f.apply(l.get(index));
        }
    };
}

From source file:org.briljantframework.array.Arrays.java

/**
 * Split an array into multiple sub-arrays of equal size.
 *
 * @param array the array//  www  . j av a 2s  . c  o  m
 * @param parts the number of parts
 * @param dim the dimension along which to split
 * @param <T> the type of array
 * @return a (lazy) list of sub-arrays. Each time {@link List#get(int)} is called, the sub-arrays
 *         are recomputed. If accessing sub-arrays multiple times, consider creating a new
 *         pre-computed list (e.g., {@code new ArrayList<>(Arrays.split(x, 2, 0)}).
 */
public static <T extends BaseArray<T>> List<T> split(T array, int parts, int dim) {
    Check.argument(array.size(dim) % parts == 0);
    int[] shape = array.getShape();
    shape[dim] /= parts;

    return new AbstractList<T>() {
        @Override
        public T get(int index) {
            T empty = array.newEmptyArray(shape);
            int size = empty.size(dim);
            int rowPadding = index * size;
            for (int i = 0; i < size; i++) {
                empty.select(dim, i).assign(array.select(dim, rowPadding + i));
            }
            return empty;
        }

        @Override
        public int size() {
            return parts;
        }
    };
}

From source file:org.briljantframework.array.Arrays.java

/**
 * Stack arrays in sequence vertically (row wise). Take a sequence of arrays and stack them
 * vertically to make a single array. Rebuild arrays divided by {@link #vsplit(BaseArray, int)}.
 *
 * @param arrays a list of arrays//  w ww.ja v  a 2s . com
 * @param <T> the type of arrays
 * @return a new array
 * @see #concatenate(List, int)
 */
public static <T extends BaseArray<T>> T vstack(List<T> arrays) {
    return concatenate(new AbstractList<T>() {
        @Override
        public T get(int index) {
            T v = arrays.get(index);
            return v.isVector() ? v.reshape(v.size(), 1) : v;
        }

        @Override
        public int size() {
            return arrays.size();
        }
    }, 0);
}

From source file:org.briljantframework.array.Arrays.java

/**
 * Stack arrays in sequence horizontally (column wise). Take a sequence of arrays and stack them
 * horizontally to make a single array. Rebuild arrays divided by {@link #hsplit(BaseArray, int)}.
 *
 * @param arrays the arrays/*from www.  j  ava2 s . c om*/
 * @param <T> the type of array
 * @return a new array
 * @see #concatenate(List, int)
 */
public static <T extends BaseArray<T>> T hstack(List<T> arrays) {
    return concatenate(new AbstractList<T>() {
        @Override
        public T get(int index) {
            T a = arrays.get(index);
            return a.dims() == 1 ? a.reshape(1, a.size()) : a;
        }

        @Override
        public int size() {
            return arrays.size();
        }
    }, 1);
}