Example usage for java.util SortedSet size

List of usage examples for java.util SortedSet size

Introduction

In this page you can find the example usage for java.util SortedSet size.

Prototype

int size();

Source Link

Document

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

Usage

From source file:org.broadleafcommerce.common.cache.StatisticsServiceImpl.java

@Override
public MBeanInfo getMBeanInfo() {
    SortedSet<String> names = new TreeSet<String>();
    for (Map.Entry<String, CacheStat> stats : cacheStats.entrySet()) {
        names.add(stats.getKey());//www. j  a  va 2  s.c  o  m
    }
    MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[names.size()];
    Iterator<String> it = names.iterator();
    for (int i = 0; i < attrs.length; i++) {
        String name = it.next();
        attrs[i] = new MBeanAttributeInfo(name, "java.lang.Double", name, true, // isReadable
                false, // isWritable
                false); // isIs
    }
    attrs = ArrayUtils.add(attrs,
            new MBeanAttributeInfo("LOG_RESOLUTION", "java.lang.Double", "LOG_RESOLUTION", true, // isReadable
                    true, // isWritable
                    false) // isIs
    );
    MBeanOperationInfo[] opers = { new MBeanOperationInfo("activate", "Activate statistic logging", null, // no parameters
            "void", MBeanOperationInfo.ACTION),
            new MBeanOperationInfo("disable", "Disable statistic logging", null, // no parameters
                    "void", MBeanOperationInfo.ACTION) };
    return new MBeanInfo("org.broadleafcommerce:name=StatisticsService." + appName, "Runtime Statistics", attrs,
            null, // constructors
            opers, null); // notifications
}

From source file:com.wakacommerce.common.cache.StatisticsServiceImpl.java

@Override
public MBeanInfo getMBeanInfo() {
    SortedSet<String> names = new TreeSet<String>();
    for (Map.Entry<String, CacheStat> stats : cacheStats.entrySet()) {
        names.add(stats.getKey());//from   w  ww.ja v  a2 s.  c o m
    }
    MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[names.size()];
    Iterator<String> it = names.iterator();
    for (int i = 0; i < attrs.length; i++) {
        String name = it.next();
        attrs[i] = new MBeanAttributeInfo(name, "java.lang.Double", name, true, // isReadable
                false, // isWritable
                false); // isIs
    }
    attrs = ArrayUtils.add(attrs,
            new MBeanAttributeInfo("LOG_RESOLUTION", "java.lang.Double", "LOG_RESOLUTION", true, // isReadable
                    true, // isWritable
                    false) // isIs
    );
    MBeanOperationInfo[] opers = { new MBeanOperationInfo("activate", "Activate statistic logging", null, // no parameters
            "void", MBeanOperationInfo.ACTION),
            new MBeanOperationInfo("disable", "Disable statistic logging", null, // no parameters
                    "void", MBeanOperationInfo.ACTION) };
    return new MBeanInfo("com.wakacommerce:name=StatisticsService." + appName, "Runtime Statistics", attrs,
            null, // constructors
            opers, null); // notifications
}

From source file:org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest.java

private void assertContainerEmptyDeleting(String containerName, String key) {
    SortedSet<? extends ResourceMetadata> listing = context.getBlobStore().list(containerName);
    assertEquals(listing.size(), 0,
            String.format("deleting %s, we still have %s left in container %s, using encoding %s", key,
                    listing.size(), containerName, LOCAL_ENCODING));
}

From source file:org.apache.hadoop.mapred.SortedRanges.java

/**
 * Remove the range indices. If this range is  
 * found in existing ranges, the existing ranges 
 * are shrunk./*from ww w .  j  a v a  2 s .c  o  m*/
 * If range is of 0 length, doesn't do anything.
 * @param range Range to be removed.
 */
