Example usage for com.google.common.collect Iterables size

List of usage examples for com.google.common.collect Iterables size

Introduction

In this page you can find the example usage for com.google.common.collect Iterables size.

Prototype

public static int size(Iterable<?> iterable) 

Source Link

Document

Returns the number of elements in iterable .

Usage

From source file:com.github.joshelser.ScannerQueryTask.java

@Override
public Integer call() throws Exception {
    int count = 0;
    for (Range r : ranges) {
        try (Scanner s = conn.createScanner("usertable", Authorizations.EMPTY)) {
            s.setRange(r);//from   w w w .j  a v  a2s .  c om
            count += Iterables.size(s);
        }
    }
    return count;
}

From source file:org.jclouds.rest.functions.ReturnNullOnNotFoundOr404.java

public Object apply(Exception from) {
    Iterable<ResourceNotFoundException> throwables = Iterables.filter(Throwables.getCausalChain(from),
            ResourceNotFoundException.class);
    if (Iterables.size(throwables) >= 1) {
        return null;
    } else if (rto404.apply(from)) {
        return null;
    }/*  w w  w.j ava 2 s .com*/
    return Object.class.cast(propagateOrNull(from));
}

From source file:org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404.java

public Void apply(Exception from) {
    Iterable<ResourceNotFoundException> throwables = Iterables.filter(Throwables.getCausalChain(from),
            ResourceNotFoundException.class);
    if (Iterables.size(throwables) >= 1) {
        return null;
    } else {//from w w w .j a  v  a2s  . c  o  m
        Boolean value = rto404.apply(from);
        if (value != null && value)
            return null;
    }
    return Void.class.cast(propagateOrNull(from));
}

From source file:com.android.tools.idea.npw.project.AndroidGradleModuleUtils.java

/**
 * Given a file and a project, return the Module corresponding to the containing Gradle project for the file.  If the file is not
 * contained by any project then return null
 *//*  w w  w  .j a v  a  2 s  .  c o  m*/
@Nullable
public static Module getContainingModule(File file, Project project) {
    VirtualFile vFile = VfsUtil.findFileByIoFile(file, false);
    if (vFile == null) {
        return null;
    }
    Module bestMatch = null;
    int bestMatchValue = Integer.MAX_VALUE;
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        GradleFacet facet = GradleFacet.getInstance(module);
        if (facet != null) {
            GradleModuleModel gradleModuleModel = facet.getGradleModuleModel();
            assert gradleModuleModel != null;
            VirtualFile buildFile = gradleModuleModel.getBuildFile();
            if (buildFile != null) {
                VirtualFile root = buildFile.getParent();
                if (VfsUtilCore.isAncestor(root, vFile, true)) {
                    String relativePath = VfsUtilCore.getRelativePath(vFile, root, '/');
                    if (relativePath != null) {
                        int value = Iterables.size(Splitter.on('/').split(relativePath));
                        if (value < bestMatchValue) {
                            bestMatch = module;
                            bestMatchValue = value;
                        }
                    }
                }
            }
        }
    }
    return bestMatch;
}

From source file:domain.common.AbstractBusinessObjectBeanMapper.java

public List<Bo> newBusinessObjectList(final Iterable<Bean> businessObjectBeanList) {
    List<Bo> businessObjectDTOList = new ArrayList<>(Iterables.size(businessObjectBeanList));

    for (Bean businessObjectBean : businessObjectBeanList)
        businessObjectDTOList.add(this.newBusinessObject(businessObjectBean));

    return businessObjectDTOList;
}

From source file:eu.trentorise.opendata.semtext.SemTexts.java

/**
 * Determines the best meaning among the given ones according to their
 * probabilities. If no best meaning is found null is returned.
 *
 * @param meanings a sorted list of meanings, with the first ones being the
 * most important./*from  w ww  .j av a  2  s  .c  o  m*/
 * @return the disambiguated meaning or null if no meaning can be clearly
 * identified.
 */
@Nullable
public static Meaning disambiguate(Iterable<Meaning> meanings) {

    if (Iterables.isEmpty(meanings)) {
        return null;
    }

    int size = Iterables.size(meanings);

    if (size == 1) {
        Meaning m = meanings.iterator().next();
        if (m.getId() == null) {
            return null;
        } else {
            return m;
        }
    }

    Meaning first = Iterables.getFirst(meanings, null);

    if (first.getProbability() > DISAMBIGUATION_FACTOR / size && first.getId() != null) {
        return first;
    } else {
        return null;
    }

}

From source file:org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404.java

public Object apply(Exception from) {
    Iterable<ResourceNotFoundException> throwables = Iterables.filter(Throwables.getCausalChain(from),
            ResourceNotFoundException.class);
    if (Iterables.size(throwables) >= 1) {
        return PagedIterables.EMPTY;
    } else if (rto404.apply(from)) {
        return PagedIterables.EMPTY;
    }/*from   w  ww .j  a  v a  2s  .  co  m*/
    throw Throwables.propagate(from);
}

From source file:com.eviware.loadui.util.collections.CollectionFuture.java

public int size() {
    return Iterables.size(futures);
}

From source file:org.jclouds.rest.functions.ReturnEmptyIterableWithMarkerOnNotFoundOr404.java

public Object apply(Exception from) {
    Iterable<ResourceNotFoundException> throwables = Iterables.filter(Throwables.getCausalChain(from),
            ResourceNotFoundException.class);
    if (Iterables.size(throwables) >= 1) {
        return IterableWithMarkers.EMPTY;
    } else if (rto404.apply(from)) {
        return IterableWithMarkers.EMPTY;
    }//from w ww .  java2s. co m
    throw Throwables.propagate(from);
}

From source file:com.google.security.zynamics.binnavi.disassembly.views.CViewFilter.java

/**
 * Returns the number of views of type FLOWGRAPH.
 * /*  ww w.ja va2s  .  com*/
 * @param views The list of views.
 * @return The number of views of type FLOWGRAPH:
 */
public static int getFlowgraphViewCount(final List<INaviView> views) {
    return Iterables.size(getViewsByType(views, GraphType.FLOWGRAPH));
}