public void whenCalculatingSetIntersection_thenCorrect() {
    Set<Character> first = ImmutableSet.of('a', 'b', 'c');
    Set<Character> second = ImmutableSet.of('b', 'c', 'd');
 
    Set<Character> intersection = Sets.intersection(first, second);
    assertThat(intersection, containsInAnyOrder('b', 'c'));
}

        

class GFG { 
  
    // Driver's code 
    public static void main(String[] args) 
    { 
        // Creating first set 
        Set<Integer> 
            set1 = Sets.newHashSet(10, 20, 30, 40, 50); 
  
        // Creating second set 
        Set<Integer> 
            set2 = Sets.newHashSet(30, 50, 70, 90); 
  
        // Using Guava's Sets.intersection() method 
        Set<Integer> 
            answer = Sets.intersection(set1, set2); 
  
        // Displaying the intersection of set1 and set2 
        System.out.println("Set 1: "
                           + set1); 
        System.out.println("Set 2: "
                           + set2); 
        System.out.println("Set 1 intersection Set 2: "
                           + answer); 
    } 
}

        

public static void main(String[] args) {
	// Given sets
	Set<Character> ab = ImmutableSet.of('a', 'b');
	Set<Character> bc = ImmutableSet.of('b', 'c');

	// Intersection of two sets
	Sets.intersection(ab, bc);			// -> [b]
}

        

public static void main(final String[] args) {
	final Concept a = new Concept("Dog");
	final Concept b = new Concept("Tree");
	final Concept c= new Concept("Dog");
	final Set<Concept> set1 = Sets.newHashSet(a);
	final Set<Concept> set2 = Sets.newHashSet(b, c);

	final SetView<Concept> inter = Sets.intersection(set1, set2);
	System.out.println(inter); // => [Concept [data=Dog]]
}

        

public static void main(String args[]) {

	// Set which stores some Singer
	Set<String> singers = new HashSet<String>();
	singers.add("Amitabh Bacchan");
	singers.add("Shan");
	singers.add("Medona");

	// Another Set which stores Actors
	Set<String> actors = new HashSet<String>();
	actors.add("Amitabh Bacchan");
	actors.add("tom cruise");
	actors.add("SRK");

	// Calculating Intersection of two Set in Java
	Set<String> intersection = Sets.intersection(actors, singers);
	System.out.printf("Intersection of two Set %s and %s in Java is %s %n",
			singers.toString(), actors.toString(), intersection.toString());
	System.err.println("Number of elements common in two Set : "
			+ intersection.size());

	// Calculating Union of two Set in Java
	Set<String> union = Sets.union(actors, singers);
	System.out.printf("Union of two Set %s and %s in Java is %s %n",
			singers.toString(), actors.toString(), union.toString());
	System.out.println("total number of element in union of two Set is : "
			+ union.size());
}

        

static void formatConfiguration(StringBuilder sb, AttributeContainer fromConfigurationAttributes, AttributesSchema consumerSchema, List<ConfigurationMetadata> matches, Set<String> requestedAttributes, int maxConfLength, final String conf) {
    Optional<ConfigurationMetadata> match = Iterables.tryFind(matches, new Predicate<ConfigurationMetadata>() {
        @Override
        public boolean apply(ConfigurationMetadata input) {
            return conf.equals(input.getName());
        }
    });
    if (match.isPresent()) {
        AttributeContainer producerAttributes = match.get().getAttributes();
        Set<Attribute<?>> targetAttributes = producerAttributes.keySet();
        Set<String> targetAttributeNames = Sets.newTreeSet(Iterables.transform(targetAttributes, ATTRIBUTE_NAME));
        Set<Attribute<?>> allAttributes = Sets.union(fromConfigurationAttributes.keySet(), producerAttributes.keySet());
        Set<String> commonAttributes = Sets.intersection(requestedAttributes, targetAttributeNames);
        Set<String> consumerOnlyAttributes = Sets.difference(requestedAttributes, targetAttributeNames);
        sb.append("   ").append("- Configuration '").append(StringUtils.rightPad(conf + "'", maxConfLength + 1)).append(" :");
        List<Attribute<?>> sortedAttributes = Ordering.usingToString().sortedCopy(allAttributes);
        List<String> values = new ArrayList<String>(sortedAttributes.size());
        formatAttributes(sb, fromConfigurationAttributes, consumerSchema, producerAttributes, commonAttributes, consumerOnlyAttributes, sortedAttributes, values);
    }
}

        

