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:org.auraframework.test.AuraTestingUtil.java

/**
 * Clear cached defs from the system. When mocking a def, if the def has already been cached, as itself, or as part
 * of a preloaded set, the mock will not be effective, so it's safer to clear any cached defs after setting up mocks
 * but before executing a test. This relies on source change notifications to get the servlets to clear their
 * caches.//from   w  w  w .  j a va  2  s.c o m
 * 
 * @param defs the Definitions to be cleared from any caches
 * @throws InterruptedException
 */
public static <T extends Definition> void clearCachedDefs(Collection<T> defs) throws Exception {
    if (defs == null || defs.isEmpty()) {
        return;
    }

    // Get the Descriptors for the provided Definitions
    final DefinitionService definitionService = Aura.getDefinitionService();
    final Set<DefDescriptor<?>> cached = Sets.newHashSet();
    for (T def : defs) {
        if (def != null) {
            cached.add(def.getDescriptor());
        }
    }

    // Wait for the change notifications to get processed. We expect listeners to get processed in the order in
    // which they subscribe.
    final CountDownLatch latch = new CountDownLatch(cached.size());
    SourceListener listener = new SourceListener() {
        private Set<DefDescriptor<?>> descriptors = Sets.newHashSet(cached);

        @Override
        public void onSourceChanged(DefDescriptor<?> source, SourceMonitorEvent event, String filePath) {
            if (descriptors.remove(source)) {
                latch.countDown();
            }
            if (descriptors.isEmpty()) {
                definitionService.unsubscribeToChangeNotification(this);
            }
        }
    };
    definitionService.subscribeToChangeNotification(listener);
    for (DefDescriptor<?> desc : cached) {
        definitionService.onSourceChanged(desc, SourceMonitorEvent.CHANGED, null);
    }
    if (!latch.await(CACHE_CLEARING_TIMEOUT_SECS, TimeUnit.SECONDS)) {
        throw new AuraRuntimeException(
                String.format("Timed out after %s seconds waiting for cached Aura definitions to clear: %s",
                        CACHE_CLEARING_TIMEOUT_SECS, defs));
    }
}

From source file:org.eclipse.virgo.ide.facet.core.FacetUtils.java

public static IProject[] getBundleProjects(IProject parProject) {
    Set<IProject> bundles = new HashSet<IProject>();
    if (isParProject(parProject)) {
        Par par = getParDefinition(parProject);
        if (par != null && par.getBundle() != null) {
            for (Bundle bundle : par.getBundle()) {
                IProject bundleProject = ResourcesPlugin.getWorkspace().getRoot()
                        .getProject(bundle.getSymbolicName());
                if (FacetUtils.isBundleProject(bundleProject)) {
                    bundles.add(bundleProject);
                }//from ww  w. ja va 2 s .  com
            }
        }
    }
    return (IProject[]) bundles.toArray(new IProject[bundles.size()]);
}

From source file:com.clustercontrol.performance.util.code.CollectorItemCodeTable.java

/**
 * ??facilityId????????//  w w w  . j  a va  2s  .c o  m
 * 
 * @param facilityId
 * @return
 * @throws HinemosUnknown
 */