synchronized void remove(Range range) {
    if (range.isEmpty()) {
        return;
    }
    long startIndex = range.getStartIndex();
    long endIndex = range.getEndIndex();
    //make sure that there are no overlapping ranges
    SortedSet<Range> headSet = ranges.headSet(range);
    if (headSet.size() > 0) {
        Range previousRange = headSet.last();
        LOG.debug("previousRange " + previousRange);
        if (startIndex < previousRange.getEndIndex()) {
            //previousRange overlaps this range
            //narrow down the previousRange
            if (ranges.remove(previousRange)) {
                indicesCount -= previousRange.getLength();
                LOG.debug("removed previousRange " + previousRange);
            }
            add(previousRange.getStartIndex(), startIndex);
            if (endIndex <= previousRange.getEndIndex()) {
                add(endIndex, previousRange.getEndIndex());
            }
        }
    }

    Iterator<Range> tailSetIt = ranges.tailSet(range).iterator();
    while (tailSetIt.hasNext()) {
        Range nextRange = tailSetIt.next();
        LOG.debug("nextRange " + nextRange + "   startIndex:" + startIndex + "  endIndex:" + endIndex);
        if (endIndex > nextRange.getStartIndex()) {
            //nextRange overlaps this range
            //narrow down the nextRange
            tailSetIt.remove();
            indicesCount -= nextRange.getLength();
            if (endIndex < nextRange.getEndIndex()) {
                add(endIndex, nextRange.getEndIndex());
                break;
            }
        } else {
            break;
        }
    }
}

From source file:org.apache.hadoop.mapred.SortedRanges.java

/**
 * Add the range indices. It is ensured that the added range 
 * doesn't overlap the existing ranges. If it overlaps, the 
 * existing overlapping ranges are removed and a single range 
 * having the superset of all the removed ranges and this range 
 * is added. /*from  www  .  j  av a 2  s  .com*/
 * If the range is of 0 length, doesn't do anything.
 * @param range Range to be added.
 */
synchronized void add(Range range) {
    if (range.isEmpty()) {
        return;
    }

    long startIndex = range.getStartIndex();
    long endIndex = range.getEndIndex();
    //make sure that there are no overlapping ranges
    SortedSet<Range> headSet = ranges.headSet(range);
    if (headSet.size() > 0) {
        Range previousRange = headSet.last();
        LOG.debug("previousRange " + previousRange);
        if (startIndex < previousRange.getEndIndex()) {
            //previousRange overlaps this range
            //remove the previousRange
            if (ranges.remove(previousRange)) {
                indicesCount -= previousRange.getLength();
            }
            //expand this range
            startIndex = previousRange.getStartIndex();
            endIndex = endIndex >= previousRange.getEndIndex() ? endIndex : previousRange.getEndIndex();
        }
    }

    Iterator<Range> tailSetIt = ranges.tailSet(range).iterator();
    while (tailSetIt.hasNext()) {
        Range nextRange = tailSetIt.next();
        LOG.debug("nextRange " + nextRange + "   startIndex:" + startIndex + "  endIndex:" + endIndex);
        if (endIndex >= nextRange.getStartIndex()) {
            //nextRange overlaps this range
            //remove the nextRange
            tailSetIt.remove();
            indicesCount -= nextRange.getLength();
            if (endIndex < nextRange.getEndIndex()) {
                //expand this range
                endIndex = nextRange.getEndIndex();
                break;
            }
        } else {
            break;
        }
    }
    add(startIndex, endIndex);
}

From source file:org.apache.hadoop.hbase.util.TestRegionSplitCalculator.java

/**
 * Check the "depth" (number of regions included at a split) of a generated
 * split calculation//from  w  ww . j a v a  2  s  . co  m
 */
void checkDepths(SortedSet<byte[]> splits, Multimap<byte[], SimpleRange> regions, Integer... depths) {
    assertEquals(splits.size(), depths.length);
    int i = 0;
    for (byte[] k : splits) {
        Collection<SimpleRange> rs = regions.get(k);
        int sz = rs == null ? 0 : rs.size();
        assertEquals((int) depths[i], sz);
        i++;
    }
}

From source file:gov.nih.nci.caarray.upgrade.FixIlluminaGenotypingCsvDesignProbeNamesMigrator.java