private List<Color> computeEdgeColors(final Edge edge) {
    final List<Color> edgeColors;

    if (edge.getFromSegment().equals(hoveredSegmentProperty.get())
            || edge.getToSegment().equals(hoveredSegmentProperty.get())) {
        edgeColors = Collections.singletonList(HighlightType.HIGHLIGHTED.getColor());
    } else if (edge.getGenomes() != null
            && graphDimensionsCalculator.getRadiusProperty().get() < MAX_PATH_THICKNESS_DRAWING_RADIUS) {
        final Set<String> selectedGenomesInEdge
                = Sets.intersection(edge.getGenomes(), selectedGenomePaths.keySet());

        if (selectedGenomesInEdge.isEmpty()) {
            edgeColors = Collections.singletonList(getEdgeColor());
        } else {
            edgeColors = selectedGenomesInEdge.stream()
                    .map(path -> correctColorForEdgeOpacity(selectedGenomePaths.get(path)))
                    .collect(Collectors.toList());
        }
    } else {
        edgeColors = Collections.singletonList(getEdgeColor());
    }

    return edgeColors;
}

        

private void expandDerivRightwards(Derivation leftChild) {
  if (parser.verbose(6))
    LogInfo.begin_track("Expanding rightward");
  Map<String, List<Rule>> rhsCategoriesToRules = parser.leftToRightSiblingMap.get(leftChild.cat);
  if (rhsCategoriesToRules != null) {
    for (int i = 1; leftChild.end + i <= numTokens; ++i) {
      Set<String> intersection = Sets.intersection(rhsCategoriesToRules.keySet(), chart[leftChild.end][leftChild.end + i].keySet());

      for (String rhsCategory : intersection) {
        List<Rule> compatibleRules = rhsCategoriesToRules.get(rhsCategory);
        List<Derivation> rightChildren = chart[leftChild.end][leftChild.end + i].get(rhsCategory);
        generateParentDerivations(leftChild, rightChildren, true, compatibleRules);
      }
    }
    // handle terminals
    if (leftChild.end < numTokens)
      handleTerminalExpansion(leftChild, false, rhsCategoriesToRules);
  }
  if (parser.verbose(6))
    LogInfo.end_track();
}

        

protected synchronized void releaseResource(Resource clusterResource,
    Resource resource, Set<String> nodeLabels) {
  // Update usedResources by labels
  if (null == nodeLabels || nodeLabels.isEmpty()) {
    queueUsage.decUsed(resource);
  } else {
    Set<String> anls = (accessibleLabels.contains(RMNodeLabelsManager.ANY))
        ? labelManager.getClusterNodeLabels() : accessibleLabels;
    for (String label : Sets.intersection(anls, nodeLabels)) {
      queueUsage.decUsed(label, resource);
    }
  }

  if (null == nodeLabels || nodeLabels.isEmpty()) {
    CSQueueUtils.updateQueueStatistics(resourceCalculator, this, getParent(),
        labelManager.getResourceByLabel(RMNodeLabelsManager.NO_LABEL, clusterResource), minimumAllocation);
  }
  --numContainers;
}

        

private Set<User> findUsersWithRolesAndPermissions(Set<Role> roles, Set<Permission> permissions) {
    Set<User> userWithRole = new HashSet<>();
    Set<User> userWithPermissionLevel = new HashSet<>();

    if(permissions.isEmpty() && roles.isEmpty())
        return new HashSet<>(userRepository.findAll());

    permissions.
        forEach(permission -> userWithPermissionLevel.addAll(permission.getUsers()));
    if (roles.isEmpty())
        return userWithPermissionLevel;
    else {
        roles.forEach(role -> userWithRole.addAll(role.getUsers()));
        return Sets.intersection(userWithPermissionLevel, userWithRole);
    }
}        
main