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

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

Introduction

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

Prototype

Set<K> keySet();

Source Link

Document

Returns a view collection of all distinct keys contained in this multimap.

Usage

From source file:com.netxforge.netxstudio.server.logic.reporting.ResourceReportingEngine.java

/**
 * @param sheet// w ww.ja  v  a 2s.  c o m
 * @param rowIndex
 */
public void writeTS(Sheet sheet, int rowIndex) {
    // Get the timestamps by week numbers.
    Multimap<Integer, XMLGregorianCalendar> timeStampsByWeek = StudioUtils
            .hourlyTimeStampsByWeekFor(this.getPeriod());

    Row tsRow = this.rowForIndex(sheet, rowIndex);
    System.out.println("Analyzed weeks " + timeStampsByWeek.keySet().size());

    int column = NODE_COLUMN + 4;

    // TODO, Should reverse the weeks.

    // build an index of colums and timestamps.
    for (int i : timeStampsByWeek.keySet()) {
        Collection<XMLGregorianCalendar> collection = timeStampsByWeek.get(i);

        List<Date> weekTS = NonModelUtils.transformXMLDateToDate(collection);
        Collections.sort(weekTS);

        // CB Apply a check, if our usemodel for POI is based on HSSF which
        // is < '07 excel.
        // if( weekTS.size() + column >= 256 ){
        // // With HSSF POI model, we can't do more than 256 columns
        // break;
        // }

        // Write the timestamps from the specified column.
        column = this.writeTS(columnTS, sheet, tsRow, weekTS, i, column);

        System.out.println(weekTS);

    }
}

From source file:org.gbif.common.search.builder.SolrQueryBuilder.java

/**
 * Sets the query filters.//from   w w  w .  j a  va2 s. c  o  m
 * Takes a {@link Multimap} and produces a Solr filter query containing the filtering criteria.
 * The output string will be in the format: (param1:vp1.1 OR param1:vp1.2) AND (param2:vf2.1 OR param2:vp2.2)...
 * The param-i key are taken from the key sets of the map and the vpi.j (value j of param i) are the entry set of the
 * map.
 * 
 * @return the String containing a Solr filter query
 */
private void setQueryFilter(final SearchRequest<P> searchRequest, SolrQuery solrQuery) {
    final Multimap<P, String> params = searchRequest.getParameters();
    final boolean isFacetedRequest = FacetedSearchRequest.class.isAssignableFrom(searchRequest.getClass());
    if (params != null) {
        BiMap<P, String> fieldsPropertiesMapInv = facetFieldsPropertiesMap.inverse();
        for (P param : params.keySet()) {
            if (param != null && !fieldsPropertiesMapInv.containsKey(param)) {
                LOG.warn("Unknown search parameter {}", param);
                continue;
            }
            // solr field for this parameter
            final String solrFieldName = fieldsPropertiesMapInv.get(param);

            List<String> filterQueriesComponents = Lists.newArrayList();
            for (String paramValue : params.get(param)) {
                // Negate expression is removed if it is present
                final String interpretedValue = getInterpretedValue(param.type(), removeNegation(paramValue));
                final String queryComponent = PARAMS_JOINER.join(solrFieldName, interpretedValue);

                filterQueriesComponents.add(isNegated(paramValue) ? NOT_OP + queryComponent : queryComponent);
            }
            if (!filterQueriesComponents.isEmpty()) { // there are filter queries for this parameter
                StringBuilder filterQuery = buildFilterQuery(isFacetedRequest, solrFieldName,
                        filterQueriesComponents);
                solrQuery.addFilterQuery(filterQuery.toString());
            }

        }
    }
}

From source file:org.onosproject.net.flowext.impl.FlowRuleExtManager.java

/**
 * Applies a batch operation of FlowRules.
 * this batch can be divided into many sub-batch by deviceId
 *
 * @param batch batch operation to apply
 * @return future indicating the state of the batch operation
 *//*w  ww.j a v  a  2s  .  c  om*/
@Override
public Future<FlowExtCompletedOperation> applyBatch(FlowRuleBatchRequest batch) {
    // TODO group the Collection into sub-Collection by deviceId
    Multimap<DeviceId, FlowRuleBatchEntry> perDeviceBatches = ArrayListMultimap.create();
    for (FlowRuleBatchEntry fbe : batch.ops()) {
        FlowRule flowRule = fbe.target();
        perDeviceBatches.put(flowRule.deviceId(), fbe);
    }

    List<Future<FlowExtCompletedOperation>> futures = Lists.newArrayList();
    for (DeviceId deviceId : perDeviceBatches.keySet()) {
        Collection<FlowRuleBatchEntry> flows = perDeviceBatches.get(deviceId);
        //FIXME if there can be collisions, than converting the collection to a set will drop flow rules
        FlowRuleBatchRequest subBatch = new FlowRuleBatchRequest(batch.batchId(), Sets.newHashSet(flows));
        Future<FlowExtCompletedOperation> future = router.applySubBatch(subBatch);
        futures.add(future);
    }
    return new FlowRuleBatchFuture(batch.batchId(), futures);
}

