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

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

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of elements in this set (its cardinality).

Usage

From source file:org.caleydo.view.domino.internal.ui.SelectionInfo.java

private static String getLabel(Set<Integer> elements, IDType idType) {
    String label = idType.getIDCategory().getCategoryName();
    IDMappingManager manager = IDMappingManagerRegistry.get().getIDMappingManager(idType);
    IIDTypeMapper<Integer, String> id2label = manager.getIDTypeMapper(idType,
            idType.getIDCategory().getHumanReadableIDType());
    if (id2label != null) {
        Set<String> r = id2label.apply(elements);
        if (r != null) {
            ImmutableSortedSet<String> b = ImmutableSortedSet.orderedBy(String.CASE_INSENSITIVE_ORDER).addAll(r)
                    .build();//from  w  ww  .j  a  v  a2  s. co m
            if (b.size() < 3) {
                label = StringUtils.join(b, ", ");
            } else {
                label = StringUtils.join(b.asList().subList(0, 3), ", ") + " ...";
            }
        }
    }
    return label;
}

From source file:com.facebook.buck.io.file.PathListing.java

private static ImmutableSortedSet<Path> applyNumPathsFilter(ImmutableSortedSet<Path> paths,
        FilterMode filterMode, OptionalInt maxPathsFilter) {
    if (maxPathsFilter.isPresent()) {
        int limitIndex = Math.min(maxPathsFilter.getAsInt(), paths.size());
        paths = subSet(paths, filterMode, limitIndex);
    }/* w w  w.j a v  a 2  s.  c o  m*/
    return paths;
}

From source file:com.facebook.buck.io.PathListing.java

private static ImmutableSortedSet<Path> applyNumPathsFilter(ImmutableSortedSet<Path> paths,
        FilterMode filterMode, Optional<Integer> maxPathsFilter) {
    if (maxPathsFilter.isPresent()) {
        int limitIndex = Math.min(maxPathsFilter.get(), paths.size());
        paths = subSet(paths, filterMode, limitIndex);
    }//from w  w  w  . j  a  va  2s . c  o  m
    return paths;
}

From source file:com.facebook.buck.io.file.PathListing.java

private static ImmutableSortedSet<Path> subSet(ImmutableSortedSet<Path> paths, FilterMode filterMode,
        int limitIndex) {
    // This doesn't copy the contents of the ImmutableSortedSet. We use it
    // as a simple way to get O(1) access to the set's contents, as otherwise
    // we would have to iterate to find the Nth element.
    ImmutableList<Path> pathsList = paths.asList();
    boolean fullSet = limitIndex == paths.size();
    switch (filterMode) {
    case INCLUDE:
        // Make sure we don't call pathsList.get(pathsList.size()).
        if (!fullSet) {
            paths = paths.headSet(pathsList.get(limitIndex));
        }//from  ww  w.  java2s .  c o m
        break;
    case EXCLUDE:
        if (fullSet) {
            // Make sure we don't call pathsList.get(pathsList.size()).
            paths = ImmutableSortedSet.of();
        } else {
            paths = paths.tailSet(pathsList.get(limitIndex));
        }
        break;
    }
    return paths;
}

From source file:google.registry.monitoring.metrics.MutableDistribution.java

/** Constructs an empty Distribution with the specified {@link DistributionFitter}. */
public MutableDistribution(DistributionFitter distributionFitter) {
    this.distributionFitter = checkNotNull(distributionFitter);
    ImmutableSortedSet<Double> boundaries = distributionFitter.boundaries();

    checkArgument(boundaries.size() > 0);
    checkArgument(Ordering.natural().isOrdered(boundaries));

    this.intervalCounts = TreeRangeMap.create();

    double[] boundariesArray = Doubles.toArray(distributionFitter.boundaries());

    // Add underflow and overflow intervals
    this.intervalCounts.put(Range.lessThan(boundariesArray[0]), 0L);
    this.intervalCounts.put(Range.atLeast(boundariesArray[boundariesArray.length - 1]), 0L);

    // Add finite intervals
    for (int i = 1; i < boundariesArray.length; i++) {
        this.intervalCounts.put(Range.closedOpen(boundariesArray[i - 1], boundariesArray[i]), 0L);
    }// w  w w  .  j ava2s.co  m
}

From source file:com.coroptis.coidi.rp.base.DiscoveryResult.java

public XrdService getPreferedService() {
    UnmodifiableIterator<XrdService> openId20Services = Iterators.filter(services.iterator(),
            new Predicate<XrdService>() {
                @Override//w  ww.jav  a  2 s.  c o m
                public boolean apply(XrdService xrdService) {
                    return xrdService.idPresent(OpenIdNs.TYPE_CLAIMED_IDENTIFIER_ELEMENT_2_0)
                            || xrdService.idPresent(OpenIdNs.TYPE_OPENID_2_0);
                }
            });
    ImmutableSortedSet<XrdService> out = sortedServicesBuilder.addAll(openId20Services).build();
    return out.size() == 0 ? null : out.first();
}

From source file:com.facebook.buck.jvm.java.FakeJavaLibrary.java

public FakeJavaLibrary(BuildTarget target, SourcePathResolver resolver, ProjectFilesystem filesystem,
        ImmutableSortedSet<BuildRule> deps) {
    super(target, filesystem, resolver, deps.toArray(new BuildRule[deps.size()]));
}

From source file:com.google.devtools.build.lib.skyframe.serialization.ImmutableSortedSetCodec.java

@Override
public void serialize(SerializationContext context, ImmutableSortedSet<E> object, CodedOutputStream codedOut)
        throws SerializationException, IOException {
    context.serialize(object.comparator(), codedOut);
    codedOut.writeInt32NoTag(object.size());
    for (Object obj : object) {
        context.serialize(obj, codedOut);
    }/*from  w  w w. j av  a2 s. co  m*/
}

From source file:org.voltcore.utils.COWNavigableSet.java

@Override
public E pollLast() {
    while (true) {
        ImmutableSortedSet<E> snapshot = m_set.get();
        E last = null;//from   w  ww .  java 2  s  .co m
        if (snapshot.size() > 0) {
            last = snapshot.last();
        } else {
            return null;
        }
        ImmutableSortedSet.Builder<E> builder = ImmutableSortedSet.naturalOrder();
        builder.addAll(snapshot.headSet(last, false));
        if (m_set.compareAndSet(snapshot, builder.build())) {
            return last;
        }
    }
}

From source file:org.voltcore.utils.COWNavigableSet.java

@Override
public E pollFirst() {
    while (true) {
        ImmutableSortedSet<E> snapshot = m_set.get();
        E first = null;/*from w  ww .  j a  v  a 2  s.c  o  m*/
        if (snapshot.size() > 0) {
            first = snapshot.first();
        } else {
            return null;
        }
        ImmutableSortedSet.Builder<E> builder = ImmutableSortedSet.naturalOrder();
        builder.addAll(snapshot.tailSet(first, false));
        if (m_set.compareAndSet(snapshot, builder.build())) {
            return first;
        }
    }
}