private void renameProbesUsingReparsedProbeNames(ArrayDesign originalArrayDesign,
        ArrayDesign reparsedArrayDesign) {
    final SortedSet<PhysicalProbe> originalProbes = getSortedProbeList(originalArrayDesign);
    final SortedSet<PhysicalProbe> reparsedProbes = getSortedProbeList(reparsedArrayDesign);

    if (originalProbes.size() != reparsedProbes.size()) {
        throw new IllegalStateException("probe set sizes differ");
    }/*from   ww  w  .j  a  v  a  2s . co  m*/

    final Iterator<PhysicalProbe> reparsedProbeIterator = reparsedProbes.iterator();
    for (final PhysicalProbe originalProbe : originalProbes) {
        final String reparsedName = reparsedProbeIterator.next().getName();
        originalProbe.setName(reparsedName);
    }
}

From source file:org.jclouds.azure.storage.blob.AzureBlobClientLiveTest.java

@Test
public void testListContainers() throws Exception {

    SortedSet<ListableContainerProperties> response = connection.listContainers();
    assert null != response;
    long initialContainerCount = response.size();
    assertTrue(initialContainerCount >= 0);

}

From source file:com.cloudera.oryx.kmeans.computation.cluster.KSketchIndex.java

public Distance getDistance(RealVector vec, int id, boolean approx) {
    double distance = Double.POSITIVE_INFINITY;
    int closestPoint = -1;
    if (approx) {
        if (updated) {
            rebuildIndices();//from   w  w  w. java  2 s  .  co m
        }

        BitSet q = index(vec);
        List<BitSet> index = indices.get(id);
        SortedSet<Idx> lookup = Sets.newTreeSet();
        for (int j = 0; j < index.size(); j++) {
            Idx idx = new Idx(hammingDistance(q, index.get(j)), j);
            if (lookup.size() < projectionSamples) {
                lookup.add(idx);
            } else if (idx.compareTo(lookup.last()) < 0) {
                lookup.add(idx);
                lookup.remove(lookup.last());
            }
        }

        List<RealVector> p = points.get(id);
        List<Double> lsq = lengthSquared.get(id);
        for (Idx idx : lookup) {
            double lenSq = lsq.get(idx.getIndex());
            double length = vec.getNorm();
            double d = length * length + lenSq - 2 * vec.dotProduct(p.get(idx.getIndex()));
            if (d < distance) {
                distance = d;
                closestPoint = idx.getIndex();
            }
        }
    } else { // More expensive exact computation
        List<RealVector> px = points.get(id);
        List<Double> lsq = lengthSquared.get(id);
        for (int j = 0; j < px.size(); j++) {
            RealVector p = px.get(j);
            double lenSq = lsq.get(j);
            double length = vec.getNorm();
            double d = length * length + lenSq - 2 * vec.dotProduct(p);
            if (d < distance) {
                distance = d;
                closestPoint = j;
            }
        }
    }

    return new Distance(distance, closestPoint);
}

From source file:org.jclouds.azure.storage.blob.AzureBlobClientLiveTest.java

@Test(timeOut = 5 * 60 * 1000)
public void testCreateContainer() throws Exception {
    boolean created = false;
    while (!created) {
        privateContainer = containerPrefix + new SecureRandom().nextInt();
        try {/*from   w  w  w  .  ja  v  a  2s.c om*/
            created = connection.createContainer(privateContainer,
                    CreateContainerOptions.Builder.withMetadata(ImmutableMultimap.of("foo", "bar")));
        } catch (UndeclaredThrowableException e) {
            HttpResponseException htpe = (HttpResponseException) e.getCause().getCause();
            if (htpe.getResponse().getStatusCode() == 409)
                continue;
            throw e;
        }
    }
    SortedSet<ListableContainerProperties> response = connection.listContainers();
    assert null != response;
    long containerCount = response.size();
    assertTrue(containerCount >= 1);
    ListBlobsResponse list = connection.listBlobs(privateContainer);
    assertEquals(list.getUrl(),
            URI.create(String.format("https://%s.blob.core.windows.net/%s", account, privateContainer)));
    // TODO ... check to see the container actually exists
}