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:org.apache.servicecomb.foundation.vertx.http.TestStandardHttpServletRequestEx.java

@Test
public void parameterMap_inherited() {
    Map<String, String[]> inherited = new HashMap<>();
    String[] v1 = new String[] { "v1-1", "v1-2" };
    inherited.put("p1", v1);
    new Expectations() {
        {//from   w ww. j a  v  a  2s . c o m
            request.getParameterMap();
            result = inherited;
            request.getMethod();
            result = HttpMethod.POST;
        }
    };

    Assert.assertSame(inherited, requestEx.getParameterMap());
    Assert.assertThat(Collections.list(requestEx.getParameterNames()), Matchers.contains("p1"));
    Assert.assertSame(v1, requestEx.getParameterValues("p1"));
    Assert.assertEquals("v1-1", requestEx.getParameter("p1"));
}

From source file:org.onosproject.ospf.controller.impl.Controller.java

/**
 * Tell controller that we're ready to handle channels.
 *//*from w w  w  .j  a va2 s . c om*/
public void run() {
    try {
        //get the configuration from json file
        List<OSPFArea> areas = getConfiguration();
        //get the connected interfaces
        Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
        // Check NetworkInterfaces and area-config have same IP Address
        for (NetworkInterface netInt : Collections.list(nets)) {
            // if the interface is up & not loopback
            if (!netInt.isUp() && !netInt.isLoopback()) {
                continue;
            }
            //get all the InetAddresses
            Enumeration<InetAddress> inetAddresses = netInt.getInetAddresses();
            for (InetAddress inetAddress : Collections.list(inetAddresses)) {
                String ipAddress = inetAddress.getHostAddress();
                //Search for the address in all configured areas interfaces
                for (OSPFArea area : areas) {
                    for (OSPFInterface ospfIf : area.getInterfacesLst()) {
                        String ipFromConfig = ospfIf.getIpAddress();
                        if (ipFromConfig.trim().equals(ipAddress.trim())) {
                            log.debug("Both Config and Interface have ipAddress {} for area {}", ipAddress,
                                    area.getAreaID());
                            // if same IP address create
                            try {
                                log.debug("Creating ServerBootstrap for {} @ {}", ipAddress, ospfPort);

                                final ServerBootstrap bootstrap = createServerBootStrap();
                                bootstrap.setOption("reuseAddr", true);
                                bootstrap.setOption("child.keepAlive", true);
                                bootstrap.setOption("child.tcpNoDelay", true);
                                bootstrap.setOption("child.sendBufferSize", Controller.BUFFER_SIZE);

                                //Set the interface name in ospfInterface
                                ospfIf.setInterfaceName(netInt.getDisplayName());
                                //netInt.get
                                // passing OSPFArea and interface to pipelinefactory
                                ChannelPipelineFactory pfact = new OSPFPipelineFactory(this, null, area,
                                        ospfIf);
                                bootstrap.setPipelineFactory(pfact);
                                InetSocketAddress sa = new InetSocketAddress(InetAddress.getByName(ipAddress),
                                        ospfPort);

                                cg = new DefaultChannelGroup();
                                cg.add(bootstrap.bind(sa));

                                log.debug("Listening for connections on {}", sa);
                                //For testing. remove this
                                interfc = ospfIf;

                                //Start aging process
                                area.initializeDB();
                                area.initializeArea();
                            } catch (Exception e) {
                                throw new RuntimeException(e);
                            }
                        }
                    }
                }
            }
        }

    } catch (Exception e) {
        log.error("Error::Controller:: {}", e.getMessage());
    }
}

From source file:com.smartdevicelink.tcpdiscovery.DiscoveredDevice.java

private String getLocalAddressForIface(String ifaceName) throws Exception {
    NetworkInterface iface = NetworkInterface.getByName(ifaceName);
    Enumeration<InetAddress> inetAddresses = iface.getInetAddresses();
    for (InetAddress inetAddress : Collections.list(inetAddresses)) {
        if (InetAddressUtils.isIPv4Address(inetAddress.toString())) {
            return inetAddress.toString();
        }/*from  w  w w  .ja  va  2 s.c o m*/
    }
    return "";
}

