Search in sources :

Example 56 with ListIterator

use of java.util.ListIterator in project Payara by payara.

the class WoodstockHandler method populateApplicationsMonitorDropDown.

/**
 * <p>
 * Returns the list of monitorable application components</p>
 */
@Handler(id = "populateApplicationsMonitorDropDown", input = { @HandlerInput(name = "AppsList", type = List.class, required = true), @HandlerInput(name = "monitorURL", type = String.class, required = true) }, output = { @HandlerOutput(name = "MonitorList", type = Option[].class), @HandlerOutput(name = "FirstItem", type = String.class) })
public void populateApplicationsMonitorDropDown(HandlerContext handlerCtx) {
    List aList = (List) handlerCtx.getInputValue("AppsList");
    String monitorURL = (String) handlerCtx.getInputValue("monitorURL");
    ArrayList menuList = new ArrayList();
    String firstItem = null;
    String title = null;
    if (aList != null) {
        ListIterator al = aList.listIterator();
        while (al.hasNext()) {
            ArrayList moduleList = new ArrayList();
            String appName = (String) al.next();
            // Add the application name link in the dropdown if there are any app scoped resources.
            if (MonitoringHandlers.doesMonitoringDataExist(monitorURL + "/applications/" + appName + "/resources")) {
                moduleList.add(appName);
            }
            Set<String> modules = new HashSet<String>();
            try {
                modules = RestUtil.getChildMap(GuiUtil.getSessionValue("REST_URL") + "/applications/application/" + appName + "/module").keySet();
            } catch (Exception ex) {
                GuiUtil.handleException(handlerCtx, ex);
            }
            for (String moduleName : modules) {
                if (MonitoringHandlers.doesAppProxyExist(appName, moduleName)) {
                    if (!moduleList.contains(moduleName)) {
                        moduleList.add(moduleName);
                    }
                }
            }
            if (moduleList.isEmpty()) {
                menuList.add(new Option(appName, appName));
                if (firstItem == null) {
                    firstItem = appName;
                }
            } else {
                OptionGroup menuOptions = getMenuOptions(moduleList, appName, "", false);
                menuList.add(menuOptions);
                if (firstItem == null) {
                    firstItem = (String) moduleList.get(0);
                }
            }
        }
    }
    // Add Menu Options.
    jumpMenuOptions = (Option[]) menuList.toArray(new Option[menuList.size()]);
    handlerCtx.setOutputValue("MonitorList", jumpMenuOptions);
    handlerCtx.setOutputValue("FirstItem", firstItem);
}
Also used : OptionGroup(com.sun.webui.jsf.model.OptionGroup) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Option(com.sun.webui.jsf.model.Option) ListIterator(java.util.ListIterator) IOException(java.io.IOException) HashSet(java.util.HashSet) Handler(com.sun.jsftemplating.annotation.Handler)

Example 57 with ListIterator

use of java.util.ListIterator in project jop by jop-devel.

the class RandomAccessSubList method equals.

// Comparison and hashing
/**
     * Compares the specified object with this list for equality.  Returns
     * {@code true} if and only if the specified object is also a list, both
     * lists have the same size, and all corresponding pairs of elements in
     * the two lists are <i>equal</i>.  (Two elements {@code e1} and
     * {@code e2} are <i>equal</i> if {@code (e1==null ? e2==null :
     * e1.equals(e2))}.)  In other words, two lists are defined to be
     * equal if they contain the same elements in the same order.<p>
     *
     * This implementation first checks if the specified object is this
     * list. If so, it returns {@code true}; if not, it checks if the
     * specified object is a list. If not, it returns {@code false}; if so,
     * it iterates over both lists, comparing corresponding pairs of elements.
     * If any comparison returns {@code false}, this method returns
     * {@code false}.  If either iterator runs out of elements before the
     * other it returns {@code false} (as the lists are of unequal length);
     * otherwise it returns {@code true} when the iterations complete.
     *
     * @param o the object to be compared for equality with this list
     * @return {@code true} if the specified object is equal to this list
     */
public boolean equals(Object o) {
    if (o == this)
        return true;
    if (!(o instanceof List))
        return false;
    ListIterator<E> e1 = listIterator();
    ListIterator e2 = ((List) o).listIterator();
    while (e1.hasNext() && e2.hasNext()) {
        E o1 = e1.next();
        Object o2 = e2.next();
        if (!(o1 == null ? o2 == null : o1.equals(o2)))
            return false;
    }
    return !(e1.hasNext() || e2.hasNext());
}
Also used : List(java.util.List) ListIterator(java.util.ListIterator)

Example 58 with ListIterator

use of java.util.ListIterator in project jop by jop-devel.

the class RandomAccessSubList method listIterator.

public ListIterator<E> listIterator(final int index) {
    checkForComodification();
    if (index < 0 || index > size)
        throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
    return new ListIterator<E>() {

        private ListIterator<E> i = l.listIterator(index + offset);

        public boolean hasNext() {
            return nextIndex() < size;
        }

        public E next() {
            if (hasNext())
                return i.next();
            else
                throw new NoSuchElementException();
        }

        public boolean hasPrevious() {
            return previousIndex() >= 0;
        }

        public E previous() {
            if (hasPrevious())
                return i.previous();
            else
                throw new NoSuchElementException();
        }

        public int nextIndex() {
            return i.nextIndex() - offset;
        }

        public int previousIndex() {
            return i.previousIndex() - offset;
        }

        public void remove() {
            i.remove();
            expectedModCount = l.modCount;
            size--;
            modCount++;
        }

        public void set(E e) {
            i.set(e);
        }

        public void add(E e) {
            i.add(e);
            expectedModCount = l.modCount;
            size++;
            modCount++;
        }
    };
}
Also used : ListIterator(java.util.ListIterator) NoSuchElementException(java.util.NoSuchElementException)

