Example usage for com.google.common.collect Multimap putAll

List of usage examples for com.google.common.collect Multimap putAll

Introduction

In this page you can find the example usage for com.google.common.collect Multimap putAll.

Prototype

boolean putAll(Multimap<? extends K, ? extends V> multimap);

Source Link

Document

Stores all key-value pairs of multimap in this multimap, in the order returned by multimap.entries() .

Usage

From source file:org.computer.whunter.rpm.parser.RpmSpecParser.java

/** 
 * The values of fields and macros can themselves contain the values of other directives. Search through the 
 * properties and replace these values if they are present.
 * //from   ww w . j a  v  a 2 s  .  co  m
 * @param properties the properties to modify by expanding any values
 */
private void expandReferences(Multimap<String, String> properties) {

    Map<Pattern, String> matcherPatterns = new HashMap<Pattern, String>();
    matcherPatterns.putAll(m_fieldReferenceMatcherPatterns);
    matcherPatterns.putAll(m_macroReferenceMatcherPatterns);

    Map<String, Pattern> replacePatterns = new HashMap<String, Pattern>();
    replacePatterns.putAll(m_fieldReferenceReplacePatterns);
    replacePatterns.putAll(m_macroReferenceReplacePatterns);

    Multimap<String, String> newProperties = ArrayListMultimap.create();
    for (Entry<String, String> property : properties.entries()) {
        String newValue = expandReferences(property.getValue().toString(), properties, matcherPatterns,
                replacePatterns);
        newProperties.put(property.getKey().toString(), newValue);
    }
    properties.clear();
    properties.putAll(newProperties);
}

From source file:org.sosy_lab.cpachecker.core.algorithm.PredicatedAnalysisAlgorithm.java

private Precision buildInitialPrecision(Collection<Precision> precisions, Precision initialPrecision)
        throws InterruptedException, RefinementFailedException {
    if (precisions.size() == 0) {
        return initialPrecision;
    }//  www  .ja  v a 2 s  . co  m

    Multimap<Pair<CFANode, Integer>, AbstractionPredicate> locationInstancPreds = HashMultimap.create();
    Multimap<CFANode, AbstractionPredicate> localPreds = HashMultimap.create();
    Multimap<String, AbstractionPredicate> functionPreds = HashMultimap.create();
    Collection<AbstractionPredicate> globalPreds = new HashSet<>();

    Collection<PredicatePrecision> seenPrecisions = new HashSet<>();

    // add initial precision
    PredicatePrecision predPrec = Precisions.extractPrecisionByType(initialPrecision, PredicatePrecision.class);
    locationInstancPreds.putAll(predPrec.getLocationInstancePredicates());
    localPreds.putAll(predPrec.getLocalPredicates());
    functionPreds.putAll(predPrec.getFunctionPredicates());
    globalPreds.addAll(predPrec.getGlobalPredicates());

    seenPrecisions.add(predPrec);

    // add further precision information obtained during refinement
    for (Precision nextPrec : precisions) {
        predPrec = Precisions.extractPrecisionByType(nextPrec, PredicatePrecision.class);

        shutdownNotifier.shutdownIfNecessary();

        if (!seenPrecisions.contains(predPrec)) {
            seenPrecisions.add(predPrec);
            locationInstancPreds.putAll(predPrec.getLocationInstancePredicates());
            localPreds.putAll(predPrec.getLocalPredicates());
            functionPreds.putAll(predPrec.getFunctionPredicates());
            globalPreds.addAll(predPrec.getGlobalPredicates());
        }
    }

    // construct new predicate precision
    PredicatePrecision newPredPrec = new PredicatePrecision(locationInstancPreds, localPreds, functionPreds,
            globalPreds);

    try {
        // assure that refinement fails if same path is encountered twice and precision not refined on that path
        if (repeatedFailure && noNewPredicates(oldPrecision, newPredPrec)) {
            throw new RefinementFailedException(Reason.RepeatedCounterexample, pathToFailure);
        }
    } catch (SolverException e) {
        throw new RefinementFailedException(Reason.InterpolationFailed, pathToFailure, e);
    }

    return Precisions.replaceByType(initialPrecision, newPredPrec,
            Predicates.instanceOf(PredicatePrecision.class));
}

From source file:org.eclipse.sirius.business.internal.session.danalysis.SessionResourcesSynchronizer.java

