Example usage for com.google.common.collect Sets newLinkedHashSet

List of usage examples for com.google.common.collect Sets newLinkedHashSet

Introduction

In this page you can find the example usage for com.google.common.collect Sets newLinkedHashSet.

Prototype

public static <E> LinkedHashSet<E> newLinkedHashSet() 

Source Link

Document

Creates a mutable, empty LinkedHashSet instance.

Usage

From source file:org.eclipse.sirius.diagram.ui.business.internal.migration.SetGMFViewsToNillMigrationParticipant.java

/**
 * //w w w .j  a va 2  s  .  co  m
 * {@inheritDoc}
 * 
 * @see fr.obeo.dsl.viewpoint.business.api.migration.AbstractRepresentationsFileMigrationParticipant#postLoad(fr.obeo.dsl.viewpoint.DAnalysis,
 *      org.osgi.framework.Version)
 */
@Override
protected void postLoad(DAnalysis dAnalysis, Version loadedVersion) {
    if (loadedVersion.compareTo(MIGRATION_VERSION) < 0) {
        // Step 1: get all views to update
        final Collection<View> allViewsToUpdate = Sets.newLinkedHashSet();
        for (DView view : dAnalysis.getOwnedViews()) {
            for (DDiagram dDiagram : Iterables.filter(view.getOwnedRepresentations(), DDiagram.class)) {
                DiagramCreationUtil diagramCreationUtil = new DiagramCreationUtil(dDiagram);
                if (diagramCreationUtil.findAssociatedGMFDiagram()) {
                    Diagram gmfDiagram = diagramCreationUtil.getAssociatedGMFDiagram();
                    allViewsToUpdate.addAll(getViewsToUpdate(gmfDiagram));
                }
            }
        }
        // Step 2: update views
        for (View viewToUpdate : allViewsToUpdate) {
            viewToUpdate.setElement(null);
        }
    }
    super.postLoad(dAnalysis, loadedVersion);
}

From source file:com.axelor.auth.AuthResolver.java

/**
 * Filter the given set of permissions for the given object with the
 * required access type. <br>//from   w ww  .  j a va2  s .c  om
 * <p>
 * It first tries to find exact match for the given object else it tries to
 * find wild card (by package name). The permissions on objects without
 * condition gets preference over wild card permissions.
 * 
 * @param permissions
 *            set of permissions to filter
 * @param object
 *            object name for which to check the permission
 * @param type
 *            the requested access type
 * @return filtered set of {@link Permission}
 */
private Set<Permission> filterPermissions(final Set<Permission> permissions, final String object,
        final AccessType type) {

    if (permissions == null || permissions.isEmpty()) {
        return Sets.newLinkedHashSet();
    }

    final Set<Permission> all = Sets.newLinkedHashSet();

    for (final Permission permission : permissions) {
        if (Objects.equal(object, permission.getObject())
                && (permission.getCondition() == null || hasAccess(permission, type))) {
            all.add(permission);
        }
    }
    if (!all.isEmpty()) {
        return all;
    }

    final String pkg = object.substring(0, object.lastIndexOf('.')) + ".*";

    for (final Permission permission : permissions) {
        if (Objects.equal(pkg, permission.getObject())
                && (permission.getCondition() == null || hasAccess(permission, type))) {
            all.add(permission);
        }
    }

    return all;
}

From source file:org.eclipse.sirius.ui.tools.internal.actions.analysis.AddSemanticResourceAction.java

/**
 * Returns the list of {@link URI}s corresponding to the given
 * {@link Session}s.//from ww w  .j ava2  s.  c o m
 * 
 * @param sessions
 *            The list of {@link Session}s to get the {@link URI} from
 * @return the list of {@link URI}s corresponding to the given
 *         {@link Session}s
 */
private static Collection<URI> collectURIsFromSessions(List<Session> sessions) {
    Collection<URI> sessionsURIs = Sets.newLinkedHashSet();
    for (Session concernedSession : sessions) {
        sessionsURIs.add(concernedSession.getSessionResource().getURI());
    }
    return sessionsURIs;
}

From source file:de.cau.cs.kieler.klay.layered.intermediate.SplineSelfLoopPreProcessor.java

/**
 * {@inheritDoc}// w  ww .  jav a 2 s  .  c  o m
 */
