Example usage for com.google.common.collect ImmutableSetMultimap inverse

List of usage examples for com.google.common.collect ImmutableSetMultimap inverse

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSetMultimap inverse.

Prototype

ImmutableSetMultimap inverse

To view the source code for com.google.common.collect ImmutableSetMultimap inverse.

Click Source Link

Usage

From source file:com.google.errorprone.bugpatterns.RemoveUnusedImports.java

@Override
public Description matchCompilationUnit(CompilationUnitTree compilationUnitTree, VisitorState state) {
    final ImmutableSetMultimap<ImportTree, Symbol> importedSymbols = getImportedSymbols(compilationUnitTree,
            state);//from w  w  w.j  a  v  a  2 s  .  c om

    if (importedSymbols.isEmpty()) {
        return NO_MATCH;
    }

    final Set<ImportTree> unusedImports = new HashSet<>(importedSymbols.keySet());
    new TreeSymbolScanner(JavacTrees.instance(state.context), state.getTypes()).scan(compilationUnitTree,
            new SymbolSink() {
                @Override
                public boolean keepScanning() {
                    return !unusedImports.isEmpty();
                }

                @Override
                public void accept(Symbol symbol) {
                    unusedImports.removeAll(importedSymbols.inverse().get(symbol));
                }
            });

    if (unusedImports.isEmpty()) {
        return NO_MATCH;
    }
    SuggestedFix.Builder fixBuilder = SuggestedFix.builder();
    for (ImportTree unusedImport : unusedImports) {
        fixBuilder.delete(unusedImport);
    }
    return describeMatch(unusedImports.iterator().next(), fixBuilder.build());
}

From source file:com.publictransitanalytics.scoregenerator.environment.StoredGrid.java

public StoredGrid(final SegmentFinder segmentFinder, final GeoBounds bounds, final int numLatitudeGridlines,
        final int numLongitudeGridlines, final InEnvironmentDetector detector,
        final Store<GridIdKey, GridInfo> gridInfoStore, final RangedStore<SectorKey, SectorInfo> sectorStore,
        final RangedStore<GridPointAssociationKey, GridPointAssociation> gridPointAssociationsStore)
        throws InterruptedException {

    final GridIdKey gridIdKey = new GridIdKey(bounds, numLatitudeGridlines, numLongitudeGridlines);
    final String gridId = gridIdKey.getKeyString();

    try {//ww w.  j a va  2  s  .c o  m
        final ImmutableSetMultimap<GridPoint, Sector> gridPointSectorMap;
        if (gridInfoStore.containsKey(gridIdKey)) {
            sectorTable = getSectorTable(gridId, sectorStore);
            allSectors = sectorTable.cellSet().stream().map(cell -> cell.getValue())
                    .collect(Collectors.toSet());
            final Map<String, Sector> sectorIdMap = allSectors.stream()
                    .collect(Collectors.toMap(Sector::getIdentifier, Function.identity()));
            gridPointSectorMap = getPointSectorMap(gridId, sectorIdMap, gridPointAssociationsStore);
        } else {
            final Set<Segment> segments = segmentFinder.getSegments();

            final NavigableSet<GeoLatitude> latitudeGridlines = bounds
                    .getLatitudeGridlines(numLatitudeGridlines);
            final NavigableSet<GeoLongitude> longitudeGridlines = bounds
                    .getLongitudeGridlines(numLongitudeGridlines);

            final ImmutableSetMultimap<GeoLatitude, GridPoint> latitudePointMap = getLatitudePointMap(segments,
                    bounds, latitudeGridlines);
            final ImmutableSetMultimap<GeoLongitude, GridPoint> longitudePointMap = getLongitudePointMap(
                    segments, bounds, longitudeGridlines);
            final GridIdKey gridKey = new GridIdKey(bounds, numLatitudeGridlines, numLongitudeGridlines);

            sectorTable = getSectorTable(latitudeGridlines, longitudeGridlines, detector);
            allSectors = sectorTable.cellSet().stream().map(cell -> cell.getValue())
                    .collect(Collectors.toSet());

            storeSectors(gridKey.getKeyString(), allSectors, sectorStore);

            gridPointSectorMap = dispositionSectors(latitudeGridlines, latitudePointMap, longitudeGridlines,
                    longitudePointMap, sectorTable);

            storeGridPointAssocations(gridKey.getKeyString(), gridPointSectorMap, gridPointAssociationsStore);

            final GridInfo gridInfo = new GridInfo(bounds.toString(), numLatitudeGridlines,
                    numLongitudeGridlines, allSectors.size());
            gridInfoStore.put(gridKey, gridInfo);

        }
        sectorGridPointMap = gridPointSectorMap.inverse();
        pointSectorMap = ImmutableSetMultimap.copyOf(gridPointSectorMap);
        gridPoints = gridPointSectorMap.keySet();
        reachableSectors = ImmutableSet.copyOf(gridPointSectorMap.values());
        this.bounds = bounds;
    } catch (final BitvantageStoreException e) {
        throw new ScoreGeneratorFatalException(e);
    }
}