Java Code Examples for java.util.LinkedHashSet#retainAll()

The following examples show how to use java.util.LinkedHashSet#retainAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DashboardMain.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
private static ImmutableList<String> commonVersionlessArtifacts(
    List<DependencyPath> dependencyPaths) {
  ImmutableList<String> initialVersionlessCoordinates =
      versionlessCoordinates(dependencyPaths.get(0));
  // LinkedHashSet remembers insertion order
  LinkedHashSet<String> versionlessCoordinatesIntersection =
      Sets.newLinkedHashSet(initialVersionlessCoordinates);
  for (DependencyPath dependencyPath : dependencyPaths) {
    // List of versionless coordinates ("groupId:artifactId")
    ImmutableList<String> versionlessCoordinatesInPath = versionlessCoordinates(dependencyPath);
    // intersection of elements in DependencyPaths
    versionlessCoordinatesIntersection.retainAll(versionlessCoordinatesInPath);
  }

  return ImmutableList.copyOf(versionlessCoordinatesIntersection);
}
 
Example 2
Source File: MoreAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public JMenuItem getPopupPresenter() {
    Lookup l = Utilities.actionsGlobalContext();
    Collection<? extends MatchingObject> matchingObjects
            = l.lookupAll(MatchingObject.class);
    LinkedHashSet<Action> commonActions = new LinkedHashSet<Action>();
    boolean first = true;
    for (MatchingObject mo : matchingObjects) {
        DataObject dob = mo.getDataObject();
        if (dob != null) {
            Node nodeDelegate = dob.getNodeDelegate();
            Collection<Action> dobActions = Arrays.asList(
                    nodeDelegate.getActions(false));
            if (first) {
                commonActions.addAll(dobActions);
                first = false;
            } else {
                commonActions.retainAll(dobActions);
            }
        }
    }
    return actionsToMenu(commonActions, l);
}
 
Example 3
Source File: PathFinder.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * Determines all functions that lie on all possible paths between a given start function and a
 * given target function.
 *
 * @param callgraph The Call graph that contains all function call information.
 * @param startFunction The start function of the path.
 * @param targetFunction The target function of the path.
 *
 * @return A set of all functions that are passed on the possible paths between the start function
 *         and the end function.
 */
private static LinkedHashSet<FunctionBlock> findPassedFunctions(final Callgraph callgraph,
    final Function startFunction, final Function targetFunction) {
  // Find the graph nodes that correspond to the functions in the graph
  final FunctionBlock sourceCallgraphNode = findBlock(callgraph, startFunction);
  final FunctionBlock targetCallgraphNode = findBlock(callgraph, targetFunction);

  Logger.info("Source block: %s\n", sourceCallgraphNode.getFunction().getName());
  Logger.info("Target block: %s\n", targetCallgraphNode.getFunction().getName());

  // Passed functions = Intersection of the successors of the start function and the predecessors
  // of the target function.
  final Collection<FunctionBlock> successorFunctions =
      GraphAlgorithms.getSuccessors(sourceCallgraphNode);
  final Collection<FunctionBlock> predecessorFunctions =
      GraphAlgorithms.getPredecessors(targetCallgraphNode);

  final LinkedHashSet<FunctionBlock> sharedFunctions =
      new LinkedHashSet<FunctionBlock>(successorFunctions);
  sharedFunctions.retainAll(predecessorFunctions);

  sharedFunctions.add(sourceCallgraphNode);
  sharedFunctions.add(targetCallgraphNode);

  return sharedFunctions;
}
 
Example 4
Source File: CTraceCombinationFunctions.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the event addresses that appear in all traces.
 *
 * @param traces The input traces.
 *
 * @return The addresses of those events that appear in all traces.
 */
private static LinkedHashSet<BreakpointAddress> getIntersectedAddresses(
    final List<TraceList> traces) {
  final LinkedHashSet<BreakpointAddress> addresses = new LinkedHashSet<BreakpointAddress>();

  boolean first = true;

  for (final Collection<BreakpointAddress> collection : getTraceAddresses(traces)) {
    if (first) {
      addresses.addAll(collection);

      first = false;
    } else {
      addresses.retainAll(collection);
    }
  }

  return addresses;
}
 