private Multimap<ResourceStatus, Resource> getImpactingNewStatuses(Collection<ResourceStatusChange> changes) {
    Multimap<ResourceStatus, Resource> impactingNewStatuses = LinkedHashMultimap.create();
    Multimap<ResourceStatus, Resource> representationResourcesNewStatuses = LinkedHashMultimap.create();
    Iterable<Resource> semanticOrControlledresources = getAllSemanticResources();
    Set<Resource> representationResources = session.getAllSessionResources();
    for (ResourceStatusChange change : changes) {
        if (session.isResourceOfSession(change.getResource(), semanticOrControlledresources)) {
            impactingNewStatuses.put(change.getNewStatus(), change.getResource());
        } else if (session.isResourceOfSession(change.getResource(), representationResources)) {
            representationResourcesNewStatuses.put(change.getNewStatus(), change.getResource());
        }/*from  w  w  w .j av a2 s.c o m*/
    }
    // Add session resource impacting status after semantic ones.
    impactingNewStatuses.putAll(representationResourcesNewStatuses);
    return impactingNewStatuses;
}

From source file:com.enonic.cms.store.dao.ResourceUsageDaoImpl.java

public Multimap<ResourceKey, ResourceReferencer> getUsedBy(ResourceKey resourceKey) {

    Multimap<ResourceKey, ResourceReferencer> usedBy = HashMultimap.create();

    for (PortletEntity obj : contentObjectDao.findByStyle(resourceKey)) {
        usedBy.put(resourceKey, new ResourceReferencer(obj, ResourceReferencerType.CONTENT_OBJECT_STYLE));
    }//from   w ww. java 2 s .  c o m
    for (PortletEntity obj : contentObjectDao.findByBorder(resourceKey)) {
        usedBy.put(resourceKey, new ResourceReferencer(obj, ResourceReferencerType.CONTENT_OBJECT_BORDER));
    }
    for (ContentTypeEntity obj : contentTypeDao.findByCSS(resourceKey)) {
        usedBy.put(resourceKey, new ResourceReferencer(obj, ResourceReferencerType.CONTENT_TYPE_CSS));
    }
    for (PageTemplateEntity obj : pageTemplateDao.findByStyle(resourceKey)) {
        usedBy.put(resourceKey, new ResourceReferencer(obj, ResourceReferencerType.PAGE_TEMPLATE_STYLE));
    }
    for (PageTemplateEntity obj : pageTemplateDao.findByCSS(resourceKey)) {
        usedBy.put(resourceKey, new ResourceReferencer(obj, ResourceReferencerType.PAGE_TEMPLATE_CSS));
    }

    usedBy.putAll(getUsedBySites(resourceKey));

    return usedBy;
}

From source file:org.sosy_lab.cpachecker.core.algorithm.AnalysisWithRefinableEnablerCPAAlgorithm.java

private PredicatePrecision builtNewPredicatePrecision(final Precision initialPrecision,
        final Collection<Precision> pReachedSetPrecisions) throws InterruptedException {
    Multimap<Pair<CFANode, Integer>, AbstractionPredicate> locationInstancPreds = HashMultimap.create();
    Multimap<CFANode, AbstractionPredicate> localPreds = HashMultimap.create();
    Multimap<String, AbstractionPredicate> functionPreds = HashMultimap.create();
    Collection<AbstractionPredicate> globalPreds = new HashSet<>();

    Collection<PredicatePrecision> seenPrecisions = new HashSet<>();

    // add initial precision
    PredicatePrecision predPrec = Precisions.extractPrecisionByType(initialPrecision, PredicatePrecision.class);
    locationInstancPreds.putAll(predPrec.getLocationInstancePredicates());
    localPreds.putAll(predPrec.getLocalPredicates());
    functionPreds.putAll(predPrec.getFunctionPredicates());
    globalPreds.addAll(predPrec.getGlobalPredicates());

    seenPrecisions.add(predPrec);//from   ww w .  j  a  v  a 2  s .c  o  m

    // add further precision information obtained during refinement
    for (Precision nextPrec : pReachedSetPrecisions) {
        predPrec = Precisions.extractPrecisionByType(nextPrec, PredicatePrecision.class);

        shutdownNotifier.shutdownIfNecessary();

        if (!seenPrecisions.contains(predPrec)) {
            seenPrecisions.add(predPrec);
            locationInstancPreds.putAll(predPrec.getLocationInstancePredicates());
            localPreds.putAll(predPrec.getLocalPredicates());
            functionPreds.putAll(predPrec.getFunctionPredicates());
            globalPreds.addAll(predPrec.getGlobalPredicates());
        }
    }

    // construct new predicate precision
    return new PredicatePrecision(locationInstancPreds, localPreds, functionPreds, globalPreds);
}

