Example usage for java.util Deque iterator

List of usage examples for java.util Deque iterator

Introduction

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

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this deque in proper sequence.

Usage

From source file:Main.java

public static void main(String[] args) {

    Deque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(1);//from www .j  av  a  2s  .c o  m
    deque.add(2);
    deque.add(3);
    deque.add(4);

    for (Iterator itr = deque.iterator(); itr.hasNext();) {
        System.out.println(itr.next());
    }
}

From source file:Main.java

public static void main(String[] args) {

    Deque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(1);//from w ww .  j  ava 2 s. c  o  m
    deque.add(2);
    deque.add(3);
    deque.add(4);

    for (Iterator itr = deque.iterator(); itr.hasNext();) {
        System.out.println(itr.next());
    }

    for (Iterator descItr = deque.descendingIterator(); descItr.hasNext();) {
        System.out.println(descItr.next());
    }
}

From source file:com.griddynamics.banshun.DependencySorter.java

private List<Location> pullLocationListHead(Deque<Location> locations) {
    Set<String> resolvedBeans = new LinkedHashSet<>();
    List<Location> resolvedLocations = new LinkedList<>();

    for (Iterator<Location> it = locations.iterator(); it.hasNext();) {
        Location location = it.next();

        if (resolvedBeans.containsAll(location.getImportBeanNames())) {
            resolvedBeans.addAll(location.getExportBeanNames());
            resolvedLocations.add(location);

            it.remove(); //remove location from unresolved
            it = locations.iterator(); //reset iterator
        }//from   w  w  w .j  a  v  a2 s .  c  om
    }
    return resolvedLocations;
}

From source file:org.apache.asterix.om.typecomputer.impl.RecordRemoveFieldsTypeComputer.java

/**
 * Comparison elements of two paths/* ww w .  ja  v a2s .  c  o m*/
 * Note: l2 uses a LIFO insert and removal.
 */
private <E> boolean isEqualPaths(List<E> l1, Deque<E> l2) {
    if ((l1 == null) || (l2 == null)) {
        return false;
    }

    if (l1.size() != l2.size()) {
        return false;
    }

    Iterator<E> it2 = l2.iterator();

    int len = l1.size();
    for (int i = len - 1; i >= 0; i--) {
        E o1 = l1.get(i);
        E o2 = it2.next();
        if (!o1.equals(o2)) {
            return false;
        }
    }
    return true;
}

From source file:org.openregistry.core.domain.jpa.JpaPersonImpl.java

@Override
public Identifier findIdentifierByValue(String identifierType, String identifierValue) {
    final Map<String, Deque<Identifier>> identifiersByType = getIdentifiersByType();
    Deque<Identifier> ids = identifiersByType.get(identifierType);
    if (ids == null) {

        //            throw new RuntimeException("No identifiers exist for the specified type [" + identifierType + "]");
        return null;
    }/*from ww  w .  j  a  va 2  s  .  c  om*/
    Iterator<Identifier> iter = ids.iterator();
    Identifier id = null;
    while (iter.hasNext()) {
        id = iter.next();
        if (id.getValue().equals(identifierValue)) {
            return id;
        }
    }
    return null;
}

From source file:gov.nih.nci.cacis.common.util.ExtractSchematron.java

private String toXPath(Deque<XSElementDeclaration> eltStack) {
    return StringUtils
            .join(Iterators.transform(eltStack.iterator(), new Function<XSElementDeclaration, String>() {

                @Override//from   ww  w. jav  a  2  s  .c  om
                public String apply(XSElementDeclaration elt) {
                    final StringBuilder sb = new StringBuilder();
                    if (elt.getNamespace() != null) {
                        sb.append(getNSPrefix(elt.getNamespace()) + ":");
                    }
                    return sb.append(elt.getName()).toString();
                }
            }), "/");
}

From source file:com.yangtsaosoftware.pebblemessenger.services.MessageProcessingService.java

private Deque<CharacterMatrix> process_RTL_UNIStr(Deque<CharacterMatrix> dc) {
    Iterator<CharacterMatrix> cmIt = dc.iterator();
    while (cmIt.hasNext()) {
        CharacterMatrix cmCur = cmIt.next();
        byte[] pos = cmCur.getPos();
        int newCol = fChars - (int) pos[1] + (cmCur.getWidthBytes() > 1 ? 0 : 1);
        cmCur.setPos((int) pos[0], newCol);
        Constants.log(TAG_NAME, String.format("Deque pos old col %d:new col %d", (int) pos[1], newCol));
    }//from   w w  w.jav  a2s  . co  m
    return dc;
}

From source file:com.solera.defrag.ViewStack.java

/**
 * Replace the current stack with the given views,
 *
 * @param views the list of views to replace the stack with. The list consists of pairs of
 * Integer (layoutId) to Bundle (parameters) for the view. If the Bundle component
 * is the USE_EXISTING_SAVED_STATE tag, then we will use that saved state for that
 * view (if it exists, and is at the right location in the stack) otherwise this will be null.
 *//*from w  w w  .  j  a  v a 2s . com*/
