Java Code Examples for com.google.common.collect.Sets#newSetFromMap()

The following examples show how to use com.google.common.collect.Sets#newSetFromMap() . 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: ManagedFilterPipeline.java    From dagger-servlet with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void initPipeline(ServletContext servletContext)
        throws ServletException {
    //double-checked lock, prevents duplicate initialization
    if (initialized)
        return;

    // Used to prevent duplicate initialization.
    Set<Filter> initializedSoFar = Sets.newSetFromMap(Maps.<Filter, Boolean>newIdentityHashMap());

    for (FilterDefinition filterDefinition : filterDefinitions) {
        filterDefinition.init(servletContext, objectGraph, initializedSoFar);
    }

    //next, initialize servlets...
    servletPipeline.init(servletContext, objectGraph);

    //everything was ok...
    initialized = true;
}
 
Example 2
Source File: ManagedFilterPipeline.java    From dagger-servlet with Apache License 2.0 5 votes vote down vote up
@Override
public void destroyPipeline() {
    //destroy servlets first
    servletPipeline.destroy();

    //go down chain and destroy all our filters
    Set<Filter> destroyedSoFar = Sets.newSetFromMap(Maps.<Filter, Boolean>newIdentityHashMap());
    for (FilterDefinition filterDefinition : filterDefinitions) {
        filterDefinition.destroy(destroyedSoFar);
    }
}
 
Example 3
Source File: ManagedServletPipeline.java    From dagger-servlet with Apache License 2.0 5 votes vote down vote up
public void init(ServletContext servletContext, ObjectGraph objectGraph) throws ServletException {
    Set<HttpServlet> initializedSoFar
            = Sets.newSetFromMap(Maps.<HttpServlet, Boolean>newIdentityHashMap());

    for (ServletDefinition servletDefinition : servletDefinitions) {
        servletDefinition.init(servletContext, objectGraph, initializedSoFar);
    }
}
 
Example 4
Source File: ManagedServletPipeline.java    From dagger-servlet with Apache License 2.0 5 votes vote down vote up
public void destroy() {
    Set<HttpServlet> destroyedSoFar
            = Sets.newSetFromMap(Maps.<HttpServlet, Boolean>newIdentityHashMap());
    for (ServletDefinition servletDefinition : servletDefinitions) {
        servletDefinition.destroy(destroyedSoFar);
    }
}
 
Example 5
Source File: DefaultSessionManager.java    From bistoury with GNU General Public License v3.0 4 votes vote down vote up
private <T> Set<T> createRelativeSet() {
    ConcurrentMap<T, Boolean> map = new MapMaker().weakKeys().makeMap();
    return Sets.newSetFromMap(map);
}
 
Example 6
Source File: ConcurrentCollections.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public static <V> Set<V> newConcurrentSet() {
    return Sets.newSetFromMap(ConcurrentCollections.<V, Boolean>newConcurrentMap());
}
 
Example 7
Source File: TypeSystemSmokeTester.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public TypeSystemSmokeTester() throws NoSuchAlgorithmException {
	messageDigest = MessageDigest.getInstance("MD5");
	seen = Sets.newSetFromMap(new ConcurrentHashMap<BigInteger, Boolean>());
}
 
Example 8
Source File: DoSFilter.java    From myrrix-recommender with Apache License 2.0 4 votes vote down vote up
public DoSFilter() {
  numRecentAccesses = Maps.newConcurrentMap();
  bannedIPAddresses = Sets.newSetFromMap(Maps.<String,Boolean>newConcurrentMap());
}
 
Example 9
Source File: ChildReaper.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a thread-safe set backed by a hash map. The set is backed by a
 * {@link ConcurrentHashMap} instance, and thus carries the same concurrency
 * guarantees.
 *
 * <p>Unlike {@code HashSet}, this class does NOT allow {@code null} to be
 * used as an element. The set is serializable.
 *
 * @return a new, empty thread-safe {@code Set}
 * @since 15.0
 */
public static <E> Set<E> newConcurrentHashSet() {
  return Sets.newSetFromMap(new ConcurrentHashMap<E, Boolean>());
}
 
Example 10
Source File: ChildReaper.java    From big-c with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a thread-safe set backed by a hash map. The set is backed by a
 * {@link ConcurrentHashMap} instance, and thus carries the same concurrency
 * guarantees.
 *
 * <p>Unlike {@code HashSet}, this class does NOT allow {@code null} to be
 * used as an element. The set is serializable.
 *
 * @return a new, empty thread-safe {@code Set}
 * @since 15.0
 */
public static <E> Set<E> newConcurrentHashSet() {
  return Sets.newSetFromMap(new ConcurrentHashMap<E, Boolean>());
}