From source file:czlab.wabbit.CljPodLoader.java

private List<URL> toList(Enumeration<URL> e) {
    return e == null ? new ArrayList<URL>() : Collections.list(e);
}

From source file:com.jkoolcloud.tnt4j.streams.format.FactPathValueFormatter.java

private static <T> Collection<T> getSortedCollection(Collection<T> col, Comparator<T> comp) {
    List<T> cList;/*  ww w  . j a  va  2s . c o  m*/
    if (col instanceof List<?>) {
        cList = (List<T>) col;
    } else {
        cList = Collections.list(Collections.enumeration(col));
    }
    Collections.sort(cList, comp);

    return cList;
}

From source file:psiprobe.tools.logging.log4j.Log4JManagerAccessor.java

/**
 * Gets the appenders.//from w  ww  .  jav a2 s .  c om
 *
 * @return the appenders
 */
public List<Log4JAppenderAccessor> getAppenders() {
    List<Log4JAppenderAccessor> appenders = new ArrayList<>();
    try {
        appenders.addAll(getRootLogger().getAppenders());

        Class clazz = (Class) getTarget();
        Method getCurrentLoggers = MethodUtils.getAccessibleMethod(clazz, "getCurrentLoggers", new Class[0]);

        for (Object currentLogger : Collections.list((Enumeration<Object>) getCurrentLoggers.invoke(null))) {
            Log4JLoggerAccessor accessor = new Log4JLoggerAccessor();
            accessor.setTarget(currentLogger);
            accessor.setApplication(getApplication());

            appenders.addAll(accessor.getAppenders());
        }
    } catch (Exception e) {
        logger.error("{}#getCurrentLoggers() failed", getTarget().getClass().getName(), e);
    }
    return appenders;
}

From source file:org.thingsplode.agent.monitors.providers.SystemComponentProvider.java

private List<Component> getNetwork() {
    try {/*from w ww .  j  a va  2 s  .com*/
        List<Component> networkComps = new ArrayList<>();
        Collections.list(NetworkInterface.getNetworkInterfaces()).forEach(n -> {
            try {

                CapabilityBuilder cb = Capability.CapabilityBuilder.newBuilder();
                cb.add("hw_address", Capability.Type.READ, true, Value.Type.TEXT,
                        Arrays.toString(n.getHardwareAddress())).add("hw_index", Capability.Type.READ, true,
                                Value.Type.TEXT, String.valueOf(n.getIndex()));

                if (n.getInetAddresses() != null) {
                    Collections.list(n.getInetAddresses()).forEach(ia -> {
                        cb.add("host_address", Capability.Type.READ, true, Value.Type.TEXT,
                                ia.getHostAddress());
                    });
                }

                Component nic = Component
                        .create(n.getDisplayName(), Component.Type.HARDWARE, EnabledState.ENABLED)
                        .putStatusInfo(n.isUp() ? StatusInfo.ONLINE : StatusInfo.OFFLINE)
                        .addCapabilities(cb.build());

                networkComps.add(nic);

            } catch (SocketException ex) {
                logAndSendError(ex);
            }
        });
        return networkComps;
    } catch (SocketException ex) {
        logAndSendError(ex);
        return null;
    }
}

From source file:net.sf.jabref.collab.EntryChange.java

@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
    boolean allAccepted = true;

    Enumeration<Change> e = children();
    for (Change c : Collections.list(e)) {
        if (c.isAcceptable() && c.isAccepted()) {
            c.makeChange(panel, secondary, undoEdit);
        } else {/*w ww.j  a v a 2  s  .  co m*/
            allAccepted = false;
        }
    }

    /*panel.database().removeEntry(memEntry.getId());
    try {
      diskEntry.setId(Util.next());
    } catch (KeyCollisionException ex) {}
    panel.database().removeEntry(memEntry.getId());*/

    return allAccepted;
}

From source file:eu.planets_project.tb.gui.backing.ListExp.java

