Example usage for java.util Deque descendingIterator

List of usage examples for java.util Deque descendingIterator

Introduction

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

Prototype

Iterator<E> descendingIterator();

Source Link

Document

Returns an iterator over the elements in this deque in reverse sequential order.

Usage

From source file:hudson.plugins.project_inheritance.projects.InheritanceProject.java

public SCM getScm(IMode mode) {
    InheritanceGovernor<SCM> gov = new InheritanceGovernor<SCM>("scm", SELECTOR.MISC, this) {
        @Override//from   www  .  java  2s  .c  o m
        protected SCM castToDestinationType(Object o) {
            return (o instanceof SCM) ? (SCM) o : null;
        }

        @Override
        public SCM getRawField(InheritanceProject ip) {
            return ip.getRawScm();
        }

        @Override
        protected SCM reduceFromFullInheritance(Deque<SCM> list) {
            if (list == null || list.isEmpty()) {
                return new NullSCM();
            }
            //Return the SCM that was defined last and is not a NullSCM
            Iterator<SCM> iter = list.descendingIterator();
            while (iter.hasNext()) {
                SCM scm = iter.next();
                if (scm != null && !(scm instanceof NullSCM)) {
                    return scm;
                }
            }
            //All SCMs are NullSCMs; so it does not matter which one to return
            return list.peekLast();
        }
    };

    SCM scm = gov.retrieveFullyDerivedField(this, mode);

    //We may not return null directly
    return (scm == null) ? new NullSCM() : scm;
}