From source file:org.mqnaas.core.impl.BindingManagement.java

@Override
public Multimap<Class<? extends IApplication>, IService> getServices(IResource resource) {

    if (resource == null)
        throw new NullPointerException("Can't get services of a null resource.");

    log.debug("Getting all services from resource " + resource.getId());

    Multimap<Class<? extends IApplication>, IService> services = ArrayListMultimap.create();

    for (CapabilityInstance representation : filterResolved(getCapabilityInstancesBoundToResource(resource))) {
        services.putAll(representation.getServices());
    }/*  w w  w.  j  a v a  2  s.c  om*/

    log.trace("Resource " + resource.getId() + " services: " + services.keySet());

    return services;
}

From source file:com.dpbymqn.fsm.manager.FsmManager.java

private String transitAtomic(StatefulObject st, String toState) {
    String currentState = getState(st);
    String nextState = toState;/*from   w  ww  . j  a v a2 s  . com*/
    // do pre-callbacks
    Collection<TransitionCallback> preCallbacks = new ArrayList<TransitionCallback>();
    synchronized (classPreTrCallbackMap) {
        for (Class<?> clz : lazySuper.get(st.getClass())) {
            final Map<String, Multimap<String, TransitionCallback>> clzPreStateFromMap = classPreTrCallbackMap
                    .get(clz);
            if (clzPreStateFromMap != null) {
                if (clzPreStateFromMap.get(null) != null || clzPreStateFromMap.get(currentState) != null) {
                    Multimap<String, TransitionCallback> clzStateToMap = LinkedHashMultimap.create();
                    Multimap<String, TransitionCallback> clzStateToMap1 = clzPreStateFromMap.get(currentState);
                    Multimap<String, TransitionCallback> clzStateToMap0 = clzPreStateFromMap.get(null);
                    if (clzStateToMap1 != null) {
                        clzStateToMap.putAll(clzStateToMap1);
                    }
                    if (clzStateToMap0 != null) {
                        clzStateToMap.putAll(clzStateToMap0);
                    }
                    if (clzStateToMap.containsKey(nextState) && clzStateToMap.get(nextState) != null) {
                        preCallbacks.addAll(clzStateToMap.get(nextState));
                    }
                    if (clzStateToMap.get(null) != null) {
                        preCallbacks.addAll(clzStateToMap.get(null));
                    }
                }
            }
        }
    }
    synchronized (instancePreTrCallbackMap) {
        if (instancePreTrCallbackMap.containsKey(st)) {
            for (final Map<String, Multimap<String, TransitionCallback>> instPreStateFromMap : instancePreTrCallbackMap
                    .get(st).values()) {
                if (instPreStateFromMap != null) {
                    if (instPreStateFromMap.get(null) != null
                            || instPreStateFromMap.get(currentState) != null) {
                        Multimap<String, TransitionCallback> instStateToMap = LinkedHashMultimap.create();
                        Multimap<String, TransitionCallback> instStateToMap1 = instPreStateFromMap
                                .get(currentState);
                        Multimap<String, TransitionCallback> instStateToMap0 = instPreStateFromMap.get(null);
                        if (instStateToMap1 != null) {
                            instStateToMap.putAll(instStateToMap1);
                        }
                        if (instStateToMap0 != null) {
                            instStateToMap.putAll(instStateToMap0);
                        }
                        if (instStateToMap.containsKey(nextState) && instStateToMap.get(nextState) != null) {
                            preCallbacks.addAll(instStateToMap.get(nextState));
                        }
                        if (instStateToMap.get(null) != null) {
                            preCallbacks.addAll(instStateToMap.get(null));
                        }
                    }
                }
            }
        }
    }
    // - call pre callbacks 
    // this "if" would prevent calling Pre methods when the transition is triggered by the newly registered listener(s)
    //        if (currentState == null || !currentState.equals(nextState)) {
    for (TransitionCallback trCallback : preCallbacks) {
        trCallback.onTransition(st, currentState, nextState);
    }
    //        }
    // move to next state

    setState(st, nextState);
    // post-callbacks
    // - collect post callbacks
    Collection<TransitionCallback> postCallbacks = new ArrayList<TransitionCallback>();
    synchronized (classPostTrCallbackMap) {
        for (Class<?> clz : lazySuper.get(st.getClass())) {
            final Map<String, Multimap<String, TransitionCallback>> clzPostStateFromMap = classPostTrCallbackMap
                    .get(clz);
            if (clzPostStateFromMap != null) {
                if (clzPostStateFromMap.get(null) != null || clzPostStateFromMap.get(currentState) != null) {
                    Multimap<String, TransitionCallback> clzStateToMap = LinkedHashMultimap.create();
                    Multimap<String, TransitionCallback> clzStateToMap1 = clzPostStateFromMap.get(currentState);
                    Multimap<String, TransitionCallback> clzStateToMap0 = clzPostStateFromMap.get(null);
                    if (clzStateToMap1 != null) {
                        clzStateToMap.putAll(clzStateToMap1);
                    }
                    if (clzStateToMap0 != null) {
                        clzStateToMap.putAll(clzStateToMap0);
                    }
                    if (clzStateToMap.containsKey(nextState) && clzStateToMap.get(nextState) != null) {
                        postCallbacks.addAll(clzStateToMap.get(nextState));
                    }
                    if (clzStateToMap.get(null) != null) {
                        postCallbacks.addAll(clzStateToMap.get(null));
                    }
                }
            }
        }
    }
    synchronized (instancePostTrCallbackMap) {
        if (instancePostTrCallbackMap.containsKey(st)) {
            for (final Map<String, Multimap<String, TransitionCallback>> instPostStateFromMap : instancePostTrCallbackMap
                    .get(st).values()) {
                if (instPostStateFromMap != null) {
                    if (instPostStateFromMap.get(null) != null
                            || instPostStateFromMap.get(currentState) != null) {
                        Multimap<String, TransitionCallback> instStateToMap = LinkedHashMultimap.create();
                        Multimap<String, TransitionCallback> instStateToMap1 = instPostStateFromMap
                                .get(currentState);
                        Multimap<String, TransitionCallback> instStateToMap0 = instPostStateFromMap.get(null);
                        if (instStateToMap1 != null) {
                            instStateToMap.putAll(instStateToMap1);
                        }
                        if (instStateToMap0 != null) {
                            instStateToMap.putAll(instStateToMap0);
                        }
                        if (instStateToMap.containsKey(nextState) && instStateToMap.get(nextState) != null) {
                            postCallbacks.addAll(instStateToMap.get(nextState));
                        }
                        if (instStateToMap.get(null) != null) {
                            postCallbacks.addAll(instStateToMap.get(null));
                        }
                    }
                }
            }
        }
    }
    // - call post callbacks
    for (TransitionCallback trCallback : postCallbacks) {
        trCallback.onTransition(st, currentState, nextState);
    }
    // check decisions
    Set<String> decisions = new HashSet<String>();
    // collect decision callbacks
    Multimap<String, DecisionCallback> possibleStates = HashMultimap.create();
    synchronized (classDecCallbackMap) {
        for (Class<?> clz : lazySuper.get(st.getClass())) {
            final Map<String, Multimap<String, DecisionCallback>> clzDecStateFromMap = classDecCallbackMap
                    .get(clz);
            if (clzDecStateFromMap != null) {
                if (clzDecStateFromMap.get(null) != null || clzDecStateFromMap.get(nextState) != null) {
                    Multimap<String, DecisionCallback> clzStateToMap1 = clzDecStateFromMap.get(nextState);
                    Multimap<String, DecisionCallback> clzStateToMap0 = clzDecStateFromMap.get(null);
                    if (clzStateToMap1 != null) {
                        possibleStates.putAll(clzStateToMap1);
                    }
                    if (clzStateToMap0 != null) {
                        possibleStates.putAll(clzStateToMap0);
                    }
                }
            }
        }
    }
    synchronized (instanceDecCallbackMap) {
        if (instanceDecCallbackMap.containsKey(st)) {
            for (final Map<String, Multimap<String, DecisionCallback>> instDecStateFromMap : instanceDecCallbackMap
                    .get(st).values()) {
                if (instDecStateFromMap != null) {
                    if (instDecStateFromMap.get(null) != null || instDecStateFromMap.get(nextState) != null) {
                        Multimap<String, DecisionCallback> instStateToMap1 = instDecStateFromMap.get(nextState);
                        Multimap<String, DecisionCallback> instStateToMap0 = instDecStateFromMap.get(null);
                        if (instStateToMap1 != null) {
                            possibleStates.putAll(instStateToMap1);
                        }
                        if (instStateToMap0 != null) {
                            possibleStates.putAll(instStateToMap0);
                        }
                    }
                }
            }
        }
    }
    // - call post callbacks
    for (Map.Entry<String, DecisionCallback> e : possibleStates.entries()) {
        DecisionCallback decCallback = e.getValue();
        String intoState = e.getKey();
        String suggest = decCallback.query(st, nextState);
        if (suggest != null) {
            decisions.add(suggest);
        } else {
            if (intoState != null && !intoState.equals(nextState)) {
                final Boolean query = decCallback.query(st, nextState, intoState);
                if (query != null && query) {
                    decisions.add(intoState);
                }
            }
        }
    }
    if (decisions.size() == 1) {
        return decisions.iterator().next();
    }
    return null;
}