public Collection<Experiment> getExperimentsOfUser() {
    // Get all experiments created/owned by the current user  
    // get user id from MB facility
    // get UserBean - grab userid   
    /*List<Experiment> usersExpList = new ArrayList<Experiment>();*/
    UserBean managedUserBean = (UserBean) JSFUtil.getManagedObject("UserBean");
    String userid = managedUserBean.getUserid();
    TestbedManager testbedMan = (TestbedManager) JSFUtil.getManagedObject("TestbedManager");
    /*Iterator<Experiment> iter = testbedMan.getAllExperiments().iterator();        
    while (iter.hasNext()) {//from   ww  w  . j a  v a 2s  . c  o m
       Experiment exp = iter.next();
       if (userid.equals(exp.getExperimentSetup().getBasicProperties().getExperimenter()))
      usersExpList.add(exp);
    }
    myExps = usersExpList; */
    Collection<Experiment> myExps = testbedMan.getAllExperimentsOfUsers(userid, true);
    currExps = Collections.list(Collections.enumeration(myExps));
    sort(getSort(), isAscending());
    return currExps;
}

From source file:in.andres.kandroid.ui.ProjectOverviewFragment.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    KanboardProject project = ((MainActivity) getActivity()).getProject();
    if (project != null) {
        assert getView() != null : "ProjectOverviewFragment: getView() returned null";
        TextView projectDescription = (TextView) getView().findViewById(R.id.project_description);
        TextView projectNBActiveTasks = (TextView) getView().findViewById(R.id.project_active_tasks);
        TextView projectNBInactiveTasks = (TextView) getView().findViewById(R.id.project_inactive_tasks);
        TextView projectNBOverdueTasks = (TextView) getView().findViewById(R.id.project_overdue_tasks);
        TextView projectNBTotalTasks = (TextView) getView().findViewById(R.id.project_total_tasks);
        TextView projectModifyDate = (TextView) getView().findViewById(R.id.project_modify_date);
        TextView projectMembers = (TextView) getView().findViewById(R.id.project_members);
        TextView projectColumns = (TextView) getView().findViewById(R.id.project_columns);
        TextView projectSwimlanes = (TextView) getView().findViewById(R.id.project_swimlanes);

        if (!project.getDescription().contentEquals("")) {
            projectDescription/*from  ww w .  ja  v  a2  s  .c o m*/
                    .setText(Utils.fromHtml(mRenderer.render(mParser.parse(project.getDescription()))));
        } else {
            getView().findViewById(R.id.card_description).setVisibility(View.GONE);
        }
        projectMembers.setText(Utils.fromHtml(TextUtils.join(" <big><b>|</b></big> ",
                Collections.list(project.getProjectUsers().elements()))));
        projectColumns.setText(Utils.fromHtml(TextUtils.join(" <big><b>|</b></big> ", project.getColumns())));
        projectSwimlanes
                .setText(Utils.fromHtml(TextUtils.join(" <big><b>|</b></big> ", project.getSwimlanes())));
        projectNBActiveTasks
                .setText(getContext().getResources().getQuantityString(R.plurals.format_nb_active_tasks,
                        project.getActiveTasks().size(), project.getActiveTasks().size()));
        projectNBInactiveTasks
                .setText(getContext().getResources().getQuantityString(R.plurals.format_nb_inactive_tasks,
                        project.getInactiveTasks().size(), project.getInactiveTasks().size()));
        projectNBOverdueTasks
                .setText(getContext().getResources().getQuantityString(R.plurals.format_nb_overdue_tasks,
                        project.getOverdueTasks().size(), project.getOverdueTasks().size()));
        projectNBTotalTasks
                .setText(getContext().getResources().getQuantityString(R.plurals.format_nb_total_tasks,
                        project.getActiveTasks().size() + project.getInactiveTasks().size(),
                        project.getActiveTasks().size() + project.getInactiveTasks().size()));
        projectModifyDate.setText(DateFormat.getLongDateFormat(getContext()).format(project.getLastModified())
                + " " + DateFormat.getTimeFormat(getContext()).format(project.getLastModified()));
    }
}