Example usage for org.apache.commons.collections.map LinkedMap lastKey

List of usage examples for org.apache.commons.collections.map LinkedMap lastKey

Introduction

In this page you can find the example usage for org.apache.commons.collections.map LinkedMap lastKey.

Prototype

public Object lastKey() 

Source Link

Document

Gets the last key in the map, which is the first inserted.

Usage

From source file:de.cosmocode.rendering.CollectionRenderer.java

private Renderer append(Object value) {
    if (mode == Mode.LIST) {
        peekList().add(value);// www  .ja  v  a 2  s .co  m
    } else if (mode == Mode.KEY) {
        final LinkedMap map = peekMap();
        map.put(map.lastKey(), value);
        mode = Mode.MAP;
    } else {
        throw new RenderingException(String.format("Appending only works in %s and %s", Mode.LIST, Mode.KEY));
    }
    return this;
}

From source file:de.cosmocode.rendering.CollectionRenderer.java

@Override
public Renderer endList() throws RenderingException {
    if (mode == Mode.LIST) {
        final List<Object> peek = peekList();
        stack.pop();/*from w  w w. j av a2  s  .c om*/
        if (stack.isEmpty()) {
            mode = Mode.DONE;
            build = peek;
        } else if (peekIsList()) {
            mode = Mode.LIST;
            peekList().add(peek);
        } else if (peekIsMap()) {
            mode = Mode.MAP;
            final LinkedMap map = peekMap();
            map.put(map.lastKey(), peek);
        } else {
            throw new RenderingException("Unknown state");
        }
        return this;
    } else {
        throw new RenderingException(String.format("endList is not allowed when in %s mode", mode));
    }
}

From source file:de.cosmocode.rendering.CollectionRenderer.java

@Override
public Renderer endMap() throws RenderingException {
    if (mode == Mode.MAP) {
        final LinkedMap peek = peekMap();
        stack.pop();/*from  www  .ja v  a  2s . c o m*/
        if (stack.isEmpty()) {
            mode = Mode.DONE;
            build = peek;
        } else if (peekIsList()) {
            mode = Mode.LIST;
            peekList().add(peek);
        } else if (peekIsMap()) {
            mode = Mode.MAP;
            final LinkedMap map = peekMap();
            map.put(map.lastKey(), peek);
        } else {
            throw new RenderingException("Unknown state");
        }
        return this;
    } else {
        throw new RenderingException(String.format("endMap is not allowed when in %s mode", mode));
    }
}

From source file:de.innovationgate.wgpublisher.webtml.portlet.TMLPortletStateSessionStorage.java

@Override
public TMLPortletState getState(TMLPortlet portlet) throws WGAPIException {

    String completeKey = getSessionContextKey(portlet);

    synchronized (_session) {

        // Get - conditionally create session context map
        Map<String, TMLPortletState> contexts = getSessionMap();

        // Get - conditionally create individual session context
        TMLPortletState context = (TMLPortletState) contexts.get(completeKey);
        if (context == null) {
            context = portlet.createState(this);

            // Set event index to current last index, so events fired before creation of this context are not executed for it
            LinkedMap list = TMLPortlet.getFiredEventsQueue(_session);
            if (!list.isEmpty()) {
                PortletEvent event = (PortletEvent) list.get(list.lastKey());
                context.setLastProcessedEventIndex(event.getIndex());
            }/*from  w  ww .  j  a  v  a  2  s  .  c  o m*/

            contexts.put(completeKey, context);
        }
        return context;
    }

}

From source file:de.innovationgate.wgpublisher.webtml.portlet.TMLPortlet.java

public void prepareEventProcessing(Base tag) throws WGAPIException {

    TMLPortletState sessionContext = getState();
    LinkedMap list = TMLPortlet.getFiredEventsQueue(tag.getPageContext().getSession());

    // Look if the event queue proceeded since the last processed event
    if (list.size() > 0) {
        PortletEvent lastEvent = (PortletEvent) list.get(list.lastKey());
        if (lastEvent != null) {
            if (lastEvent.getIndex() > sessionContext.getLastProcessedEventIndex()) {

                // Find the start index for processing new events
                Long startIndex;//w  ww  . ja  v a  2s  . c  o m
                Long lastProcessedIndex = new Long(sessionContext.getLastProcessedEventIndex());
                if (list.containsKey(lastProcessedIndex)) {
                    startIndex = (Long) list.nextKey(lastProcessedIndex);
                } else {
                    startIndex = (Long) list.firstKey();
                }

                // Set start index as WebTML option
                tag.getStatus().setOption(Base.OPTION_PORTLET_EVENT_STARTINDEX,
                        new Long(sessionContext.getLastProcessedEventIndex()), TMLOption.SCOPE_GLOBAL);

                // Update last processed event index to be the newest event's index
                sessionContext.setLastProcessedEventIndex(lastEvent.getIndex());
            }
        }
    }
}