From source file:org.jclouds.rest.internal.RestAnnotationProcessor.java

@Override
public GeneratedHttpRequest apply(Invocation invocation) {
    checkNotNull(invocation, "invocation");
    inputParamValidator.validateMethodParametersOrThrow(invocation);

    Optional<URI> endpoint = Optional.absent();
    HttpRequest r = findOrNull(invocation.getArgs(), HttpRequest.class);
    if (r != null) {
        endpoint = Optional.fromNullable(r.getEndpoint());
        if (endpoint.isPresent())
            logger.trace("using endpoint %s from invocation.getArgs() for %s", endpoint, invocation);
    } else if (caller != null) {
        endpoint = getEndpointFor(caller);
        if (endpoint.isPresent())
            logger.trace("using endpoint %s from caller %s for %s", endpoint, caller, invocation);
        else/*from   w  w w.j a va2  s . co  m*/
            endpoint = findEndpoint(invocation);
    } else {
        endpoint = findEndpoint(invocation);
    }

    if (!endpoint.isPresent())
        throw new NoSuchElementException(format("no endpoint found for %s", invocation));
    GeneratedHttpRequest.Builder requestBuilder = GeneratedHttpRequest.builder().invocation(invocation)
            .caller(caller);
    String requestMethod = null;
    if (r != null) {
        requestMethod = r.getMethod();
        requestBuilder.fromHttpRequest(r);
    } else {
        requestMethod = tryFindHttpMethod(invocation.getInvokable()).get();
        requestBuilder.method(requestMethod);
    }

    requestBuilder.filters(getFiltersIfAnnotated(invocation));

    Multimap<String, Object> tokenValues = LinkedHashMultimap.create();

    tokenValues.put(Constants.PROPERTY_API_VERSION, apiVersion);
    tokenValues.put(Constants.PROPERTY_BUILD_VERSION, buildVersion);
    // URI template in rfc6570 form
    UriBuilder uriBuilder = uriBuilder(endpoint.get().toString());

    overridePathEncoding(uriBuilder, invocation);

    if (caller != null)
        tokenValues.putAll(addPathAndGetTokens(caller, uriBuilder));
    tokenValues.putAll(addPathAndGetTokens(invocation, uriBuilder));
    Multimap<String, Object> formParams;
    if (caller != null) {
        formParams = addFormParams(tokenValues, caller);
        formParams.putAll(addFormParams(tokenValues, invocation));
    } else {
        formParams = addFormParams(tokenValues, invocation);
    }
    Multimap<String, Object> queryParams = addQueryParams(tokenValues, invocation);
    Multimap<String, String> headers = buildHeaders(tokenValues, invocation);

    if (r != null)
        headers.putAll(r.getHeaders());

    if (shouldAddHostHeader(invocation)) {
        StringBuilder hostHeader = new StringBuilder(endpoint.get().getHost());
        if (endpoint.get().getPort() != -1)
            hostHeader.append(":").append(endpoint.get().getPort());
        headers.put(HOST, hostHeader.toString());
    }

    Payload payload = null;
    for (HttpRequestOptions options : findOptionsIn(invocation)) {
        injector.injectMembers(options);// TODO test case
        for (Entry<String, String> header : options.buildRequestHeaders().entries()) {
            headers.put(header.getKey(), replaceTokens(header.getValue(), tokenValues));
        }
        for (Entry<String, String> query : options.buildQueryParameters().entries()) {
            queryParams.put(query.getKey(), replaceTokens(query.getValue(), tokenValues));
        }
        for (Entry<String, String> form : options.buildFormParameters().entries()) {
            formParams.put(form.getKey(), replaceTokens(form.getValue(), tokenValues));
        }

        String pathSuffix = options.buildPathSuffix();
        if (pathSuffix != null) {
            uriBuilder.appendPath(pathSuffix);
        }
        String stringPayload = options.buildStringPayload();
        if (stringPayload != null)
            payload = Payloads.newStringPayload(stringPayload);
    }

    if (queryParams.size() > 0) {
        uriBuilder.query(queryParams);
    }

    requestBuilder.headers(filterOutContentHeaders(headers));

    requestBuilder.endpoint(uriBuilder.build(convertUnsafe(tokenValues)));

    if (payload == null) {
        PayloadEnclosing payloadEnclosing = findOrNull(invocation.getArgs(), PayloadEnclosing.class);
        payload = (payloadEnclosing != null) ? payloadEnclosing.getPayload()
                : findOrNull(invocation.getArgs(), Payload.class);
    }

    List<? extends Part> parts = getParts(invocation,
            ImmutableMultimap.<String, Object>builder().putAll(tokenValues).putAll(formParams).build());

    if (parts.size() > 0) {
        if (formParams.size() > 0) {
            parts = newLinkedList(concat(transform(formParams.entries(), ENTRY_TO_PART), parts));
        }
        payload = new MultipartForm(MultipartForm.BOUNDARY, parts);
    } else if (formParams.size() > 0) {
        payload = Payloads
                .newUrlEncodedFormPayload(transformValues(formParams, NullableToStringFunction.INSTANCE));
    } else if (headers.containsKey(CONTENT_TYPE) && !HttpRequest.NON_PAYLOAD_METHODS.contains(requestMethod)) {
        if (payload == null)
            payload = Payloads.newByteArrayPayload(new byte[] {});
        payload.getContentMetadata().setContentType(get(headers.get(CONTENT_TYPE), 0));
    }
    if (payload != null) {
        requestBuilder.payload(payload);
    }
    GeneratedHttpRequest request = requestBuilder.build();

    org.jclouds.rest.MapBinder mapBinder = getMapPayloadBinderOrNull(invocation);
    if (mapBinder != null) {
        Map<String, Object> mapParams;
        if (caller != null) {
            mapParams = buildPayloadParams(caller);
            mapParams.putAll(buildPayloadParams(invocation));
        } else {
            mapParams = buildPayloadParams(invocation);
        }
        if (invocation.getInvokable().isAnnotationPresent(PayloadParams.class)) {
            PayloadParams params = invocation.getInvokable().getAnnotation(PayloadParams.class);
            addMapPayload(mapParams, params, headers);
        }
        request = mapBinder.bindToRequest(request, mapParams);
    } else {
        request = decorateRequest(request);
    }

    if (request.getPayload() != null) {
        contentMetadataCodec.fromHeaders(request.getPayload().getContentMetadata(), headers);
    }
    utils.checkRequestHasRequiredProperties(request);
    return request;
}

From source file:com.yahoo.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl.java

private Multimap<Long, ResourceUnit> getFinalCandidatesNoPolicy(Multimap<Long, ResourceUnit> shared) {
    Multimap<Long, ResourceUnit> finalCandidates = TreeMultimap.create();

    finalCandidates.putAll(shared);
    return finalCandidates;
}

From source file:com.yahoo.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl.java

private Multimap<Long, ResourceUnit> getFinalCandidatesWithPolicy(NamespaceName namespace,
        Multimap<Long, ResourceUnit> primaries, Multimap<Long, ResourceUnit> shared) {
    Multimap<Long, ResourceUnit> finalCandidates = TreeMultimap.create();
    // if not enough primary then it should be union of primaries and secondaries
    finalCandidates.putAll(primaries);
    if (policies.shouldFailoverToSecondaries(namespace, primaries.size())) {
        log.debug(//from   ww w.j  ava  2 s. c  o m
                "Not enough of primaries [{}] available for namespace - [{}], "
                        + "adding shared [{}] as possible candidate owners",
                primaries.size(), namespace.toString(), shared.size());
        finalCandidates.putAll(shared);
    }
    return finalCandidates;
}