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

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

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this collection contains no elements.

Usage

From source file:net.gleamynode.oil.impl.wal.store.FileLogWriter.java

public void flush(Buffer logBuf) {
    Object log;//w w  w  .  ja v  a 2  s  .  co  m

    try {
        for (;;) {
            synchronized (logBuf) {
                if (logBuf.isEmpty()) {
                    break;
                }

                log = logBuf.remove();
            }

            out.write(FileLogStoreConstants.LOG_HEADER);
            writeObject(log);
        }

        out.flush();
    } catch (IOException e) {
        throw new OilException("failed to write log.", e);
    }
}

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

/**
 * @see org.opencms.gwt.shared.rpc.I_CmsCoreService#getBroadcast()
 *//*from w ww  .  ja  v a 2s .c  om*/
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>/*  w  ww  .  j  a  v a 2s. co  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>
 * /* www.j ava 2 s  . co 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();/*from  w  w w.  j  ava 2  s  . co  m*/

        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);
    }

}