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.richfaces.demo.iteration.LazyTreeNode.java

public Enumeration children() {
    initializeChildren();

    return Iterators.asEnumeration(children.iterator());
}

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

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

From source file:ch.raffael.contracts.devtools.ast.AstTreeNode.java

@Override
public Enumeration children() {
    return Iterators.asEnumeration(children.iterator());
}

From source file:io.druid.initialization.ExtensionFirstClassLoader.java

@Override
public Enumeration<URL> getResources(final String name) throws IOException {
    final List<URL> urls = new ArrayList<>();
    Iterators.addAll(urls, Iterators.forEnumeration(super.getResources(name)));
    Iterators.addAll(urls, Iterators.forEnumeration(druidLoader.getResources(name)));
    return Iterators.asEnumeration(urls.iterator());
}

From source file:co.cask.cdap.common.lang.PackageFilterClassLoader.java

@Override
public Enumeration<URL> getResources(String name) throws IOException {
    Enumeration<URL> resources = bootstrapClassLoader.getResources(name);
    if (resources.hasMoreElements()) {
        return resources;
    }/*from  w w  w .  jav a  2s.c  o  m*/
    if (name.endsWith(".class") && !predicate.apply(getResourcePackage(name))) {
        return Iterators.asEnumeration(Iterators.<URL>emptyIterator());
    }
    return super.getResources(name);
}

From source file:org.sonar.java.bytecode.loader.SquidClassLoader.java

@Override
protected Enumeration<URL> findResources(String name) throws IOException {
    List<URL> result = new ArrayList<>();
    for (Loader loader : loaders) {
        URL url = loader.findResource(name);
        if (url != null) {
            result.add(url);/*from w  w w .j ava2  s. c o m*/
        }
    }
    return Iterators.asEnumeration(result.iterator());
}

From source file:com.facebook.buck.log.LogConfig.java

/**
 * Creates the log output directory and concatenates logging.properties
 * files together to configure or re-configure LogManager.
 *///from   w w w  .j  a  v  a 2s. co m
public static synchronized void setupLogging(LogConfigSetup logConfigSetup) throws IOException {
    // Bug JDK-6244047: The default FileHandler does not handle the directory not existing,
    // so we have to create it before any log statements actually run.
    Files.createDirectories(logConfigSetup.getLogDir());

    if (logConfigSetup.getRotateLog()) {
        try {
            deleteOldLogFiles(logConfigSetup);
        } catch (IOException e) {
            System.err.format("Error deleting old log files (ignored): %s\n", e.getMessage());
        }
    }

    ImmutableList.Builder<InputStream> inputStreamsBuilder = ImmutableList.builder();
    if (!LogConfigPaths.MAIN_PATH.isPresent()) {
        System.err.format(
                "Error: Couldn't read system property %s (it should be set by buck_common or buck.cmd)\n",
                LogConfigPaths.BUCK_CONFIG_STRING_TEMPLATE_FILE_PROPERTY);
    } else {
        if (!addInputStreamForTemplate(LogConfigPaths.MAIN_PATH.get(), logConfigSetup, inputStreamsBuilder)) {
            System.err.format("Error: Couldn't open logging properties file %s\n",
                    LogConfigPaths.MAIN_PATH.get());
        }
    }

    // We ignore the return value for these files; they don't need to exist.
    addInputStreamForPath(LogConfigPaths.PROJECT_PATH, inputStreamsBuilder);
    addInputStreamForPath(LogConfigPaths.LOCAL_PATH, inputStreamsBuilder);

    // Concatenate each of the files together and read them in as a single properties file
    // for log settings.
    try (InputStream is = new SequenceInputStream(
            Iterators.asEnumeration(inputStreamsBuilder.build().iterator()))) {
        LogManager.getLogManager().readConfiguration(is);
    }
}

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

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

From source file:co.cask.cdap.common.lang.CombineClassLoader.java

@Override
protected Enumeration<URL> findResources(String name) throws IOException {
    // Using LinkedHashSet to preserve the ordering
    Set<URL> urls = Sets.newLinkedHashSet();
    for (ClassLoader classLoader : delegates) {
        Iterators.addAll(urls, Iterators.forEnumeration(classLoader.getResources(name)));
    }/*  ww  w.j  a  v  a2s . co m*/
    return Iterators.asEnumeration(urls.iterator());
}

From source file:org.apereo.portal.spring.security.RemoteUserSettingFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    final String remoteUser = StringUtils.trimToNull(FileUtils.readFileToString(this.remoteUserFile));

    if (remoteUser != null) {
        request = new HttpServletRequestWrapper((HttpServletRequest) request) {
            /* (non-Javadoc)
             * @see javax.servlet.http.HttpServletRequestWrapper#getRemoteUser()
             *///from w w w.  jav  a  2 s  . c  o m
            @Override
            public String getRemoteUser() {
                return remoteUser;
            }

            /* (non-Javadoc)
             * @see javax.servlet.http.HttpServletRequestWrapper#getHeader(java.lang.String)
             */
            @Override
            public String getHeader(String name) {
                if ("REMOTE_USER".equals(name)) {
                    return remoteUser;
                }
                return super.getHeader(name);
            }

            /* (non-Javadoc)
             * @see javax.servlet.http.HttpServletRequestWrapper#getHeaders(java.lang.String)
             */
            @Override
            public Enumeration<String> getHeaders(String name) {
                if ("REMOTE_USER".equals(name)) {
                    return Iterators.asEnumeration(Collections.singleton(remoteUser).iterator());
                }
                return super.getHeaders(name);
            }

            /* (non-Javadoc)
             * @see javax.servlet.http.HttpServletRequestWrapper#getHeaderNames()
             */
            @Override
            public Enumeration<String> getHeaderNames() {
                final LinkedHashSet<String> headers = new LinkedHashSet<String>();
                for (final Enumeration<String> headersEnum = super.getHeaderNames(); headersEnum
                        .hasMoreElements();) {
                    headers.add(headersEnum.nextElement());
                }
                headers.add("REMOTE_USER");

                return Iterators.asEnumeration(headers.iterator());
            }

            /* (non-Javadoc)
             * @see javax.servlet.http.HttpServletRequestWrapper#getIntHeader(java.lang.String)
             */
            @Override
            public int getIntHeader(String name) {
                if ("REMOTE_USER".equals(name)) {
                    return Integer.valueOf(remoteUser);
                }
                return super.getIntHeader(name);
            }
        };
    }

    chain.doFilter(request, response);
}