public static List<CollectorItemInfo> getAvailableCollectorItemList(String facilityId) throws HinemosUnknown {
    m_log.debug("getAvailableCollectorItemList() facilityId = " + facilityId);

    // null check
    if (facilityId == null || "".equals(facilityId)) {
        return new ArrayList<CollectorItemInfo>();
    }

    // ???????
    Set<NodeDeviceInfo> deviceSet = getDeviceSetContainsAllNodes(facilityId);
    m_log.debug("getAvailableCollectorItemList() facilityId = " + facilityId + ", deviceSet size = "
            + deviceSet.size());

    // ?????
    Set<CollectorItemCodeMstData> itemCodeSet = getEnableCodeSet(facilityId);
    m_log.debug("getAvailableCollectorItemList() facilityId = " + facilityId + ", itemCodeSet size = "
            + itemCodeSet.size());

    // 
    List<CollectorItemInfo> list = new ArrayList<CollectorItemInfo>();

    for (CollectorItemCodeMstData itemCode : itemCodeSet) {
        m_log.debug("getAvailableCollectorItemList() facilityId = " + facilityId + ", itemCode = "
                + itemCode.getItemCode() + ", deviceSupport = " + itemCode.isDeviceSupport().booleanValue());

        CollectorItemInfo itemInfo = null;

        if (itemCode.isDeviceSupport().booleanValue()) {
            //???
            for (NodeDeviceInfo deviceInfo : deviceSet) {
                if (itemCode.getDeviceType() != null
                        && itemCode.getDeviceType().equals(deviceInfo.getDeviceType())) {
                    itemInfo = new CollectorItemInfo(null, itemCode.getItemCode(),
                            deviceInfo.getDeviceDisplayName());//collectorId is null

                    m_log.debug("getAvailableCollectorItemList() facilityId = " + facilityId + ", itemCode = "
                            + itemCode.getItemCode() + ", deviceDisplayName = "
                            + deviceInfo.getDeviceDisplayName());
                    list.add(itemInfo);
                }
            }

            // ALL Device?
            m_log.debug("getAvailableCollectorItemList() facilityId = " + facilityId + ", itemCode = "
                    + itemCode.getItemCode() + ", deviceDisplayName = " + PollingDataManager.ALL_DEVICE_NAME);
            itemInfo = new CollectorItemInfo(null, itemCode.getItemCode(), PollingDataManager.ALL_DEVICE_NAME);//collectorId is null
            list.add(itemInfo);

        } else {
            //????
            itemInfo = new CollectorItemInfo(null, itemCode.getItemCode(), "");//collectorId is null

            m_log.debug("getAvailableCollectorItemList() facilityId = " + facilityId + ", itemCode = "
                    + itemCode.getItemCode());
            list.add(itemInfo);
        }
    }

    // Sort
    Collections.sort(list, new Comparator<CollectorItemInfo>() {
        @Override
        public int compare(CollectorItemInfo o1, CollectorItemInfo o2) {
            // TODO Auto-generated method stub
            return o1.getItemCode().compareTo(o2.getItemCode());
        }
    });

    m_log.debug("getAvailableCollectorItemList() facilityId = " + facilityId + ", list size = " + list.size());
    return list;
}

From source file:com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.java

/**
 * Retrieve the array of excluded attributes. This array should be
 * constructed in the renderer class and then passed in to the
 * PassThruAttributeRenderer./*  w ww. ja va 2 s. co m*/
 *
 * @return a String array of excluded attributes.
 */
public static String[] getExcludesArray(Set excludes) {
    String[] excludesArray = new String[excludes.size()];
    excludes.toArray(excludesArray);
    return excludesArray;
}

From source file:com.gtcgroup.jped.valid.helper.JpvValidationUtilHelper.java

/**
 * This method performs Java Bean validation.
 *
 * @param <PO>/*from   ww w. j  a va 2s .com*/
 * @param <CO>
 * @param validatorPO
 * @return List<JpvErrorMessageTBD>
 */
public static <PO extends JpvBasicValidatorPO, CO extends JpvErrorMessagesTBD> CO validate(
        final PO validatorPO) {

    // Declare/Initialize
    final Set<ConstraintViolation<Object>> constraintViolationSet = new HashSet<ConstraintViolation<Object>>();
    final Object[] instancesToBeValidated = validatorPO.getInstancesToBeValidated();

    // Validate each instance... more than one error can occur.
    for (final Object instanceToBeValidated : instancesToBeValidated) {

        constraintViolationSet.addAll(
                JpvValidationUtilHelper.VALIDATOR.validate(instanceToBeValidated, validatorPO.getGroups()));

        // Check for stopping after the first error.
        if (validatorPO.isStopAfterFirstError() && constraintViolationSet.size() > 0) {
            break;
        }
    }

    @SuppressWarnings("unchecked")
    final CO errorMessagesCO = (CO) JpvValidationUtilHelper.convertConstraintViolationsToErrors(validatorPO,
            constraintViolationSet);

    return errorMessagesCO;
}

From source file:com.espertech.esper.epl.join.plan.NStreamOuterQueryPlanBuilder.java

/**
 * Verifies that the tree-like structure representing which streams join (lookup) into which sub-streams
 * is correct, ie. all streams are included and none are listed twice.
 * @param rootStream is the stream supplying the incoming event
 * @param streamsJoinedPerStream is keyed by the from-stream number and contains as values all
 * stream numbers of lookup into to-streams.
 *///from w  w  w  .  j a  va2s  .  c  o m
public static void verifyJoinedPerStream(int rootStream, Map<Integer, int[]> streamsJoinedPerStream) {
    Set<Integer> streams = new HashSet<Integer>();
    streams.add(rootStream);

    recursiveAdd(rootStream, rootStream, streamsJoinedPerStream, streams, true);

    if (streams.size() != streamsJoinedPerStream.size()) {
        throw new IllegalArgumentException(
                "Not all streams found, streamsJoinedPerStream=" + print(streamsJoinedPerStream));
    }
}

