Example usage for java.util Set size

List of usage examples for java.util Set size

Introduction

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

Prototype

int size();

Source Link

Document

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

Usage

From source file:com.hoccer.http.AsyncHttpRequestWithBody.java

public static String urlEncodeValues(Map<String, String> pData) {

    StringBuffer tmp = new StringBuffer();
    Set keys = pData.keySet();
    int idx = 0;//from ww w.  java  2  s .  c o  m
    for (Object key : keys) {
        tmp.append(String.valueOf(key));
        tmp.append("=");
        tmp.append(URLEncoder.encode(String.valueOf(pData.get(key))));

        idx += 1;
        if (idx < keys.size()) {
            tmp.append("&");
        }
    }

    return tmp.toString();
}

From source file:com.beginner.core.utils.ProjectUtil.java

/**
 * ?Web???(???)//from   w  ww  . j  a v  a2 s  .  c  o m
 */
public static String getPort() {
    String result = "";
    try {
        MBeanServer mBeanServer = null;
        List<MBeanServer> mBeanServers = MBeanServerFactory.findMBeanServer(null);
        if (mBeanServers.size() > 0) {
            for (MBeanServer _mBeanServer : mBeanServers) {
                mBeanServer = _mBeanServer;
                break;
            }
        }
        if (mBeanServer == null) {
            throw new IllegalStateException("?JVM?MBeanServer.");
        }
        Set<ObjectName> objectNames = null;
        objectNames = mBeanServer.queryNames(new ObjectName("Catalina:type=Connector,*"), null);
        if (objectNames == null || objectNames.size() <= 0) {
            throw new IllegalStateException("?JVM?MBeanServer : "
                    + mBeanServer.getDefaultDomain() + " ??.");
        }
        for (ObjectName objectName : objectNames) {
            String protocol = (String) mBeanServer.getAttribute(objectName, "protocol");
            if (protocol.equals("HTTP/1.1")) {
                int port = (Integer) mBeanServer.getAttribute(objectName, "port");
                result = port + StringUtils.EMPTY;
            }
        }
    } catch (Exception e) {
        logger.error("?WEB?HTTP/1.1???", e);
    }
    return result;
}

From source file:org.springframework.xd.distributed.util.ServerProcessUtils.java

/**
 * Block the executing thread until all of the indicated process IDs
 * have been identified in the list of runtime containers as indicated
 * by the admin server. If an empty list is provided, the executing
 * thread will block until there are no containers running.
 *
 * @param template REST template used to communicate with the admin server
 * @param pids     set of process IDs for the expected containers
 * @return map of process id to container id
 * @throws InterruptedException            if the executing thread is interrupted
 * @throws java.lang.IllegalStateException if the number of containers identified
 *         does not match the number of PIDs provided
 *///from w w w  .  ja  va  2s.c o m
public static Map<Long, String> waitForContainers(SpringXDTemplate template, Set<Long> pids)
        throws InterruptedException, IllegalStateException {
    int pidCount = pids.size();
    Map<Long, String> mapPidUuid = getRunningContainers(template);
    long expiry = System.currentTimeMillis() + 3 * 60000;

    while (mapPidUuid.size() != pidCount && System.currentTimeMillis() < expiry) {
        Thread.sleep(500);
        mapPidUuid = getRunningContainers(template);
    }

    if (mapPidUuid.size() == pidCount && mapPidUuid.keySet().containsAll(pids)) {
        return mapPidUuid;
    }

    Set<Long> missingPids = new HashSet<Long>(pids);
    missingPids.removeAll(mapPidUuid.keySet());

    Set<Long> unexpectedPids = new HashSet<Long>(mapPidUuid.keySet());
    unexpectedPids.removeAll(pids);

    StringBuilder builder = new StringBuilder();
    if (!missingPids.isEmpty()) {
        builder.append("Admin server did not find the following container PIDs:").append(missingPids);
    }
    if (!unexpectedPids.isEmpty()) {
        if (builder.length() > 0) {
            builder.append("; ");
        }
        builder.append("Admin server found the following unexpected container PIDs:").append(unexpectedPids);
    }

    throw new IllegalStateException(builder.toString());
}

From source file:io.seldon.clustering.recommender.RecommendationContext.java