public void process(final LGraph layeredGraph, final IKielerProgressMonitor monitor) {
    monitor.begin("Spline SelfLoop pre-processing.", 1);

    // A set of all loop edges of the currently processed node.
    final Set<LEdge> loopEdges = Sets.newLinkedHashSet();

    // process all nodes
    for (final LNode node : layeredGraph.getLayerlessNodes()) {
        correctPortSideConstraint(node);
        loopEdges.clear();

        // find all self-loops of the node. Don't use node.connectedEdges, as it returns all
        // loops twice.
        for (final LEdge edge : node.getOutgoingEdges()) {
            if (edge.isSelfLoop()) {
                loopEdges.add(edge);
            }
        }

        /* First we will turn some loops, so that they go into the directions:
         * North->South / West->East / Counterclockwise  
         * This way we have to care about fewer cases.
         * We will reverse following edges:
         *  1. North -> East or South
         *  2. East -> South
         *  3. South -> West
         *  4. West -> North or East
         */
        for (final LEdge edge : loopEdges) {
            final PortSide sourcePortSide = edge.getSource().getSide();
            final PortSide targetPortSide = edge.getTarget().getSide();

            if ((sourcePortSide == PortSide.NORTH
                    && (targetPortSide == PortSide.EAST || targetPortSide == PortSide.SOUTH))
                    || (sourcePortSide == PortSide.EAST && targetPortSide == PortSide.SOUTH)
                    || (sourcePortSide == PortSide.SOUTH && targetPortSide == PortSide.WEST)
                    || (sourcePortSide == PortSide.WEST
                            && (targetPortSide == PortSide.NORTH || targetPortSide == PortSide.EAST))) {

                edge.reverse(layeredGraph, false);
            }
        }

        // Construct the set of connected components...
        final List<ConnectedSelfLoopComponent> allComponents = findAllConnectedComponents(loopEdges, node);

        // ... and add the set to the node's properties.
        node.setProperty(InternalProperties.SPLINE_SELFLOOP_COMPONENTS, allComponents);

        // Now we will hide self-loop ports from the node.
        // We don't hide the ports of nodes with portConstraint "fixedOrder",
        // or if the port has a non-loop edge connected.
        if (!node.getProperty(LayoutOptions.PORT_CONSTRAINTS).isOrderFixed()) {
            final Set<LPort> portsToHide = Sets.newHashSet();
            for (final ConnectedSelfLoopComponent component : allComponents) {
                portsToHide.addAll(component.getHidablePorts());
                portsToHide.addAll(component.getPortsWithPortSide());
            }

            // Hide the ports by removing them from the node. 
            // The reference of the port to the node is kept, 
            // as we will re-add the port to the same node later. (in the SplieSelfLoopPositioner) 
            final Iterator<LPort> itr = node.getPorts().listIterator();
            while (itr.hasNext()) {
                final LPort port = itr.next();
                if (portsToHide.contains(port)) {
                    itr.remove();
                }
            }
        }
    }
    monitor.done();
}

From source file:org.obiba.magma.datasource.hibernate.domain.ValueSetState.java

public Set<ValueSetValue> getValues() {
    return values == null ? (values = Sets.newLinkedHashSet()) : values;
}

From source file:org.eclipse.sirius.diagram.tools.internal.validation.description.constraints.MappingForReconnectToolsConstraint.java

private Collection<String> getReconnectOnRegions(ReconnectEdgeDescription tool) {
    Predicate<ContainerMapping> isRegionMapping = new Predicate<ContainerMapping>() {
        @Override/*from ww w  .j  a  va 2s  . c  o m*/
        public boolean apply(ContainerMapping input) {
            return new ContainerMappingQuery(input).isRegion();
        }
    };

    Collection<EdgeMapping> edgeToRegions = Sets.newLinkedHashSet();
    for (EdgeMapping em : tool.getMappings()) {
        if (tool.getReconnectionKind() == ReconnectionKind.RECONNECT_SOURCE_LITERAL
                || tool.getReconnectionKind() == ReconnectionKind.RECONNECT_BOTH_LITERAL) {
            if (Iterables.any(Iterables.filter(em.getSourceMapping(), ContainerMapping.class),
                    isRegionMapping)) {
                edgeToRegions.add(em);
            }
        }

        if (tool.getReconnectionKind() == ReconnectionKind.RECONNECT_TARGET_LITERAL
                || tool.getReconnectionKind() == ReconnectionKind.RECONNECT_BOTH_LITERAL) {
            if (Iterables.any(Iterables.filter(em.getTargetMapping(), ContainerMapping.class),
                    isRegionMapping)) {
                edgeToRegions.add(em);
            }
        }
    }

    Collection<String> mappingsLabel = Lists.newArrayList();
    for (EdgeMapping mapping : edgeToRegions) {
        mappingsLabel.add(new IdentifiedElementQuery(mapping).getLabel());
    }
    return mappingsLabel;
}

