Example usage for java.util Deque offer

List of usage examples for java.util Deque offer

Introduction

In this page you can find the example usage for java.util Deque offer.

Prototype

boolean offer(E e);

Source Link

Document

Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and false if no space is currently available.

Usage

From source file:com.playtech.portal.platform.portlet.spring.InternalResourceViewResolver.java

protected String viewNameForLicensee(String viewName) {
    String[] pathParts = split(viewName, "/");
    if (pathParts == null)
        return null;

    Deque<String> deque = new LinkedList<>(asList(pathParts));
    String view = deque.pollLast();
    deque.offer(licenseePackageName);
    deque.offer(view);/*from w  w  w.ja va 2  s . c  o m*/
    return join(deque, "/");
}

From source file:org.jasig.portal.layout.TransientUserLayoutXMLEventReader.java

@Override
protected Deque<XMLEvent> getAdditionalEvents(XMLEvent event) {
    if (event.isStartElement()) {
        final StartElement startElement = event.asStartElement();

        //All following logic requires an ID attribute, ignore any element without one
        final Attribute idAttribute = startElement.getAttributeByName(IUserLayoutManager.ID_ATTR_NAME);
        if (idAttribute == null) {
            return null;
        }/*from  www  .j  a v a  2  s. c om*/

        //Handle adding a transient folder to the root element
        if (this.rootFolderId.equals(idAttribute.getValue())) {
            final QName name = startElement.getName();
            final String namespaceURI = name.getNamespaceURI();
            final String prefix = name.getPrefix();

            final Deque<XMLEvent> transientEventBuffer = new LinkedList<XMLEvent>();

            final Collection<Attribute> transientFolderAttributes = new LinkedList<Attribute>();
            transientFolderAttributes.add(
                    EVENT_FACTORY.createAttribute("ID", TransientUserLayoutManagerWrapper.TRANSIENT_FOLDER_ID));
            transientFolderAttributes.add(EVENT_FACTORY.createAttribute("type", "regular"));
            transientFolderAttributes.add(EVENT_FACTORY.createAttribute("hidden", "true"));
            transientFolderAttributes.add(EVENT_FACTORY.createAttribute("unremovable", "true"));
            transientFolderAttributes.add(EVENT_FACTORY.createAttribute("immutable", "true"));
            transientFolderAttributes.add(EVENT_FACTORY.createAttribute("name", "Transient Folder"));

            final StartElement transientFolder = EVENT_FACTORY.createStartElement(prefix, namespaceURI,
                    IUserLayoutManager.FOLDER, transientFolderAttributes.iterator(), null);
            transientEventBuffer.add(transientFolder);

            //append channel element iff subscribeId describes a transient channel, and not a regular layout channel
            final String subscribeId = this.userLayoutManager.getFocusedId();
            if (null != subscribeId && !subscribeId.equals("")
                    && this.userLayoutManager.isTransientChannel(subscribeId)) {
                IPortletDefinition chanDef = null;
                try {
                    chanDef = this.userLayoutManager.getChannelDefinition(subscribeId);
                } catch (Exception e) {
                    this.logger.error("Could not obtain IChannelDefinition for subscribe id: " + subscribeId,
                            e);
                }

                if (chanDef != null) {
                    //TODO Move IChannelDefinition/IPortletDefinition -> StAX events code somewhere reusable
                    final Collection<Attribute> channelAttrs = new LinkedList<Attribute>();
                    channelAttrs.add(EVENT_FACTORY.createAttribute("ID", subscribeId));
                    channelAttrs.add(EVENT_FACTORY.createAttribute("typeID",
                            Integer.toString(chanDef.getType().getId())));
                    channelAttrs.add(EVENT_FACTORY.createAttribute("hidden", "false"));
                    channelAttrs.add(EVENT_FACTORY.createAttribute("unremovable", "true"));
                    channelAttrs.add(EVENT_FACTORY.createAttribute("name", chanDef.getName()));
                    channelAttrs.add(EVENT_FACTORY.createAttribute("description", chanDef.getDescription()));
                    channelAttrs.add(EVENT_FACTORY.createAttribute("title", chanDef.getTitle()));
                    channelAttrs.add(EVENT_FACTORY.createAttribute("chanID",
                            chanDef.getPortletDefinitionId().getStringId()));
                    channelAttrs.add(EVENT_FACTORY.createAttribute("fname", chanDef.getFName()));
                    channelAttrs.add(
                            EVENT_FACTORY.createAttribute("timeout", Integer.toString(chanDef.getTimeout())));
                    channelAttrs.add(EVENT_FACTORY.createAttribute("transient", "true"));

                    final StartElement startChannel = EVENT_FACTORY.createStartElement(prefix, namespaceURI,
                            IUserLayoutManager.CHANNEL, channelAttrs.iterator(), null);
                    transientEventBuffer.offer(startChannel);

                    // add channel parameter elements
                    for (final IPortletDefinitionParameter parm : chanDef.getParameters()) {
                        final Collection<Attribute> parameterAttrs = new LinkedList<Attribute>();
                        parameterAttrs.add(EVENT_FACTORY.createAttribute("name", parm.getName()));
                        parameterAttrs.add(EVENT_FACTORY.createAttribute("value", parm.getValue()));

                        final StartElement startParameter = EVENT_FACTORY.createStartElement(prefix,
                                namespaceURI, IUserLayoutManager.PARAMETER, parameterAttrs.iterator(), null);
                        transientEventBuffer.offer(startParameter);

                        final EndElement endParameter = EVENT_FACTORY.createEndElement(prefix, namespaceURI,
                                IUserLayoutManager.PARAMETER, null);
                        transientEventBuffer.offer(endParameter);
                    }

                    final EndElement endChannel = EVENT_FACTORY.createEndElement(prefix, namespaceURI,
                            IUserLayoutManager.CHANNEL, null);
                    transientEventBuffer.offer(endChannel);
                }
            }

            final EndElement endFolder = EVENT_FACTORY.createEndElement(prefix, namespaceURI,
                    IUserLayoutManager.FOLDER, null);
            transientEventBuffer.offer(endFolder);

            return transientEventBuffer;
        }
    }

    return null;
}