public static RecommendationContext buildContext(String client, AlgorithmStrategy strategy, Long user,
        String clientUserId, Long currentItem, Set<Integer> dimensions, String lastRecListUUID,
        int numRecommendations, DefaultOptions defaultOptions, FilteredItems includedItems) {

    OptionsHolder optsHolder = new OptionsHolder(defaultOptions, strategy.config);
    List<String> inclusionKeys = new ArrayList<String>();
    Set<Long> contextItems = new HashSet<>();

    if (includedItems != null) {
        contextItems.addAll(includedItems.getItems());
        inclusionKeys.add(includedItems.getCachingKey());
        return new RecommendationContext(MODE.INCLUSION, contextItems, Collections.<Long>emptySet(),
                inclusionKeys, currentItem, lastRecListUUID, optsHolder);
    }//  w  w  w .j  a v  a 2s  . co  m

    Set<ItemIncluder> inclusionProducers = strategy.includers;
    Set<ItemFilter> itemFilters = strategy.filters;
    if (inclusionProducers == null || inclusionProducers.size() == 0) {
        if (itemFilters == null || itemFilters.size() == 0) {
            logger.warn("No filters or includers present in strategy");
            return new RecommendationContext(MODE.NONE, Collections.<Long>emptySet(),
                    Collections.<Long>emptySet(), Collections.<String>emptyList(), currentItem, lastRecListUUID,
                    optsHolder);
        }
        for (ItemFilter filter : itemFilters) {
            contextItems.addAll(filter.produceExcludedItems(client, user, clientUserId, optsHolder, currentItem,
                    lastRecListUUID, numRecommendations));
        }
        return new RecommendationContext(MODE.EXCLUSION, contextItems, contextItems, inclusionKeys, currentItem,
                lastRecListUUID, optsHolder);
    }

    Integer itemsPerIncluder = optsHolder.getIntegerOption(ITEMS_PER_INCLUDER_OPTION_NAME);
    if (itemFilters == null || itemFilters.size() == 0) {
        for (ItemIncluder producer : inclusionProducers) {
            FilteredItems filteredItems = producer.generateIncludedItems(client, dimensions, itemsPerIncluder);
            contextItems.addAll(filteredItems.getItems());
            inclusionKeys.add(filteredItems.getCachingKey());
        }
        return new RecommendationContext(MODE.INCLUSION, contextItems, Collections.<Long>emptySet(),
                inclusionKeys, currentItem, lastRecListUUID, optsHolder);
    }

    Set<Long> included = new HashSet<>();
    Set<Long> excluded = new HashSet<>();
    for (ItemFilter filter : itemFilters) {
        excluded.addAll(filter.produceExcludedItems(client, user, clientUserId, optsHolder, currentItem,
                lastRecListUUID, numRecommendations));
    }
    for (ItemIncluder producer : inclusionProducers) {
        FilteredItems filteredItems = producer.generateIncludedItems(client, dimensions, itemsPerIncluder);
        included.addAll(filteredItems.getItems());
        inclusionKeys.add(filteredItems.getCachingKey());
    }
    included.removeAll(excluded); // ok to do this as the excluded items that weren't in "included" will never
                                  // be recommended

    return new RecommendationContext(MODE.INCLUSION, included, excluded, inclusionKeys, currentItem,
            lastRecListUUID, optsHolder);
}

From source file:modula.parser.io.ModelUpdater.java

/**
 * transitiontarget??/*w  w  w.  j  av a 2s. c o m*/
 * targettarget
 */
private static boolean verifyTransitionTargets(final Set<TransitionTarget> tts) {
    if (tts.size() <= 1) { // No contention
        return true;
    }

    Set<EnterableState> parents = new HashSet<EnterableState>();
    for (TransitionTarget tt : tts) {
        boolean hasParallelParent = false;
        for (int i = tt.getNumberOfAncestors() - 1; i > -1; i--) {
            EnterableState parent = tt.getAncestor(i);

            if (!parents.add(parent)) {
                // this TransitionTarget is an descendant of another, or shares the same Parallel region
                return false;

            }
        }
    }
    return true;
}

From source file:com.opengamma.bloombergexample.loader.PortfolioLoaderHelper.java

public static void persistLiborRawSecurities(Set<Currency> currencies, ToolContext toolContext) {
    SecurityMaster securityMaster = toolContext.getSecurityMaster();
    byte[] rawData = new byte[] { 0 };
    StringBuilder sb = new StringBuilder();
    sb.append("Created ").append(currencies.size()).append(" libor securities:\n");
    for (Currency ccy : currencies) {
        ConventionBundle swapConvention = getSwapConventionBundle(ccy, toolContext.getConventionBundleSource());
        ConventionBundle liborConvention = getLiborConventionBundle(swapConvention,
                toolContext.getConventionBundleSource());
        sb.append("\t").append(liborConvention.getIdentifiers()).append("\n");
        RawSecurity rawSecurity = new RawSecurity(LIBOR_RATE_SECURITY_TYPE, rawData);
        rawSecurity.setExternalIdBundle(liborConvention.getIdentifiers());
        SecurityDocument secDoc = new SecurityDocument();
        secDoc.setSecurity(rawSecurity);
        securityMaster.add(secDoc);/*from  ww w . j  a v  a2  s  .  co  m*/
    }
    s_logger.info(sb.toString());
}