From source file:org.apache.nutch.util.DbPageConverter.java

private static Set<Field> filterFields(WebPage page, Set<String> queryFields) {
    // DbIterator.LOG.error("queryFields : {}", new Gson().toJson(queryFields));

    List<Field> pageFields = page.getSchema().getFields();
    if (CollectionUtils.isEmpty(queryFields)) {
        return Sets.newHashSet(pageFields);
    }//from www. j a  v  a  2 s  .c  o  m

    Set<Field> filteredFields = Sets.newLinkedHashSet();
    for (Field field : pageFields) {
        // DbIterator.LOG.error("name : {}", field.name());

        if (queryFields.contains(field.name())) {
            filteredFields.add(field);
        }
    }

    return filteredFields;
}

From source file:org.switchyard.tools.ui.editor.model.merge.ReflectiveWeightProvider.java

/**
 * Create the weight provider.
 */
public ReflectiveWeightProvider() {
    _weights = Maps.newHashMap();
    _toBeIgnored = Sets.newLinkedHashSet();
}

From source file:org.eclipse.sirius.table.ui.tools.internal.editor.provider.DTableEditorUtil.java

/**
 * Updates the viewer columns according to the given {@link DTable} :
 * creates, deletes and update columns width if needed.
 * //ww w. jav a 2  s.c o m
 * @param treeViewerManager
 *            the table viewer to update
 * @param dTable
 *            the {@link DTable} reflecting the expected viewer state
 */
public static void updateViewerColumns(AbstractDTableViewerManager treeViewerManager, DTable dTable) {
    DTableTreeViewer dTableTreeViewer = (DTableTreeViewer) treeViewerManager.getTreeViewer();
    TreeColumn[] treeColumns = dTableTreeViewer.getTree().getColumns();

    // Step 1: update header column width
    TreeColumn treeColumn = treeColumns[0];
    TreeColumnWidthQuery treeColumnWidthQuery = new TreeColumnWidthQuery(treeColumn);
    Display.getDefault().syncExec(treeColumnWidthQuery);
    int widgetWidth = treeColumnWidthQuery.getResult();
    if (dTable.getHeaderColumnWidth() != widgetWidth && dTable.getHeaderColumnWidth() > 0) {
        treeColumn.setWidth(dTable.getHeaderColumnWidth());
    }

    // Step 2: update other columns width
    Set<DColumn> handledDColumns = Sets.newLinkedHashSet();
    for (int i = 1; i < treeColumns.length; i++) {
        treeColumn = treeColumns[i];
        DColumn dColumn = (DColumn) treeColumn.getData(DTableViewerManager.TABLE_COLUMN_DATA);

        if (dColumn != null && dTable.getColumns().contains(dColumn)) {
            handledDColumns.add(dColumn);
            treeColumnWidthQuery = new TreeColumnWidthQuery(treeColumn);
            Display.getDefault().syncExec(treeColumnWidthQuery);
            widgetWidth = treeColumnWidthQuery.getResult();
            // If the DColumn as a default width (0) then resizing at
            // opening should not impact the model
            if (dColumn.isVisible() && dColumn.getWidth() > 0 && dColumn.getWidth() != widgetWidth) {
                treeColumn.setWidth(dColumn.getWidth());
            }
        } else {
            // Step 3: handle deleted columns
            ((DTableViewerManager) treeViewerManager).removeOldColumn(dColumn);

        }
    }
    // Step 4: handle added columns
    for (DColumn newColumn : Sets.difference(Sets.newLinkedHashSet(dTable.getColumns()), handledDColumns)) {
        int position = dTable.getColumns().indexOf(newColumn) + 1;
        addNewColumn(treeViewerManager, position, newColumn);
    }

    // Step 5: update expanded elemeents
    dTableTreeViewer.setExpandedElements(TableHelper.getExpandedLines(dTable).toArray());
}

From source file:org.eclipse.xtext.xtext.ecoreInference.TypeHierarchyHelper.java

public Set<EClassInfo> getSubTypesOf(EClassInfo info) {
    Set<EClassInfo> result = subTypesMap.get(info);
    if (result == null) {
        result = Sets.newLinkedHashSet();
        subTypesMap.put(info, result);//ww w.  ja v a 2 s . c  om
    }
    return result;
}