Example 59 with ListIterator

use of java.util.ListIterator in project Openfire by igniterealtime.

the class SipCommRouter method getNextHops.

/**
     * Return the default address to forward the request to. The list is
     * organized in the following priority.
     * <p/>
     * If the outboung proxy has been specified, then it is used to construct
     * the first element of the list.
     * <p/>
     * If the requestURI refers directly to a host, the host and port
     * information are extracted from it and made the next hop on the list.
     *
     * @param sipRequest is the sip request to route.
     */
public ListIterator<Hop> getNextHops(Request sipRequest) {
    URI requestURI = sipRequest.getRequestURI();
    if (requestURI == null) {
        throw new IllegalArgumentException("Bad message: Null requestURI");
    }
    LinkedList<Hop> hops = new LinkedList<Hop>();
    if (outboundProxy != null) {
        hops.add(outboundProxy);
    }
    ListIterator routes = sipRequest.getHeaders(RouteHeader.NAME);
    if (routes != null && routes.hasNext()) {
        while (routes.hasNext()) {
            RouteHeader route = (RouteHeader) routes.next();
            SipURI uri = (SipURI) route.getAddress().getURI();
            int port = uri.getPort();
            port = (port == -1) ? 5060 : port;
            String host = uri.getHost();
            Log.debug("getNextHops", host);
            String transport = uri.getTransportParam();
            if (transport == null) {
                transport = "udp";
            }
            Hop hop = new SipCommHop(host + ':' + port + '/' + transport);
            hops.add(hop);
        }
    } else if (requestURI instanceof SipURI && ((SipURI) requestURI).getMAddrParam() != null) {
        SipURI sipURI = ((SipURI) requestURI);
        String maddr = sipURI.getMAddrParam();
        String transport = sipURI.getTransportParam();
        if (transport == null) {
            transport = "udp";
        }
        int port = 5060;
        Hop hop = new SipCommHop(maddr, port, transport);
        hops.add(hop);
    } else if (requestURI instanceof SipURI) {
        SipURI sipURI = ((SipURI) requestURI);
        int port = sipURI.getPort();
        if (port == -1) {
            port = 5060;
        }
        String host = sipURI.getHost();
        String transport = sipURI.getTransportParam();
        if (transport == null) {
            transport = "UDP";
        }
        Hop hop = new SipCommHop(host + ":" + port + "/" + transport);
        hops.add(hop);
    } else {
        throw new IllegalArgumentException("Malformed requestURI");
    }
    return (hops.size() == 0) ? null : hops.listIterator();
}
Also used : RouteHeader(javax.sip.header.RouteHeader) Hop(javax.sip.address.Hop) ListIterator(java.util.ListIterator) SipURI(javax.sip.address.SipURI) SipURI(javax.sip.address.SipURI) URI(javax.sip.address.URI) LinkedList(java.util.LinkedList)

Example 60 with ListIterator

use of java.util.ListIterator in project hudson-2.x by hudson.

the class BeanBuilder method manageListIfNecessary.

/**
	 * Checks whether there are any runtime refs inside the list and
	 * converts it to a ManagedList if necessary
	 *
	 * @param value The object that represents the list
	 * @return Either a new list or a managed one
	 */
private Object manageListIfNecessary(Object value) {
    List list = (List) value;
    boolean containsRuntimeRefs = false;
    for (ListIterator i = list.listIterator(); i.hasNext(); ) {
        Object e = i.next();
        if (e instanceof RuntimeBeanReference) {
            containsRuntimeRefs = true;
        }
        if (e instanceof BeanConfiguration) {
            BeanConfiguration c = (BeanConfiguration) e;
            i.set(c.getBeanDefinition());
            containsRuntimeRefs = true;
        }
    }
    if (containsRuntimeRefs) {
        List tmp = new ManagedList();
        tmp.addAll((List) value);
        value = tmp;
    }
    return value;
}
Also used : ManagedList(org.springframework.beans.factory.support.ManagedList) List(java.util.List) GroovyObject(groovy.lang.GroovyObject) ManagedList(org.springframework.beans.factory.support.ManagedList) ListIterator(java.util.ListIterator) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Aggregations

ListIterator (java.util.ListIterator)121 ArrayList (java.util.ArrayList)42 List (java.util.List)41 LinkedList (java.util.LinkedList)26 Iterator (java.util.Iterator)21 Map (java.util.Map)12 Handler (com.sun.jsftemplating.annotation.Handler)8 AbstractList (java.util.AbstractList)7 HashMap (java.util.HashMap)7 AbstractSequentialList (java.util.AbstractSequentialList)6 IOException (java.io.IOException)5 RandomAccess (java.util.RandomAccess)5 SelectResults (org.apache.geode.cache.query.SelectResults)5 Test (org.junit.Test)5 File (java.io.File)4 HashSet (java.util.HashSet)4 NoSuchElementException (java.util.NoSuchElementException)4 SipURI (javax.sip.address.SipURI)4 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)4 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)4