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

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

Introduction

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

Prototype

Map<K, Collection<V>> asMap();

Source Link

Document

Returns a view of this multimap as a Map from each distinct key to the nonempty collection of that key's associated values.

Usage

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

/**
 * Overridden to update the {@link DAnalysis#getModels()} reference
 * according to new added {@link DSemanticDecorator}.
 * /*w w  w .j a v a 2  s .co m*/
 * {@inheritDoc}
 */
@Override
public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
    Multimap<DAnalysis, ResourceDescriptor> referencedSemanticModels = getRootSemanticResourceEltsPerRepresentationsResource(
            event.getNotifications());
    CompoundCommand result = new CompoundCommand();
    for (Entry<DAnalysis, Collection<ResourceDescriptor>> entry : referencedSemanticModels.asMap().entrySet()) {
        DAnalysis analysis = entry.getKey();
        Collection<ResourceDescriptor> semanticResourceDescriptors = entry.getValue();
        if (!analysis.getSemanticResources().containsAll(semanticResourceDescriptors)) {
            semanticResourceDescriptors.removeAll(analysis.getSemanticResources());
            result.append(AddCommand.create(event.getEditingDomain(), analysis,
                    ViewpointPackage.Literals.DANALYSIS__SEMANTIC_RESOURCES, semanticResourceDescriptors));
        }
    }
    return result;
}

From source file:com.isotrol.impe3.support.nr.ContentNode.java

/**
 * Returns highlighted fields as list of string fragments.
 *//*from w w w. j  a  v a  2 s.  co m*/
public Map<String, Collection<String>> getHighlighted() {
    Multimap<String, String> multimap = node.getHighlight();
    if (multimap == null) {
        return ImmutableMap.of();
    }
    return multimap.asMap();
}

From source file:com.isotrol.impe3.support.nr.ContentNode.java

/**
 * returns content properties/*from   ww w. j  a  v  a 2s .  c o  m*/
 */
public Map<String, Collection<String>> getProperties() {
    Multimap<String, String> multimap = node.getProperties();
    if (multimap == null) {
        return ImmutableMap.of();
    }
    return multimap.asMap();
}

From source file:moa2014.MOA2014.java

public static void principal(int[][] matrizatual) {

    Multimap<Integer, String> open_list = TreeMultimap.create();
    HashMap<String, Estado> processados = new HashMap();

    int difmatrizatual = diferencaMatriz(matrizatual);

    String stringmatriz = transformaMatrizString(matrizatual);
    open_list.put(difmatrizatual, stringmatriz);
    Estado estadoatual = new Estado(matrizatual, 0);
    processados.put(stringmatriz, estadoatual);

    int counter = 1;

    while (!open_list.isEmpty()) {
        System.out.println("Arvores processadas: " + counter);
        Iterator iterator = open_list.keySet().iterator();
        /*/*w w w .j a v a2s  .c o  m*/
        Iterator iterator2 = open_list.keySet().iterator();
                
        while (iterator2.hasNext()) {
          Integer key = (Integer) iterator2.next();
          System.out.println("key : " + key + " value :" + open_list.get(key));
        }
                
        Scanner scanner = new Scanner( System.in );
        String input = scanner.nextLine();
        */
        counter++;
        Integer key = (Integer) iterator.next();
        String matrizatualx1 = open_list.asMap().get(key).iterator().next();
        Estado estadomenor = processados.get(matrizatualx1);
        int altura = estadomenor.getCusto();
        System.out.println("Altura: " + altura);
        //LOCALIZA O ZERO
        int[] zerot = localizazero(estadomenor.getMatriz());
        int x = zerot[0];
        int y = zerot[1];
        int x0 = x - 1;
        int x1 = x + 1;
        int y0 = y - 1;
        int y1 = y + 1;
        int difmatrizatualx = diferencaMatriz(estadomenor.getMatriz());
        if (difmatrizatualx == 0) {
            System.out.println("Arvores processadas: " + counter);
            System.out.println("Custo: " + estadomenor.getCusto());
            break;
        }
        int[][] matrizatualx = estadomenor.getMatriz();
        if (x0 >= 0) {

            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x0][y];
            matriz[x0][y] = matrizatualx[x][y];

            String stringmatriz1 = transformaMatrizString(matriz);
            if (!(processados.containsKey(stringmatriz1))) {

                int diferencamatriz = diferencaMatriz(matriz);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz1);

                processados.put(stringmatriz1, estadonovo);

            }
        }
        if (x1 <= 3) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x1][y];
            matriz[x1][y] = matrizatualx[x][y];
            String stringmatriz2 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz2))) {

                int diferencamatriz = diferencaMatriz(matriz);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz2);

                processados.put(stringmatriz2, estadonovo);

            }
        }
        if (y0 >= 0) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x][y0];
            matriz[x][y0] = matrizatualx[x][y];
            String stringmatriz3 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz3))) {

                int diferencamatriz = diferencaMatriz(matriz);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz3);

                processados.put(stringmatriz3, estadonovo);

            }
        }
        if (y1 <= 3) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x][y1];
            matriz[x][y1] = matrizatualx[x][y];

            int custoateaqui = diferencaMatriz(matriz) + altura + 1;
            String stringmatriz4 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz4))) {

                int diferencamatriz = diferencaMatriz(matriz);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz4);

                processados.put(stringmatriz4, estadonovo);

            }
        }
        open_list.remove(key, matrizatualx1);
    }

}

From source file:blow.eventbus.OrderedEventBus.java

