Example usage for org.apache.commons.collections Buffer remove

List of usage examples for org.apache.commons.collections Buffer remove

Introduction

In this page you can find the example usage for org.apache.commons.collections Buffer remove.

Prototype

Object remove();

Source Link

Document

Gets and removes the next object from the buffer.

Usage

From source file:org.apache.excalibur.event.impl.DefaultQueue.java

/**
 * Removes the given number of elements from the given <code>buf</code>
 * and returns them in an array. Trusts the caller to pass in a buffer
 * full of <code>Object</code>s and with at least
 * <code>count</code> elements available.
 * <p>//from  w w w .  j a v  a2  s .  c  o  m
 * @param buf to remove elements from, the caller is responsible
 *            for synchronizing access
 * @param count number of elements to remove/return
 * @return requested number of elements
 */
private static Object[] retrieveElements(Buffer buf, int count) {
    Object[] elements = new Object[count];

    for (int i = 0; i < count; i++) {
        elements[i] = buf.remove();
    }

    return elements;
}

From source file:org.opencms.gwt.CmsCoreService.java

/**
 * @see org.opencms.gwt.shared.rpc.I_CmsCoreService#getBroadcast()
 *///from w  ww  . j a v  a 2  s  .  c  o  m
public List<CmsBroadcastMessage> getBroadcast() {

    OpenCms.getWorkplaceManager().checkWorkplaceRequest(getRequest(), getCmsObject());
    CmsSessionInfo sessionInfo = OpenCms.getSessionManager().getSessionInfo(getRequest().getSession());
    if (sessionInfo == null) {
        return null;
    }
    String sessionId = sessionInfo.getSessionId().toString();
    Buffer messageQueue = OpenCms.getSessionManager().getBroadcastQueue(sessionId);
    if (!messageQueue.isEmpty()) {
        CmsMessages messages = org.opencms.workplace.Messages.get()
                .getBundle(OpenCms.getWorkplaceManager().getWorkplaceLocale(getCmsObject()));
        List<CmsBroadcastMessage> result = new ArrayList<CmsBroadcastMessage>();
        // the user has pending messages, display them all
        while (!messageQueue.isEmpty()) {
            CmsBroadcast broadcastMessage = (CmsBroadcast) messageQueue.remove();
            CmsBroadcastMessage message = new CmsBroadcastMessage(
                    broadcastMessage.getUser() != null ? broadcastMessage.getUser().getName()
                            : messages.key(org.opencms.workplace.Messages.GUI_LABEL_BROADCAST_FROM_SYSTEM_0),
                    messages.getDateTime(broadcastMessage.getSendTime()), broadcastMessage.getMessage());
            result.add(message);
        }
        return result;
    }
    // no message pending, return null
    return null;
}

From source file:org.opencms.ui.apps.CmsAppWorkplaceUi.java

/**
 * Checks for new broadcasts.<p>//from  www.  j  a  v  a2 s  .  c o  m
 */
public void checkBroadcasts() {

    CmsSessionInfo info = OpenCms.getSessionManager().getSessionInfo(getHttpSession());
    Buffer queue = info.getBroadcastQueue();
    if (!queue.isEmpty()) {
        StringBuffer broadcasts = new StringBuffer();
        while (!queue.isEmpty()) {
            CmsBroadcast broadcastMessage = (CmsBroadcast) queue.remove();
            String from = broadcastMessage.getUser() != null ? broadcastMessage.getUser().getName()
                    : CmsVaadinUtils
                            .getMessageText(org.opencms.workplace.Messages.GUI_LABEL_BROADCAST_FROM_SYSTEM_0);
            String date = CmsVaadinUtils.getWpMessagesForCurrentLocale()
                    .getDateTime(broadcastMessage.getSendTime());
            String content = broadcastMessage.getMessage();
            content = content.replaceAll("\\n", "<br />");
            broadcasts.append("<p><em>").append(date).append("</em><br />");
            broadcasts
                    .append(CmsVaadinUtils
                            .getMessageText(org.opencms.workplace.Messages.GUI_LABEL_BROADCASTMESSAGEFROM_0))
                    .append(" <b>").append(from).append("</b>:</p><p>");
            broadcasts.append(content).append("<br /></p>");
        }
        Notification notification = new Notification(
                CmsVaadinUtils.getMessageText(Messages.GUI_BROADCAST_TITLE_0), broadcasts.toString(),
                Type.WARNING_MESSAGE, true);
        notification.setDelayMsec(-1);
        notification.show(getPage());
    }
}

From source file:org.opencms.workplace.CmsWorkplace.java