From source file:com.denkbares.semanticcore.utils.ResultTableModel.java

public static String generateErrorsText(MultiMap<String, Message> failures, boolean full) {
    StringBuilder buffy = new StringBuilder();
    buffy.append("The following test failures occurred:\n");
    for (String type : failures.keySet()) {
        Set<Message> failuresOfType = failures.getValues(type);
        buffy.append(failuresOfType.size()).append(" ").append(type).append(":\n");
        int i = 0;
        for (Message message : failuresOfType) {
            if (!full && ++i > MAX_DISPLAYED_FAILRUES) {
                buffy.append("* ... see expected and actual result linked below\n");
                break;
            }/*w ww. j a  v a  2 s. co m*/
            buffy.append("* ").append(message.getText()).append("\n");
        }
    }
    return buffy.toString();
}

From source file:com.frostwire.vuze.VuzeDownloadManager.java

private static String calculateDisplayName(DownloadManager dm, Set<DiskManagerFileInfo> noSkippedSet) {
    String displayName = null;/*w w  w  .ja  v a 2s  .c o m*/

    if (noSkippedSet.size() == 1) {
        displayName = FilenameUtils.getBaseName(noSkippedSet.iterator().next().getFile(false).getName());
    } else {
        displayName = dm.getDisplayName();
    }

    return displayName;
}

From source file:com.frostwire.vuze.VuzeDownloadManager.java

private static long calculateSize(DownloadManager dm, Set<DiskManagerFileInfo> noSkippedSet) {
    long size = 0;

    boolean partial = noSkippedSet.size() != dm.getDiskManagerFileInfoSet().nbFiles();

    if (partial) {
        for (DiskManagerFileInfo fileInfo : noSkippedSet) {
            size += fileInfo.getLength();
        }/*from w ww .j av  a2s. co  m*/
    } else {
        size = dm.getSize();
    }

    return size;
}

From source file:de.micromata.mgc.jpa.hibernatesearch.impl.SearchEmgrFactoryRegistryUtils.java

private static void addHibernateSearchOwnFields(ISearchEmgr<?> emgr, Map<String, SearchColumnMetadata> ret,
        EntityMetadata entm) {//from  w w  w  .java 2  s  .  co m
    IndexedTypeDescriptor tddesc = emgr.getFullTextEntityManager().getSearchFactory()
            .getIndexedTypeDescriptor(entm.getJavaType());
    if (tddesc == null) {
        return;
    }
    Set<FieldDescriptor> fields = tddesc.getIndexedFields();

    for (PropertyDescriptor idesc : tddesc.getIndexedProperties()) {
        String name = idesc.getName();
        if (ret.containsKey(name) == true) {
            continue;
        }
        ColumnMetadata coldesc = entm.findColumn(name);

        if (coldesc == null) {
            ColumnMetadataBean dcoldesc = new ColumnMetadataBean(entm);
            dcoldesc.setName(name);
            dcoldesc.setJavaType(String.class);
            coldesc = dcoldesc;
        }
        Set<FieldDescriptor> indexedfields = idesc.getIndexedFields();
        indexedfields.size();

        if (idesc.getIndexedFields().isEmpty() == true) {
            LOG.warn("Field has no indexed fields: " + entm.getJavaType().getName() + "." + name);
        }
        boolean isId = idesc.isId();
        for (FieldDescriptor fdesc : idesc.getIndexedFields()) {
            SearchColumnMetadataBean nb = new SearchColumnMetadataBean(fdesc.getName(), coldesc);
            switch (fdesc.getType()) {
            case BASIC:
                nb.setIndexType(String.class);
                break;
            case NUMERIC:
                nb.setIndexType(Long.class);
                break;
            case SPATIAL:
                nb.setIndexType(void.class);
                break;
            }
            nb.setIdField(isId);
            nb.setIndexed(fdesc.getIndex() == Index.YES);
            nb.setAnalyzed(fdesc.getAnalyze() == Analyze.YES);
            nb.setStored(fdesc.getStore() == Store.YES);
            ret.put(fdesc.getName(), nb);
        }

    }
}