Example usage for java.util Collections list

List of usage examples for java.util Collections list

Introduction

In this page you can find the example usage for java.util Collections list.

Prototype

public static <T> ArrayList<T> list(Enumeration<T> e) 

Source Link

Document

Returns an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration.

Usage

From source file:com.feilong.core.bean.ConvertUtil.java

/**
 *  <code>enumeration</code> ??.
 * /*from  w ww  .j a  va  2  s .  co  m*/
 * @param <T>
 *            the generic type
 * @param enumeration
 *            the enumeration
 * @return  <code>enumeration</code> null, {@link Collections#emptyList()}<br>
 *         ? {@link Collections#list(Enumeration)}
 * @see Collections#emptyList()
 * @see Collections#EMPTY_LIST
 * @see Collections#list(Enumeration)
 * @see EnumerationUtils#toList(Enumeration)
 * @since 1.0.7
 */
public static <T> List<T> toList(final Enumeration<T> enumeration) {
    return null == enumeration ? Collections.<T>emptyList() : Collections.list(enumeration);
}

From source file:org.apereo.portal.layout.dlm.DistributedLayoutManager.java

private boolean canMoveRight(String nodeId, String targetNextSibId) throws PortalException {
    IUserLayoutNodeDescription node = getNode(nodeId);
    Enumeration sibIds = getVisibleChildIds(getParentId(nodeId));
    List sibs = Collections.list(sibIds);

    for (int idx = sibs.indexOf(nodeId) + 1; idx > 0 && idx < sibs.size(); idx++) {
        String nextSibId = (String) sibs.get(idx);
        IUserLayoutNodeDescription next = getNode(nextSibId);

        if (nextSibId != null && next.getId().equals(targetNextSibId))
            return true;
        else if (!isFragmentOwner && !MovementRules.canHopRight(node, next))
            return false;
    }/*from  ww  w .ja va2 s . c om*/

    if (targetNextSibId == null) // made it to end of sib list and
        return true; // that is the desired location
    return false; // oops never found the sib. Should never happen.
}

From source file:org.xwoot.jxta.mock.MockJxtaPeer.java

/** {@inheritDoc} **/
public Object sendObjectToRandomPeerInGroup(Object object, boolean expectReply)
        throws PeerGroupException, IllegalArgumentException, JxtaException {
    if (!this.isConnectedToGroup()) {
        throw new PeerGroupException("The peer has not yet joined a group and contacted a group RDV peer.");
    }/*  ww  w  .  j  av a 2 s .c om*/

    if (!(object instanceof Serializable)) {
        throw new IllegalArgumentException(
                "The object does not implement the interface java.io.Serializable and can not be sent.");
    }

    this.logger.info("Trying to send an object to a random peer in the group.");

    Object reply = null;
    boolean success = false;

    for (int i = 0; i < NUMBER_OF_TRIES && !success; i++) {
        this.logger.info("Try number: " + i);

        // simulate discovery process.
        List<Advertisement> knownPipeAdvs = Collections
                .list(this.getKnownDirectCommunicationPipeAdvertisements());

        Set<MockJxtaPeer> peersInGroup = MockJxtaPeer.groupsWithPeersMap
                .get(this.currentJoinedGroup.getPeerGroupAdvertisement());
        for (MockJxtaPeer peer : peersInGroup) {
            // if we discovered this peer and it is not our peer then try to send the message.
            if (!peer.equals(this)
                    && knownPipeAdvs.contains(peer.getMyDirectCommunicationPipeAdvertisement())) {
                PipeAdvertisement pipeAdv = peer.getMyDirectCommunicationPipeAdvertisement();

                this.logger.info("Trying to send through this pipe advertisement:\n" + pipeAdv);

                try {
                    reply = this.sendObject(object, pipeAdv);
                } catch (Exception e) {
                    this.logger.error("Failed to send object to this peer.\n", e);
                    continue;
                }

                if (expectReply && reply == null) {
                    this.logger.warn("Peer contacted but no reply given. Skipping");
                    continue;
                }

                success = true;
                break;
            }
        }

        // If success, don`t go to sleep anymore.
        if (success) {
            break;
        }

        // Wait for advertisement discovery to get more possible pipe advs.
        try {
            Thread.sleep(WAIT_INTERVAL_BETWEEN_TRIES);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    this.logger.info("Object successfuly sent: " + success);
    if (!success) {
        throw new JxtaException(
                "Failed to send message. No peer group member found or none of them could receive it. Try again later.");
    }

    return reply;
}

From source file:org.lsc.jndi.JndiServices.java

/**
 * Return the LDAP schema.//w  w w  .  ja  va 2  s .c  om
 *
 * @param attrsToReturn
 *                list of attribute names to return (or null for all
 *                'standard' attributes)
 * @return the map of name => attribute
 * @throws NamingException
 *                 thrown if something goes wrong (bad
 */
@SuppressWarnings("unchecked")
public Map<String, List<String>> getSchema(final String[] attrsToReturn) throws NamingException {
    Map<String, List<String>> attrsResult = new HashMap<String, List<String>>();

    // connect to directory
    Hashtable<String, String> props = (Hashtable<String, String>) ctx.getEnvironment();
    String baseUrl = (String) props.get(Context.PROVIDER_URL);
    baseUrl = baseUrl.substring(0, baseUrl.lastIndexOf('/'));
    props.put(Context.PROVIDER_URL, baseUrl);
    DirContext schemaCtx = new InitialLdapContext(props, null);

    // find schema entry
    SearchControls sc = new SearchControls();
    sc.setSearchScope(SearchControls.OBJECT_SCOPE);
    sc.setReturningAttributes(new String[] { "subschemaSubentry" });

    NamingEnumeration<SearchResult> schemaDnSR = schemaCtx.search("", "(objectclass=*)", sc);

    SearchResult sr = null;
    Attribute subschemaSubentry = null;
    String subschemaSubentryDN = null;

    if (schemaDnSR.hasMore()) {
        sr = schemaDnSR.next();
    }
    if (sr != null) {
        subschemaSubentry = sr.getAttributes().get("subschemaSubentry");
    }
    if (subschemaSubentry != null && subschemaSubentry.size() > 0) {
        subschemaSubentryDN = (String) subschemaSubentry.get();
    }

    if (subschemaSubentryDN != null) {
        // get schema attributes from subschemaSubentryDN
        Attributes schemaAttrs = schemaCtx.getAttributes(subschemaSubentryDN,
                attrsToReturn != null ? attrsToReturn : new String[] { "*", "+" });

        if (schemaAttrs != null) {
            for (String attr : attrsToReturn) {
                Attribute schemaAttr = schemaAttrs.get(attr);
                if (schemaAttr != null) {
                    attrsResult.put(schemaAttr.getID(), (List<String>) Collections.list(schemaAttr.getAll()));
                }
            }
        }
    }

    return attrsResult;
}

From source file:org.jasig.portal.layout.dlm.DistributedLayoutManager.java

private boolean canMoveLeft(String nodeId, String targetNextSibId) throws PortalException {
    IUserLayoutNodeDescription node = getNode(nodeId);
    Enumeration sibIds = getVisibleChildIds(getParentId(nodeId));
    List sibs = Collections.list(sibIds);

    for (int idx = sibs.indexOf(nodeId) - 1; idx >= 0; idx--) {
        String prevSibId = (String) sibs.get(idx);
        IUserLayoutNodeDescription prev = getNode(prevSibId);

        if (!MovementRules.canHopLeft(node, prev))
            return false;
        if (targetNextSibId != null && prev.getId().equals(targetNextSibId))
            return true;
    }//from w w w .j  a v  a 2  s .c om
    return false; // oops never found the sib
}

From source file:org.apache.nifi.web.server.JettyServer.java

private void dumpUrls() throws SocketException {
    final List<String> urls = new ArrayList<>();

    for (Connector connector : server.getConnectors()) {
        if (connector instanceof ServerConnector) {
            final ServerConnector serverConnector = (ServerConnector) connector;

            Set<String> hosts = new HashSet<>();

            // determine the hosts
            if (StringUtils.isNotBlank(serverConnector.getHost())) {
                hosts.add(serverConnector.getHost());
            } else {
                Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
                if (networkInterfaces != null) {
                    for (NetworkInterface networkInterface : Collections.list(networkInterfaces)) {
                        for (InetAddress inetAddress : Collections.list(networkInterface.getInetAddresses())) {
                            hosts.add(inetAddress.getHostAddress());
                        }//  w  w w.  j a  v  a  2  s .co  m
                    }
                }
            }

            // ensure some hosts were found
            if (!hosts.isEmpty()) {
                String scheme = "http";
                if (props.getSslPort() != null && serverConnector.getPort() == props.getSslPort()) {
                    scheme = "https";
                }

                // dump each url
                for (String host : hosts) {
                    urls.add(String.format("%s://%s:%s", scheme, host, serverConnector.getPort()));
                }
            }
        }
    }

    if (urls.isEmpty()) {
        logger.warn(
                "NiFi has started, but the UI is not available on any hosts. Please verify the host properties.");
    } else {
        // log the ui location
        logger.info("NiFi has started. The UI is available at the following URLs:");
        for (final String url : urls) {
            logger.info(String.format("%s/nifi", url));
        }
    }
}

From source file:org.apereo.portal.layout.dlm.DistributedLayoutManager.java

private boolean canMoveLeft(String nodeId, String targetNextSibId) throws PortalException {
    IUserLayoutNodeDescription node = getNode(nodeId);
    Enumeration sibIds = getVisibleChildIds(getParentId(nodeId));
    List sibs = Collections.list(sibIds);

    for (int idx = sibs.indexOf(nodeId) - 1; idx >= 0; idx--) {
        String prevSibId = (String) sibs.get(idx);
        IUserLayoutNodeDescription prev = getNode(prevSibId);

        if (!isFragmentOwner && !MovementRules.canHopLeft(node, prev))
            return false;
        if (targetNextSibId != null && prev.getId().equals(targetNextSibId))
            return true;
    }//from ww w.jav a  2s.  c o  m
    return false; // oops never found the sib
}

From source file:org.nuxeo.theme.editor.Main.java

@POST
@Path("expand_css_categories")
@SuppressWarnings("unchecked")
public void expandCssCategories() {
    Properties cssStyleCategories = org.nuxeo.theme.editor.Utils.getCssStyleCategories();
    List<String> allCssCategories = (List<String>) Collections.list(cssStyleCategories.propertyNames());
    SessionManager.setSelectedCssCategories(allCssCategories);
}

From source file:org.apache.openejb.config.DeploymentLoader.java

public static void addBeansXmls(final WebModule webModule) {
    final List<URL> urls = webModule.getScannableUrls();
    // parent returns nothing when calling getresources because we don't want here to be fooled by maven classloader
    final URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]),
            new EmptyResourcesClassLoader());

    final List<URL> xmls = new LinkedList<>();
    try {//w ww  . j a  va2  s  .com
        final URL e = (URL) webModule.getAltDDs().get("beans.xml");
        if (e != null) { // first!
            xmls.add(e);
        }
        xmls.addAll(Collections.list(loader.getResources("META-INF/beans.xml")));
    } catch (final IOException e) {
        return;
    }

    final CompositeBeans complete = new CompositeBeans();
    for (final URL url : xmls) {
        if (url == null) {
            continue;
        }
        mergeBeansXml(complete, url);
    }
    if (!complete.getDiscoveryByUrl().isEmpty()) {
        complete.removeDuplicates();
        webModule.getAltDDs().put("beans.xml", complete);
    }
}