/**
 * Unregisters all handler methods on a registered {@code object}.
 *
 * @param object  object whose handler methods should be unregistered.
 * @throws IllegalArgumentException if the object was not previously registered.
 *///from  w ww  .j  a  va 2  s .  c  om
public void unregister(Object object) {
    Multimap<Class<?>, EventHandler> methodsInListener = finder.findAllHandlers(object);
    for (Entry<Class<?>, Collection<EventHandler>> entry : methodsInListener.asMap().entrySet()) {
        List<EventHandler> currentHandlers = getHandlersForEventType(entry.getKey());
        Collection<EventHandler> eventMethodsInListener = entry.getValue();

        if (currentHandlers == null || !currentHandlers.containsAll(entry.getValue())) {
            throw new IllegalArgumentException(
                    "missing event handler for an annotated method. Is " + object + " registered?");
        }
        currentHandlers.removeAll(eventMethodsInListener);
    }
}

From source file:org.sourcepit.maven.dependency.model.aether.DependencyUtils.java

public static Collection<List<DependencyNode>> computeConflictingNodeGroups(DependencyNode node) {
    final Collection<Collection<VersionConflictKey>> conflictKeyGroups = computeConflictKeyGroups(node);

    final Multimap<Collection<VersionConflictKey>, DependencyNode> conflictNodes = LinkedHashMultimap.create();
    node.accept(new AbstractDependencyVisitor(false) {
        @Override//  w  w  w . j av  a 2  s . com
        protected boolean onVisitEnter(DependencyNode parent, DependencyNode node) {
            final DependencyNode2 adapter = DependencyNode2Adapter.get(node);
            final VersionConflictKey originGroupKey = adapter.getDependencyConflictKey();
            if (originGroupKey != null) {
                boolean put = false;
                for (Collection<VersionConflictKey> conflictGroup : conflictKeyGroups) {
                    if (conflictGroup.contains(originGroupKey)) {
                        checkState(!put);
                        conflictNodes.put(conflictGroup, node);
                        put = true;
                    }
                }
                checkState(put);
            }
            return true;
        }
    });

    final Collection<List<DependencyNode>> conflictNodeGroups = new ArrayList<List<DependencyNode>>();

    for (Collection<DependencyNode> conflictNodeGroup : conflictNodes.asMap().values()) {
        if (conflictNodeGroup.size() > 1) {
            conflictNodeGroups.add(new ArrayList<DependencyNode>(conflictNodeGroup));
        }
    }

    return conflictNodeGroups;
}

From source file:com.qcadoo.mes.productionPerShift.dates.ProgressDatesService.java

@Transactional
public void setUpDatesFor(final Entity order) {
    for (OrderDates orderDates : resolveOrderDates(order).asSet()) {
        List<Entity> progressesForDays = progressForDayDataProvider.findForOrder(order,
                ProgressForDayDataProvider.DEFAULT_SEARCH_ORDER);
        Multimap<Long, Entity> progressesByOperationId = Multimaps.index(progressesForDays,
                EXTRACT_TECHNOLOGY_OPERATION_ID);
        for (Collection<Entity> progresses : progressesByOperationId.asMap().values()) {
            setupDatesFor(progresses, orderDates);
        }//from  www . ja  v  a  2s  . c  om
    }
}

From source file:eu.lp0.cursus.xml.scores.results.ScoresXMLSeriesResults.java

public ScoresXMLSeriesResults(Scores scores) {
    super(scores);

    series = AbstractXMLEntity.generateId(scores.getSeries());

    discards = scores.getDiscardCount();

    Multimap<Event, Race> events_ = LinkedHashMultimap.create(scores.getRaces().size(),
            scores.getRaces().size());/*from ww  w  . j a  v  a 2s.  c  om*/
    for (Race race : scores.getRaces()) {
        events_.put(race.getEvent(), race);
    }

    eventResults = new ArrayList<ScoresXMLSeriesEventResults>(events_.keySet().size());
    for (Entry<Event, Collection<Race>> event : events_.asMap().entrySet()) {
        eventResults.add(new ScoresXMLSeriesEventResults(scores, event.getKey(), event.getValue()));
    }
}

From source file:com.squareup.wire.java.ProfileLoader.java

private ImmutableList<ProfileFileElement> loadProfileFiles(Multimap<Path, String> pathsToAttempt)
        throws IOException {
    ImmutableList.Builder<ProfileFileElement> result = ImmutableList.builder();
    try (Closer closer = Closer.create()) {
        for (Map.Entry<Path, Collection<String>> entry : pathsToAttempt.asMap().entrySet()) {
            Path base = entry.getKey();
            if (Files.isRegularFile(base)) {
                FileSystem sourceFs = FileSystems.newFileSystem(base, getClass().getClassLoader());
                closer.register(sourceFs);
                base = getOnlyElement(sourceFs.getRootDirectories());
            }/*from w  w  w.  j ava 2  s  .c o  m*/
            for (String path : entry.getValue()) {
                ProfileFileElement element = loadProfileFile(base, path);
                if (element != null)
                    result.add(element);
            }
        }
    }
    return result.build();
}

From source file:com.google.devtools.build.lib.collect.ImmutableSortedKeyListMultimap.java

@Override
public boolean equals(@Nullable Object object) {
    if (this == object) {
        return true;
    }/*ww  w  .jav a  2s  .  c  o  m*/
    if (object instanceof Multimap) {
        Multimap<?, ?> that = (Multimap<?, ?>) object;
        return asMap().equals(that.asMap());
    }
    return false;
}