Example usage for com.google.common.collect Iterators asEnumeration

List of usage examples for com.google.common.collect Iterators asEnumeration

Introduction

In this page you can find the example usage for com.google.common.collect Iterators asEnumeration.

Prototype

public static <T> Enumeration<T> asEnumeration(final Iterator<T> iterator) 

Source Link

Document

Adapts an Iterator to the Enumeration interface.

Usage

From source file:org.apache.jackrabbit.oak.security.user.AbstractGroupPrincipal.java

@Override
public Enumeration<? extends Principal> members() {
    final Iterator<Authorizable> members;
    try {/*  ww  w  . j  a  v a2  s.  c  o m*/
        members = getMembers();
    } catch (RepositoryException e) {
        // should not occur.
        String msg = "Unable to retrieve Group members: " + e.getMessage();
        log.error(msg);
        throw new IllegalStateException(msg, e);
    }

    Iterator<Principal> principals = Iterators.transform(members, new Function<Authorizable, Principal>() {
        @Override
        public Principal apply(Authorizable authorizable) {
            if (authorizable == null) {
                return null;
            }
            try {
                return authorizable.getPrincipal();
            } catch (RepositoryException e) {
                String msg = "Internal error while retrieving principal: " + e.getMessage();
                log.error(msg);
                throw new IllegalStateException(msg, e);
            }
        }
    });
    return Iterators.asEnumeration(Iterators.filter(principals, Predicates.<Object>notNull()));
}

From source file:org.jglue.cdiunit.DummyHttpRequest.java

@Override
public Enumeration<String> getParameterNames() {

    return Iterators.asEnumeration(_parameters.keySet().iterator());
}

From source file:com.google.gdt.eclipse.designer.hosted.classloader.GWTSharedClassLoader.java

@Override
public Enumeration<URL> findResources(String name) throws IOException {
    final Enumeration<URL> superResources = super.findResources(name);
    final Enumeration<URL> moduleResources = stateTL.get().activeLoader.getResources(name);
    Iterator<URL> allResources = Iterators.concat(Iterators.forEnumeration(superResources),
            Iterators.forEnumeration(moduleResources));
    return Iterators.asEnumeration(allResources);
}

From source file:com.google.inject.servlet.FilterDefinition.java

public void init(final ServletContext servletContext, Injector injector, Set<Filter> initializedSoFar)
        throws ServletException {

    // This absolutely must be a singleton, and so is only initialized once.
    if (!Scopes.isSingleton(injector.getBinding(filterKey))) {
        throw new ServletException(
                "Filters must be bound as singletons. " + filterKey + " was not bound in singleton scope.");
    }//from w w  w.  j ava  2s.  co m

    Filter filter = injector.getInstance(filterKey);
    this.filter.set(filter);

    // Only fire init() if this Singleton filter has not already appeared earlier
    // in the filter chain.
    if (initializedSoFar.contains(filter)) {
        return;
    }

    //initialize our filter with the configured context params and servlet context
    filter.init(new FilterConfig() {
        public String getFilterName() {
            return filterKey.toString();
        }

        public ServletContext getServletContext() {
            return servletContext;
        }

        public String getInitParameter(String s) {
            return initParams.get(s);
        }

        public Enumeration getInitParameterNames() {
            return Iterators.asEnumeration(initParams.keySet().iterator());
        }
    });

    initializedSoFar.add(filter);
}

From source file:com.leacox.dagger.servlet.ServletDefinition.java