From source file:AmazonDynamoDBSample.java

private static void oneTimeAddContacts() {

    String firstNameLastName = "";
    String saltS = "";
    String ssnhash = "";

    Set<String> unionSet = new HashSet<>();
    unionSet.addAll(set1);/*from w w w.j  a va  2 s . com*/
    unionSet.addAll(set2);

    String strArrr[] = unionSet.toArray(new String[unionSet.size()]);

    int numEntries = saltHashMap.size();

    for (int i = 0; i < numEntries; i++) {
        firstNameLastName = strArrr[i];
        saltS = saltHashMap.get(strArrr[i]);
        ssnhash = hashedssnHashMap.get(strArrr[i]);

        Map<String, AttributeValue> item = newContactItem(firstNameLastName, saltS, ssnhash);
        PutItemRequest putItemRequest = new PutItemRequest("contacts-table", item);
        PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
    }
}

From source file:com.genentech.application.calcProps.SDFCalcProps.java

/**
 * Sort commands by dependencies ex. Solubility_Index requires cLogD7.4
 * Need to calculate cLogD7.4 before calculating solubility_index
 * cLogD7.4 command line need to appear before solubility_index command line
 *//*from ww w.  j a v a 2s .  c o  m*/
private static List<Calculator> sortByDependencies(ArrayList<Calculator> calculators,
        int noCalculatorSizeChangeCount) {
    int oldCalculatorsSize = calculators.size();
    List<Calculator> sorted = new ArrayList<Calculator>();

    if (!calculators.isEmpty()) {
        Calculator calc = calculators.remove(0); //get first element in list

        Set<String> reqCalculators = calc.getRequiredCalculators();
        if (reqCalculators.size() == 0) {
            // no dependencies, add to beginning
            sorted.add(0, calc);
        } else { //there are dependencies
            // are any dependencies left in the list of calculators to be sorted
            if (anyDependenciesInList(reqCalculators, calculators)) {
                calculators.add(calc); //add calc back to the end of the list to be sorted later
            } else {
                //they must be in the sorted list, add calc to the end of sorted list
                sorted.add(calc); //append to end of sorted calculators
            }
        }
    }
    if (calculators.size() == oldCalculatorsSize)
        noCalculatorSizeChangeCount = noCalculatorSizeChangeCount + 1;
    else
        noCalculatorSizeChangeCount = 0;

    /*If the number of calculators in the list has not going down within
      calculators.size() times*/
    if (noCalculatorSizeChangeCount == calculators.size() && calculators.size() > 0) {
        StringBuffer calculatorText = new StringBuffer();
        for (Calculator calc : calculators)
            calculatorText = calculatorText.append(calc.getName()).append(" ");
        throw new Error("There is a circular dependencies amongst following calculators: "
                + calculatorText.substring(0, calculatorText.length()));
    }

    //recursively sort remaining calculators
    if (calculators.size() > 0) {
        //append rest to sorted
        sorted.addAll(sortByDependencies(calculators, noCalculatorSizeChangeCount));
    }
    return sorted;
}

From source file:com.linkedin.pinot.controller.helix.core.UAutoRebalancer.java

public static boolean isTheSameMapping(Map oldMapping, Map nMapping) {
    if (oldMapping.size() != nMapping.size())
        return false;
    Map<String, Object> total = new HashedMap(oldMapping);
    total.putAll(nMapping);/*from  ww w .  j  a  va2 s .  c o  m*/
    if (total.size() != oldMapping.size())
        return false;
    Set<Boolean> result = new HashSet<Boolean>();
    for (Object oKey : oldMapping.keySet()) {
        Object oValue = oldMapping.get(oKey);
        if (oValue instanceof String) {
            result.add(oValue.equals(nMapping.get(oValue)));
        } else if (oValue instanceof Map) {
            result.add(isTheSameMapping((Map) oValue, (Map) nMapping.get(oKey)));
        }
    }
    if (result.size() != 1)
        return false;
    return true;
}

From source file:com.hoccer.tools.HttpHelper.java

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

    StringBuffer tmp = new StringBuffer();
    Set keys = pData.keySet();
    int idx = 0;/*ww  w  .  j  a  v a2 s . c o  m*/
    for (Object key : keys) {
        tmp.append(URLEncoder.encode(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();
}