From source file:com.github.autermann.wps.commons.WPS.java

private Repository _addAlgorithmRepository(Class<? extends IAlgorithmRepository> repoClass,
        Multimap<String, String> properties) {
    Repository repo = getRepository(repoClass).or(getConfig().getAlgorithmRepositoryList().addNewRepository());
    repo.setActive(true);/*from  w  w w.j  a  v  a  2 s  .  c  om*/
    repo.setClassName(repoClass.getName());
    repo.setName(repoClass.getName());
    if (properties != null) {
        for (String property : properties.keySet()) {
            for (String value : properties.get(property)) {
                Property p = repo.addNewProperty();
                p.setActive(true);
                p.setName(property);
                p.setStringValue(value);
            }
        }
    }
    return repo;
}

From source file:org.sosy_lab.java_smt.utils.UfElimination.java

/**
 * Applies the Ackermann transformation to the given {@link Formula} with respect to the {@link
 * Result} of another formula. Quantified formulas are not supported.
 *
 * @param pF the {@link Formula} to remove all Ufs from
 * @param pOtherResult result of eliminating Ufs in another {@link BooleanFormula}
 * @return the {@link Result} of the Ackermannization
 *///from   www  .  j av a  2  s  .c o m
public Result eliminateUfs(BooleanFormula pF, Result pOtherResult) {
    checkArgument(!isQuantified(pF));
    BooleanFormula f;
    if (!pOtherResult.getSubstitution().isEmpty()) {
        f = fmgr.substitute(pF, pOtherResult.getSubstitution());
    } else {
        f = pF;
    }

    int depth = getNestingDepthOfUfs(f);
    Multimap<FunctionDeclaration<?>, UninterpretedFunctionApplication> ufs = findUFs(f);
    ufs = merge(ufs, pOtherResult);

    ImmutableMap.Builder<Formula, Formula> substitutionsBuilder = ImmutableMap.builder();
    List<BooleanFormula> extraConstraints = new ArrayList<>();

    for (FunctionDeclaration<?> function : ufs.keySet()) {
        List<UninterpretedFunctionApplication> applications = new ArrayList<>(ufs.get(function));
        for (int idx1 = 0; idx1 < applications.size(); idx1++) {
            UninterpretedFunctionApplication application = applications.get(idx1);

            Formula uf = application.getFormula();
            List<Formula> args = application.getArguments();

            Formula substitution = application.getSubstitution();
            substitutionsBuilder.put(uf, substitution);

            for (int idx2 = idx1 + 1; idx2 < applications.size(); idx2++) {
                UninterpretedFunctionApplication application2 = applications.get(idx2);
                List<Formula> otherArgs = application2.getArguments();

                /*
                 * Add constraints to enforce functional consistency.
                 */
                Verify.verify(args.size() == otherArgs.size());
                Collection<BooleanFormula> argumentEquality = new ArrayList<>(args.size());
                for (int i = 0; i < args.size(); i++) {
                    Formula arg1 = args.get(i);
                    Formula arg2 = otherArgs.get(i);
                    argumentEquality.add(makeEqual(arg1, arg2));
                }

                BooleanFormula functionEquality = makeEqual(substitution, application2.getSubstitution());
                extraConstraints.add(bfmgr.implication(bfmgr.and(argumentEquality), functionEquality));
            }
        }
    }

    // Get rid of UFs.
    ImmutableMap<Formula, Formula> substitutions = substitutionsBuilder.build();
    BooleanFormula formulaWithoutUFs = fmgr.substitute(f, substitutions);

    // substitute all UFs in the additional constraints,
    // required if UFs are arguments of UFs, e.g. uf(uf(1, 2), 2)
    for (int i = 0; i < depth; i++) {
        extraConstraints = extraConstraints.stream().map(c -> fmgr.substitute(c, substitutions))
                .collect(Collectors.toList());
    }

    Map<Formula, Formula> otherSubstitution = difference(pOtherResult.getSubstitution(), substitutions)
            .entriesOnlyOnLeft();
    substitutionsBuilder.putAll(otherSubstitution);
    ImmutableMap<Formula, Formula> allSubstitutions = substitutionsBuilder.build();
    BooleanFormula constraints = bfmgr.and(extraConstraints);
    return new Result(formulaWithoutUFs, constraints, allSubstitutions, copyOf(ufs));
}

From source file:org.gradle.plugins.ide.idea.model.internal.IdeaDependenciesProvider.java