public void replaceStack(@NonNull final List<Pair<Integer, Bundle>> views) {
    if (views.isEmpty()) {
        throw new IllegalArgumentException("Cannot replace stack with an empty views stack");
    }

    ViewStackEntry fromEntry = null;
    Iterator<ViewStackEntry> iterator = null;
    setTraversingState(TraversingState.REPLACING);
    if (!viewStack.isEmpty()) {
        fromEntry = viewStack.peek();

        //take a copy of the view stack:
        Deque<ViewStackEntry> copy = new ArrayDeque<>(viewStack);

        viewStack.clear();
        viewStack.push(fromEntry);

        iterator = copy.iterator();
    }

    for (Pair<Integer, Bundle> view : views) {
        Bundle savedParameter = view.second;
        SparseArray<Parcelable> viewState = null;
        if (view.second == USE_EXISTING_SAVED_STATE) {
            savedParameter = null;
            if (iterator != null && iterator.hasNext()) {
                final ViewStackEntry next = iterator.next();
                if (next.mLayout == view.first) {
                    savedParameter = next.mParameters;
                    viewState = next.mViewState;
                } else {
                    iterator = null;
                }
            }
        }
        viewStack.push(new ViewStackEntry(view.first, savedParameter, viewState));
    }

    final ViewStackEntry toEntry = viewStack.peek();

    final View toView = toEntry.getView();

    if (fromEntry == null || fromEntry.mLayout == toEntry.mLayout) {
        //if current topEntry layout is null or equal to the next proposed topEntry layout
        //we cannot do a transition animation
        viewStack.remove(fromEntry);
        removeAllViews();
        addView(toView);
        ViewUtils.waitForMeasure(toView, new ViewUtils.OnMeasuredCallback() {
            @Override
            public void onMeasured(View view, int width, int height) {
                setTraversingState(TraversingState.IDLE);
            }
        });
    } else {
        final View fromView = fromEntry.getView();
        addView(toView);

        final ViewStackEntry finalFromEntry = fromEntry;
        ViewUtils.waitForMeasure(toView, new ViewUtils.OnMeasuredCallback() {
            @Override
            public void onMeasured(View view, int width, int height) {
                ViewStack.this.runAnimation(fromView, toView, TraversingOperation.REPLACE);
                viewStack.remove(finalFromEntry);
            }
        });
    }
}

From source file:nl.knaw.huc.di.tag.tagml.importer.TAGMLListener.java

private TAGMarkup removeFromMarkupStack2(String extendedTag, Deque<TAGMarkup> markupStack) {
    Iterator<TAGMarkup> iterator = markupStack.iterator();
    TAGMarkup markup = null;/*w  ww .  j av  a2s  .c  o m*/
    while (iterator.hasNext()) {
        markup = iterator.next();
        if (markup.getExtendedTag().equals(extendedTag)) {
            break;
        }
        markup = null;
    }
    if (markup != null) {
        markupStack.remove(markup);
        currentTextVariationState().removeOpenMarkup(markup);
    }
    return markup;
}

From source file:org.pentaho.di.trans.Trans.java

protected synchronized void writeMetricsInformation() throws KettleException {
    ///*from  w  w w  .  j a  v a2s .  com*/
    List<MetricsDuration> metricsList = MetricsUtil.getDuration(log.getLogChannelId(),
            Metrics.METRIC_PLUGIN_REGISTRY_REGISTER_EXTENSIONS_START);
    if (!metricsList.isEmpty()) {
        System.out.println(metricsList.get(0));
    }

    metricsList = MetricsUtil.getDuration(log.getLogChannelId(),
            Metrics.METRIC_PLUGIN_REGISTRY_PLUGIN_REGISTRATION_START);
    if (!metricsList.isEmpty()) {
        System.out.println(metricsList.get(0));
    }

    long total = 0;
    metricsList = MetricsUtil.getDuration(log.getLogChannelId(),
            Metrics.METRIC_PLUGIN_REGISTRY_PLUGIN_TYPE_REGISTRATION_START);
    if (metricsList != null) {
        for (MetricsDuration duration : metricsList) {
            total += duration.getDuration();
            System.out.println("   - " + duration.toString() + "  Total=" + total);
        }
    }

    Database db = null;
    MetricsLogTable metricsLogTable = transMeta.getMetricsLogTable();
    try {
        db = new Database(this, metricsLogTable.getDatabaseMeta());
        db.shareVariablesWith(this);
        db.connect();
        db.setCommit(logCommitSize);

        List<String> logChannelIds = LoggingRegistry.getInstance().getLogChannelChildren(getLogChannelId());
        for (String logChannelId : logChannelIds) {
            Deque<MetricsSnapshotInterface> snapshotList = MetricsRegistry.getInstance().getSnapshotLists()
                    .get(logChannelId);
            if (snapshotList != null) {
                Iterator<MetricsSnapshotInterface> iterator = snapshotList.iterator();
                while (iterator.hasNext()) {
                    MetricsSnapshotInterface snapshot = iterator.next();
                    db.writeLogRecord(metricsLogTable, LogStatus.START, new LoggingMetric(batchId, snapshot),
                            null);
                }
            }

            Map<String, MetricsSnapshotInterface> snapshotMap = MetricsRegistry.getInstance().getSnapshotMaps()
                    .get(logChannelId);
            if (snapshotMap != null) {
                synchronized (snapshotMap) {
                    Iterator<MetricsSnapshotInterface> iterator = snapshotMap.values().iterator();
                    while (iterator.hasNext()) {
                        MetricsSnapshotInterface snapshot = iterator.next();
                        db.writeLogRecord(metricsLogTable, LogStatus.START,
                                new LoggingMetric(batchId, snapshot), null);
                    }
                }
            }
        }

        // Also time-out the log records in here...
        //
        db.cleanupLogRecords(metricsLogTable);
    } catch (Exception e) {
        throw new KettleException(
                BaseMessages.getString(PKG, "Trans.Exception.UnableToWriteMetricsInformationToLogTable"), e);
    } finally {
        if (!db.isAutoCommit()) {
            db.commit(true);
        }
        db.disconnect();
    }
}