From source file:org.roche.antibody.services.graphsynchronizer.GraphSynchronizer.java

private HELMCode buildHelm(Domain activeDomain) {
    HELMCode code = new HELMCode();
    Deque<Sequence> sequencesToHandle = new ArrayDeque<Sequence>();
    handledConnections.clear();// w w w  .ja  va 2  s  . c o m
    handledInterDomainConnections.clear();
    handledSequences.clear();
    sequencesToHandle.offer(activeDomain);
    Map<Sequence, HELMElement> helmElemMap = new HashMap<Sequence, HELMElement>();
    while (sequencesToHandle.isEmpty() == false) {
        Sequence seqToHandle = sequencesToHandle.poll();
        Sequence seqForConnectionCheck = seqToHandle;

        if (handledSequences.contains(seqToHandle)) {
            continue;
        } else {
            handledSequences.add(seqToHandle);
        }

        if (seqToHandle instanceof Domain) {
            activeDomain = (Domain) seqToHandle;
            HELMElement pep = seqService.toHELM(activeDomain);
            code.addHELMElement(pep);
            helmElemMap.put(activeDomain.getPeptide(), pep);
            seqForConnectionCheck = activeDomain.getPeptide();
        }

        for (Connection con : seqToHandle.getConnections()) {
            if (handledConnections.contains(con)) {
                continue;
            }
            if (con instanceof GeneralConnection) {
                HELMConnection helmCon = null;
                if (con.getSource() == seqForConnectionCheck && con.getTarget() == seqForConnectionCheck) {
                    HELMElement element = seqService.toHELM(seqToHandle);
                    code.addHELMElement(element);
                    helmCon = connectionService.createConnection(con, element, element);
                } else {
                    HELMElement source = helmElemMap.get(con.getSource());
                    if (source == null) {
                        source = seqService.toHELM(con.getSource());
                        helmElemMap.put(con.getSource(), source);
                        code.addHELMElement(source);
                        sequencesToHandle.push(con.getSource());
                    }

                    HELMElement target = helmElemMap.get(con.getTarget());
                    if (target == null) {
                        target = seqService.toHELM(con.getTarget());
                        helmElemMap.put(con.getTarget(), target);
                        code.addHELMElement(target);
                        sequencesToHandle.push(con.getTarget());
                    }
                    helmCon = connectionService.createConnection(con, source, target);
                }
                code.addHELMConnection(helmCon);
                handledConnections.add(con);
            }
            if (con instanceof CysteinConnection && connectionService.isIntraDomainConnection(con)) {
                HELMConnection helmCon = connectionService.createConnection(con,
                        helmElemMap.get(activeDomain.getPeptide()), helmElemMap.get(activeDomain.getPeptide()));
                handledConnections.add(con);
                code.addHELMConnection(helmCon);
            }
            if (con instanceof CysteinConnection && !connectionService.isIntraDomainConnection(con)) {
                handledInterDomainConnections.add(con);
            }
        }
    }
    return code;
}