public void init(final ServletContext servletContext, ObjectGraph objectGraph,
        Set<HttpServlet> initializedSoFar) throws ServletException {
    // This absolutely must be a singleton, and so is only initialized once.
    // TODO: There isn't a good way to make sure the class is a singleton. Classes with the @Singleton annotation
    // can be identified, but classes that are singletons via an @Singleton annotated @Provides method won't
    // be identified as singletons. Bad stuff may happen for non-singletons.
    //        if (!Scopes.isSingleton(servletClass)) {
    //            throw new ServletException("Servlets must be bound as singletons. "
    //                    + servletClass + " was not bound in singleton scope.");
    //        }/*from   w ww. j av  a2s .co m*/

    HttpServlet httpServlet;
    if (servletInstance == null) {
        httpServlet = objectGraph.get(servletClass);
    } else {
        httpServlet = servletInstance;
    }
    this.httpServlet.set(httpServlet);

    if (initializedSoFar.contains(httpServlet)) {
        return;
    }

    // Initialize our servlet with the configured context params and servlet context.
    httpServlet.init(new ServletConfig() {
        @Override
        public String getServletName() {
            return servletClass.getCanonicalName();
        }

        @Override
        public ServletContext getServletContext() {
            return servletContext;
        }

        @Override
        public String getInitParameter(String name) {
            return initParams.get(name);
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return Iterators.asEnumeration(initParams.keySet().iterator());
        }
    });

    // Mark as initialized.
    initializedSoFar.add(httpServlet);
}

From source file:org.opencms.i18n.CmsVfsResourceBundle.java

/**
 * @see java.util.ResourceBundle#getKeys()
 */// www. j a v  a 2  s. c  o m
@Override
public Enumeration<String> getKeys() {

    Iterator<String> myKeyIter = handleKeySet().iterator();
    Iterator<String> result = myKeyIter;
    if (parent != null) {
        Iterator<String> parentKeyIter = Iterators.forEnumeration(parent.getKeys());
        result = Iterators.concat(myKeyIter, parentKeyIter);
    }
    return Iterators.asEnumeration(result);
}

From source file:com.google.inject.servlet.ServletDefinition.java

public void init(final ServletContext servletContext, Injector injector, Set<HttpServlet> initializedSoFar)
        throws ServletException {

    // This absolutely must be a singleton, and so is only initialized once.
    if (!Scopes.isSingleton(injector.getBinding(servletKey))) {
        throw new ServletException(
                "Servlets must be bound as singletons. " + servletKey + " was not bound in singleton scope.");
    }//from w  w  w.ja v  a 2 s .c  om

    HttpServlet httpServlet = injector.getInstance(servletKey);
    this.httpServlet.set(httpServlet);

    // Only fire init() if we have not appeared before in the filter chain.
    if (initializedSoFar.contains(httpServlet)) {
        return;
    }

    //initialize our servlet with the configured context params and servlet context
    httpServlet.init(new ServletConfig() {
        public String getServletName() {
            return servletKey.toString();
        }

        public ServletContext getServletContext() {
            return servletContext;
        }

        public String getInitParameter(String s) {
            return initParams.get(s);
        }

        public Enumeration getInitParameterNames() {
            return Iterators.asEnumeration(initParams.keySet().iterator());
        }
    });

    // Mark as initialized.
    initializedSoFar.add(httpServlet);
}

From source file:org.eclipse.wb.internal.core.utils.reflect.CompositeClassLoader.java

@Override
protected Enumeration<URL> findResources(String name) throws IOException {
    Set<URL> allResources = Sets.newHashSet();
    for (ClassLoader classLoader : m_classLoaders) {
        Enumeration<URL> resources = classLoader.getResources(name);
        CollectionUtils.addAll(allResources, resources);
    }//from   w  w  w.  j  a v a  2  s.  c  om
    return Iterators.asEnumeration(allResources.iterator());
}

From source file:com.nesscomputing.tracking.MockedHttpServletRequest.java

@Override
public Enumeration<Locale> getLocales() {
    return Iterators.asEnumeration(ImmutableSet.of(getLocale()).iterator());
}

From source file:com.mattc.argus2.io.ListFile.java

@Override
public Enumeration<String> getAsEnumeration() {
    final Set<String> cpy = Sets.newHashSet(this.items);
    return Iterators.asEnumeration(cpy.iterator());
}