Example usage for com.google.common.collect Lists newArrayList

List of usage examples for com.google.common.collect Lists newArrayList

Introduction

In this page you can find the example usage for com.google.common.collect Lists newArrayList.

Prototype

@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayList() 

Source Link

Document

Creates a mutable, empty ArrayList instance (for Java 6 and earlier).

Usage

From source file:org.apache.tajo.tuple.offheap.OffHeapRowBlockUtils.java

public static List<Tuple> sort(OffHeapRowBlock rowBlock, Comparator<Tuple> comparator) {
    List<Tuple> tupleList = Lists.newArrayList();
    ZeroCopyTuple zcTuple = new ZeroCopyTuple();
    OffHeapRowBlockReader reader = new OffHeapRowBlockReader(rowBlock);
    while (reader.next(zcTuple)) {
        tupleList.add(zcTuple);/*from  w w w  . j  av a2s .  com*/
        zcTuple = new ZeroCopyTuple();
    }
    Collections.sort(tupleList, comparator);
    return tupleList;
}

From source file:org.sonar.sslr.internal.text.TextUtils.java

public static int[] computeLines(char[] chars) {
    List<Integer> newlines = Lists.newArrayList();
    int i = 0;//from   w  w w  .  j  av a  2s . co  m
    while (i < chars.length) {
        if (isEndOfLine(chars, i)) {
            newlines.add(i + 1);
        }
        i++;
    }
    if (newlines.isEmpty()) {
        return EMPTY_INT_ARRAY;
    }
    int[] lines = new int[newlines.size()];
    for (i = 0; i < newlines.size(); i++) {
        lines[i] = newlines.get(i);
    }
    return lines;
}

From source file:com.cloudera.exhibit.core.simple.SimpleObsDescriptor.java

public static SimpleObsDescriptor of(String name, FieldType type, Object... args) {
    List<Field> fields = Lists.newArrayList();
    fields.add(new Field(name, type));
    for (int i = 0; i < args.length; i += 2) {
        fields.add(new Field(args[i].toString(), (FieldType) args[i + 1]));
    }//from w w  w .  ja  va 2s .  c om
    return new SimpleObsDescriptor(fields);
}

From source file:com.coul.common.mapper.BeanMapper.java

/**
 * Dozer?Collection./*w  w  w. j  a v a  2  s  .  c  o  m*/
 */
@SuppressWarnings("rawtypes")
public static <T> List<T> mapList(Collection sourceList, Class<T> destinationClass) {
    List<T> destinationList = Lists.newArrayList();
    for (Object sourceObject : sourceList) {
        T destinationObject = dozer.map(sourceObject, destinationClass);
        destinationList.add(destinationObject);
    }
    return destinationList;
}

From source file:org.activityinfo.legacy.shared.model.AdminLevelPredicates.java

public static List<AdminLevelDTO> breadthFirstSort(List<AdminLevelDTO> allLevels) {
    List<AdminLevelDTO> sorted = Lists.newArrayList();
    Predicate<AdminLevelDTO> predicate = rootLevels();
    Collection<AdminLevelDTO> next;
    while (!(next = Collections2.filter(allLevels, predicate)).isEmpty()) {
        sorted.addAll(next);/*w  w  w  . j a v a2s .co m*/
        predicate = childrenOf(next);
    }
    return sorted;
}

From source file:org.eclipse.wb.gef.core.tools.ToolUtilities.java

/**
 * Returns a list containing the top level selected {@link EditPart}'s based on the viewer's
 * selection. If selection parents of edit parts is differed returns empty list.
 *///from w ww. j a v  a2s . c  om
public static List<EditPart> getSelectionWithoutDependants(IEditPartViewer viewer) {
    List<EditPart> operationSet = Lists.newArrayList();
    // add selected EditPart's only if their parent is not added yet
    {
        List<EditPart> selectedParts = viewer.getSelectedEditParts();
        for (EditPart part : selectedParts) {
            if (!isAncestorContainedIn(selectedParts, part)) {
                operationSet.add(part);
            }
        }
    }
    // check that all EditPart's have same parent
    {
        EditPart commonParent = null;
        for (EditPart editPart : operationSet) {
            if (commonParent == null) {
                commonParent = editPart.getParent();
            } else if (editPart.getParent() != commonParent) {
                return Collections.emptyList();
            }
        }
    }
    // OK, we have valid set
    return operationSet;
}

From source file:net.ftb.data.news.RSSReader.java

public static List<NewsArticle> readRSS() {
    try {/*from w  w  w .  ja v a 2  s.  co  m*/
        List<NewsArticle> news = Lists.newArrayList();

        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        URL u = new URL(Locations.feedURL);
        Document doc = builder.parse(u.openStream());
        NodeList nodes = doc.getElementsByTagName("item");

        for (int i = 0; i < nodes.getLength(); i++) {
            Element element = (Element) nodes.item(i);
            NewsArticle article = new NewsArticle();
            article.setTitle(getTextValue(element, "title"));
            article.setHyperlink(getTextValue(element, "link"));
            article.setBody(getTextValue(element, "content:encoded"));
            article.setDate(getTextValue(element, "pubDate"));
            news.add(article);
        }

        return news;
    } catch (Exception ex) {
        Logger.logError("News download failed", ex);
        return null;
    }
}

From source file:runtime.intrinsic._strwhere.java

public static ListValue invoke(final String s, final Lambda pred) {
    final int len = s.length();

    if (len == 0)
        return PersistentList.EMPTY;

    final ArrayList<Integer> indexes = Lists.newArrayList();

    for (int i = 0; i < len; i++)
        if ((Boolean) pred.apply(s.substring(i, i + 1)))
            indexes.add(i);/*from   w  w w . j  a  v a 2  s .c o m*/

    return PersistentList.init(indexes.iterator(), indexes.size());
}

From source file:com.google.idea.blaze.base.sync.libraries.BlazeLibraryCollector.java

public static List<BlazeLibrary> getLibraries(BlazeProjectData blazeProjectData) {
    List<BlazeLibrary> result = Lists.newArrayList();
    List<LibrarySource> librarySources = Lists.newArrayList();
    for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
        LibrarySource librarySource = syncPlugin.getLibrarySource(blazeProjectData);
        if (librarySource != null) {
            librarySources.add(librarySource);
        }/*from w w w  .ja va  2 s.  c  o m*/
    }
    for (LibrarySource librarySource : librarySources) {
        result.addAll(librarySource.getLibraries());
    }
    Predicate<BlazeLibrary> libraryFilter = librarySources.stream().map(LibrarySource::getLibraryFilter)
            .filter(Objects::nonNull).reduce(Predicate::and).orElse(o -> true);
    return result.stream().filter(libraryFilter).collect(Collectors.toList());
}