/**
 * Returns the message String for the broadcast message alert of the workplace.<p>
 * //from   w w w.  j  a  v a 2  s . c  o m
 * Caution: returns the pure message String (not escaped) or null, if no message is pending.<p>
 * 
 * @return the message String for the broadcast message alert of the workplace
 */
public String getBroadcastMessageString() {

    CmsSessionInfo sessionInfo = OpenCms.getSessionManager().getSessionInfo(getSession());
    if (sessionInfo == null) {
        return null;
    }
    String sessionId = sessionInfo.getSessionId().toString();
    Buffer messageQueue = OpenCms.getSessionManager().getBroadcastQueue(sessionId);
    if (!messageQueue.isEmpty()) {
        // create message String
        StringBuffer result = new StringBuffer(512);
        // the user has pending messages, display them all
        while (!messageQueue.isEmpty()) {
            CmsBroadcast message = (CmsBroadcast) messageQueue.remove();
            result.append('[');
            result.append(getMessages().getDateTime(message.getSendTime()));
            result.append("] ");
            result.append(key(Messages.GUI_LABEL_BROADCASTMESSAGEFROM_0));
            result.append(' ');
            if (message.getUser() != null) {
                result.append(message.getUser().getName());
            } else {
                // system message
                result.append(key(Messages.GUI_LABEL_BROADCAST_FROM_SYSTEM_0));
            }
            result.append(":\n");
            result.append(message.getMessage());
            result.append("\n\n");
        }
        return result.toString();
    }
    // no message pending, return null
    return null;
}

From source file:scratch.scott.BrandesBetweennessCentrality.java

protected void computeBetweenness(Graph graph) {

    BetweennessDataDecorator decorator = new BetweennessDataDecorator();
    NumericDecorator bcDecorator = new NumericDecorator(CENTRALITY, UserData.SHARED);

    Set vertices = graph.getVertices();

    for (Iterator vIt = vertices.iterator(); vIt.hasNext();) {
        Vertex s = (Vertex) vIt.next();// ww w. j  a v a  2  s  .c  om

        initializeData(graph, decorator);

        decorator.data(s).numSPs = 1;
        decorator.data(s).distance = 0;

        Stack stack = new Stack();
        Buffer queue = new UnboundedFifoBuffer();
        queue.add(s);

        while (!queue.isEmpty()) {
            Vertex v = (Vertex) queue.remove();
            stack.push(v);

            for (Iterator nIt = v.getNeighbors().iterator(); nIt.hasNext();) {
                Vertex w = (Vertex) nIt.next();

                if (decorator.data(w).distance < 0) {
                    queue.add(w);
                    decorator.data(w).distance = decorator.data(v).distance + 1;
                }

                if (decorator.data(w).distance == decorator.data(v).distance + 1) {
                    decorator.data(w).numSPs += decorator.data(v).numSPs;
                    decorator.data(w).predecessors.add(v);
                }
            }
        }

        while (!stack.isEmpty()) {
            Vertex w = (Vertex) stack.pop();

            for (Iterator v2It = decorator.data(w).predecessors.iterator(); v2It.hasNext();) {
                Vertex v = (Vertex) v2It.next();
                double partialDependency = (decorator.data(v).numSPs / decorator.data(w).numSPs);
                partialDependency *= (1.0 + decorator.data(w).dependency);
                decorator.data(v).dependency += partialDependency;
                Edge currentEdge = v.findEdge(w);
                MutableDouble edgeValue = (MutableDouble) bcDecorator.getValue(currentEdge);
                edgeValue.add(partialDependency);
            }
            if (w != s) {
                MutableDouble bcValue = (MutableDouble) bcDecorator.getValue(w);
                bcValue.add(decorator.data(w).dependency);
            }
        }
    }

    if (PredicateUtils.enforcesEdgeConstraint(graph, Graph.UNDIRECTED_EDGE)) {
        for (Iterator v3It = vertices.iterator(); v3It.hasNext();) {
            MutableDouble bcValue = (MutableDouble) bcDecorator.getValue((Vertex) v3It.next());
            bcValue.setDoubleValue(bcValue.doubleValue() / 2.0);
        }
        for (Iterator eIt = graph.getEdges().iterator(); eIt.hasNext();) {
            MutableDouble bcValue = (MutableDouble) bcDecorator.getValue((Edge) eIt.next());
            bcValue.setDoubleValue(bcValue.doubleValue() / 2.0);
        }
    }

    for (Iterator vIt = vertices.iterator(); vIt.hasNext();) {
        Vertex vertex = (Vertex) vIt.next();
        decorator.removeValue(vertex);
    }

}