/** Looks for dependencies contained in all configurations to remove them from multimap and return as result. */
List<IdeDependencyKey<?, Dependency>> extractDependencies(
        Multimap<IdeDependencyKey<?, Dependency>, String> dependenciesToConfigs,
        Collection<String> configurations, Collection<String> minusConfigurations) {
    List<IdeDependencyKey<?, Dependency>> deps = new ArrayList<IdeDependencyKey<?, Dependency>>();
    List<IdeDependencyKey<?, Dependency>> minusDeps = new ArrayList<IdeDependencyKey<?, Dependency>>();
    for (IdeDependencyKey<?, Dependency> dependencyKey : dependenciesToConfigs.keySet()) {
        if (dependenciesToConfigs.get(dependencyKey).containsAll(configurations)) {
            boolean isInMinus = false;
            for (String minusConfiguration : minusConfigurations) {
                if (dependenciesToConfigs.get(dependencyKey).contains(minusConfiguration)) {
                    isInMinus = true;/*from  w w  w  .  j a v  a  2 s .  c  om*/
                    break;
                }
            }
            if (!isInMinus) {
                deps.add(dependencyKey);
            } else {
                minusDeps.add(dependencyKey);
            }
        }
    }
    for (IdeDependencyKey<?, Dependency> key : Iterables.concat(deps, minusDeps)) {
        dependenciesToConfigs.removeAll(key);
    }
    return deps;
}

From source file:io.nuun.kernel.core.internal.scanner.disk.ClasspathScannerDisk.java

@Override
public void scanClasspathForAnnotationRegex(final String annotationTypeRegex, final Callback callback) {
    //        Reflections reflections = new Reflections(configurationBuilder().addUrls(computeUrls()).setScanners(new TypeAnnotationsScanner()));

    queue(new ScannerCommand() {
        @Override//from  w  w w  .  j  a  va  2 s.  c o  m
        public void execute(Reflections reflections) {
            Store store = reflections.getStore();

            Multimap<String, String> multimap = store.get(TypeAnnotationsScanner.class);

            List<String> key = new ArrayList<String>();
            for (String loopKey : multimap.keySet()) {
                if (loopKey.matches(annotationTypeRegex)) {
                    key.add(loopKey);
                }
            }

            Collection<Class<?>> typesAnnotatedWith = new HashSet<Class<?>>();

            for (String k : key) {
                Collection<String> collectionOfString = multimap.get(k);
                typesAnnotatedWith.addAll(toClasses(collectionOfString));
            }
            callback.callback(postTreatment(typesAnnotatedWith));
        }

        @Override
        public Scanner scanner() {
            return new TypeAnnotationsScanner();
        }

    });
}

From source file:gg.pistol.sweeper.core.Analyzer.java

private SweeperCountImpl computeCount(TargetImpl root, Multimap<String, TargetImpl> hashDups)
        throws SweeperAbortException {
    log.trace("Counting {} hash duplicates.", hashDups.size());

    int totalTargets = root.getTotalTargets();
    int totalTargetFiles = root.getTotalTargetFiles();
    long totalSize = root.getSize();

    int duplicateTargets = 0;
    int duplicateTargetFiles = 0;
    long duplicateSize = 0;

    // Filter the upper targets in order to have correct aggregate counting of duplicates. The hashDups can contain
    // targets that are children of other targets.
    Collection<TargetImpl> hashDupUpperTargets = filterUpperTargets(hashDups.values());

    // Group the duplicate targets by hash.
    Multimap<String, TargetImpl> dups = filterDuplicateHash(hashDupUpperTargets);

    for (String key : dups.keySet()) {
        Iterator<TargetImpl> iterator = dups.get(key).iterator();

        // Jump over the first value from a duplicate group because deleting all the others will make this one
        // a non-duplicate.
        iterator.next();//w  w  w.jav  a2  s. c  o m

        while (iterator.hasNext()) {
            TargetImpl target = iterator.next();
            duplicateTargets += target.getTotalTargets();
            duplicateTargetFiles += target.getTotalTargetFiles();
            duplicateSize += target.getSize();

            checkAbortFlag();
        }
    }

    SweeperCountImpl count = new SweeperCountImpl(totalTargets, totalTargetFiles, totalSize, duplicateTargets,
            duplicateTargetFiles, duplicateSize);

    return count;
}

From source file:ai.grakn.graql.internal.query.QueryAnswer.java

@Override
public Answer unify(Unifier unifier) {
    if (unifier.isEmpty())
        return this;
    Answer unified = new QueryAnswer();
    Multimap<Var, Concept> answerMultimap = HashMultimap.create();

    this.entrySet().forEach(e -> {
        Var var = e.getKey();
        Collection<Var> uvars = unifier.get(var);
        if (uvars.isEmpty()) {
            answerMultimap.put(var, e.getValue());
        } else {//from w  ww .  jav a  2s  .  c  o m
            uvars.forEach(uv -> answerMultimap.put(uv, e.getValue()));
        }
    });
    //non-ambiguous mapping
    if (answerMultimap.keySet().size() == answerMultimap.values().size()) {
        answerMultimap.entries().forEach(e -> unified.put(e.getKey(), e.getValue()));
    }

    return unified.setExplanation(this.getExplanation());
}

From source file:com.android.ide.common.res2.AbstractResourceRepository.java

@NonNull
public Collection<String> getItemsOfType(@NonNull ResourceType type) {
    synchronized (ITEM_MAP_LOCK) {
        Multimap<String, ResourceItem> map = getMap(type, false);
        if (map == null) {
            return Collections.emptyList();
        }//from www  . ja v  a2s.co m
        return Collections.unmodifiableCollection(map.keySet());
    }
}