Example 5
Source File: MappingSet.java    From elasticsearch-hadoop with Apache License 2.0 6 votes vote down vote up
private static FieldType resolveTypeConflict(String fullName, FieldType existing, FieldType incoming) {
    // Prefer to upcast the incoming field to the existing first
    LinkedHashSet<FieldType> incomingSuperTypes = incoming.getCastingTypes();
    if (incomingSuperTypes.contains(existing)) {
        // Incoming can be cast to existing.
        return existing;
    }
    // See if existing can be upcast to the incoming field's type next
    LinkedHashSet<FieldType> existingSuperTypes = existing.getCastingTypes();
    if (existingSuperTypes.contains(incoming)) {
        // Existing can be cast to incoming
        return incoming;
    }
    // Finally, Try to pick the lowest common super type for both fields if it exists
    if (incomingSuperTypes.size() > 0 && existingSuperTypes.size() > 0) {
        LinkedHashSet<FieldType> combined = new LinkedHashSet<FieldType>(incomingSuperTypes);
        combined.retainAll(existingSuperTypes);
        if (combined.size() > 0) {
            return combined.iterator().next();
        }
    }
    // If none of the above options succeed, the fields are conflicting
    throw new EsHadoopIllegalArgumentException("Incompatible types found in multi-mapping: " +
            "Field ["+fullName+"] has conflicting types of ["+existing+"] and ["+
            incoming+"].");
}
 
Example 6
Source File: GroupMatcher.java    From jvm-sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public MatchingResult matching(ClassStructure classStructure) {
    boolean isFirst = true;
    final MatchingResult result = new MatchingResult();
    final LinkedHashSet<BehaviorStructure> found = new LinkedHashSet<BehaviorStructure>();
    if (null == matcherArray) {
        return result;
    }
    for (final Matcher subMatcher : matcherArray) {
        final MatchingResult subResult = subMatcher.matching(classStructure);

        // 只要有一次匹配失败,剩下的是取交集运算,所以肯定也没戏,就不用花这个计算了
        if (!subResult.isMatched()) {
            return result;
        }

        if (isFirst) {
            found.addAll(subResult.getBehaviorStructures());
            isFirst = false;
        } else {
            found.retainAll(subResult.getBehaviorStructures());
        }
    }
    if (!found.isEmpty()) {
        result.getBehaviorStructures().addAll(found);
    }
    return result;
}
 
Example 7
Source File: ContextFinder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Set<ISerializationContext> findByContents(EObject semanticObject, Iterable<ISerializationContext> contextCandidates) {
	if (semanticObject == null)
		throw new NullPointerException();

	initConstraints();

	Multimap<IConstraint, ISerializationContext> constraints;
	if (contextCandidates != null)
		constraints = getConstraints(semanticObject, contextCandidates);
	else
		constraints = getConstraints(semanticObject);

	if (constraints.size() < 2)
		return Sets.newLinkedHashSet(constraints.values());

	for (IConstraint cand : Lists.newArrayList(constraints.keySet()))
		if (!isValidValueQuantity(cand, semanticObject))
			constraints.removeAll(cand);

	if (constraints.size() < 2)
		return Sets.newLinkedHashSet(constraints.values());

	LinkedHashSet<ISerializationContext> result = Sets.newLinkedHashSet(constraints.values());
	for (EStructuralFeature feat : semanticObject.eClass().getEAllStructuralFeatures()) {
		if (transientValueUtil.isTransient(semanticObject, feat) != ValueTransient.NO)
			continue;
		if (feat.isMany() && ((List<?>) semanticObject.eGet(feat)).isEmpty())
			continue;
		Multimap<AbstractElement, ISerializationContext> assignments = collectAssignments(constraints, feat);
		Set<AbstractElement> assignedElements = findAssignedElements(semanticObject, feat, assignments);
		Set<ISerializationContext> keep = Sets.newHashSet();
		for (AbstractElement ele : assignedElements)
			keep.addAll(assignments.get(ele));
		result.retainAll(keep);
	}
	return result;
}