From source file:org.sybila.parasim.computation.verification.stl.cpu.AbstractUnaryTemporalMonitor.java

private List<Robustness> precomputeRobustness(Monitor subMonitor, FormulaInterval interval) {
    Deque<Robustness> lemireDeque = new LemireDeque<>(createComparator());
    List<Robustness> precomputed = new ArrayList<>();
    Iterator<Robustness> window = subMonitor.iterator();
    Iterator<Robustness> current = subMonitor.iterator();
    int currentIndex = 0;
    float currentTime = current.next().getTime();
    while (window.hasNext()) {
        Robustness memory = null;//from w  w w  . j  av  a2 s . co  m
        boolean windowEndReached = false;
        // push new points
        while (window.hasNext() && !windowEndReached) {
            memory = window.next();
            // check whether the time upper bound is reached
            if (memory.getTime() < currentTime + interval.getUpperBound()) {
                lemireDeque.offer(memory);
                memory = null;
            } else if (memory.getTime() == currentTime + interval.getUpperBound()) {
                lemireDeque.offer(memory);
                memory = null;
                windowEndReached = true;
            } else {
                windowEndReached = true;
            }
        }
        // check whether the window end has been reached
        if (!windowEndReached) {
            return precomputed;
        }
        // remove useless points
        while (!lemireDeque.isEmpty()
                && lemireDeque.peekFirst().getTime() < currentTime + interval.getLowerBound()) {
            lemireDeque.remove();
        }
        // get the first robustness in deque
        Robustness found = lemireDeque.peekFirst();
        precomputed.add(new SimpleRobustness(found.getValue(), currentTime, getProperty()));
        currentIndex++;
        currentTime = current.next().getTime();
        if (memory != null) {
            lemireDeque.offer(memory);
            memory = null;
        }
    }
    return precomputed;
}

From source file:org.xframium.page.data.provider.AbstractPageDataProvider.java

@Override
public PageData getRecord(String recordType) {
    try {//from  www.j  a va 2s  . c om
        Deque<PageData> dataList = recordMap.get(getRecordType(recordType)).getRecordList();

        if (dataList instanceof LinkedBlockingDeque)
            return ((LinkedBlockingDeque<PageData>) dataList).pollFirst(waitTimeOut, TimeUnit.SECONDS);
        else {
            PageData pageData = dataList.pollFirst();
            dataList.offer(pageData);
            return pageData;
        }
    } catch (Exception e) {
        log.error("Error acquiring page data [" + getRecordType(recordType) + "] - " + e.getMessage());
        return null;
    }
}

From source file:org.xframium.page.data.provider.AbstractPageDataProvider.java

public void putRecord(PageData pageData) {
    if (pageData != null) {
        Deque<PageData> dataList = recordMap.get(pageData.getType()).getRecordList();
        if (dataList instanceof LinkedBlockingDeque)
            dataList.offer(pageData);
    }//from w  w  w.  jav  a  2  s. c  om
}

From source file:org.xframium.page.data.provider.AbstractPageDataProvider.java

/**
 * Adds the record.//from   w ww.ja v  a  2 s . c  o  m
 *
 * @param pageData the page data
 */
public void addRecord(PageData pageData) {
    allRecordMap.get(pageData.getType()).addRecord(pageData);

    if (!pageData.isActive())
        return;

    Deque<PageData> dataList = recordMap.get(pageData.getType()).getRecordList();
    idMap.put(pageData.getType() + "." + pageData.getName(), pageData);
    dataList.offer(pageData);
}